AFNotificationRule.GetCounts(T) Method (AFDatabase)
- Last UpdatedNov 18, 2025
- 5 minute read
- PI System
- AF SDK 2024 R2
- Developer
Get the number of notification rules for each filter.
Namespace: OSIsoft.AF.Notification
Assembly: OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182
Syntax
public static IList<KeyValuePair<T, int>> GetCounts<T>( AFDatabase database ) where T : AFObject
Public Shared Function GetCounts(Of T As AFObject) ( database As AFDatabase ) As IList(Of KeyValuePair(Of T, Integer)) Dim database As AFDatabase Dim returnValue As IList(Of KeyValuePair(Of T, Integer)) returnValue = AFNotificationRule.GetCounts(database)
public: generic<typename T> where T : AFObject static IList<KeyValuePair<T, int>>^ GetCounts( AFDatabase^ database )
static member GetCounts : database : AFDatabase -> IList<KeyValuePair<'T, int>> when 'T : AFObject
Parameters
- database
- Type: OSIsoft.AFAFDatabase
The database to search for notification rule counts by filter.
Type Parameters
- T
- The type of objects used to filter notification rules. The following types are supported: AFNotificationTemplate, AFCategory.
Return Value
Type: IListKeyValuePairT, Int32Returns a list of KeyValuePairTKey, TValue items where the key is the filter object of the notification rules and the value is the number of notification rules associated to the filter object. The key will be for the notification rules that do not have the filter object.
Remarks
This method will make one call to the server to get the number of notification rules
associated with each filter object.
For a filter type of AFNotificationRuleTemplate, this method will return
the number of notification rules created from each notification rule template.
For a filter type of AFCategory, this method will return
the number of notification rules for each notification rule category.
Examples
// This example demonstrates how to call the GetCounts method to return // the number of notification rules based upon different filters. // Get the Database PISystems myPISystems = new PISystems(); PISystem myPISystem = myPISystems.DefaultPISystem; AFDatabase myDB = myPISystem.Databases.DefaultDatabase; // Create some filter objects AFCategory myCategory1 = myDB.NotificationRuleCategories.Add("MyCategory#1"); AFCategory myCategory2 = myDB.NotificationRuleCategories.Add("MyCategory#2"); AFElementTemplate myElementTemplate = myDB.ElementTemplates.Add("MyElementTemplate#1"); AFNotificationRuleTemplate myTemplate = new AFNotificationRuleTemplate("MyTemplate#1", myElementTemplate, createEnabled: true); myTemplate.Categories.Add(myCategory1); // Create some Notification Rules AFElement myElement = myDB.Elements.Add("MyElement#1", myElementTemplate); AFNotificationRule myNotificationRule0 = new AFNotificationRule("MyNotificationRule#0"); myNotificationRule0.Description = "This is the notification rule with no categories or template"; myNotificationRule0.SetStatus(AFStatus.Enabled); myElement.NotificationRules.Add(myNotificationRule0); AFNotificationRule myNotificationRule1 = new AFNotificationRule("MyNotificationRule#1", myTemplate, myElement); myNotificationRule1.Description = "This is the first notification rule example from template"; AFNotificationRule myNotificationRule2 = new AFNotificationRule("MyNotificationRule#2", target: myElement); myNotificationRule2.Description = "This is the second notification rule example with no template"; myNotificationRule2.Categories.Add(myCategory2); myNotificationRule2.SetStatus(AFStatus.NotReady); myDB.CheckIn(); // Get notification rule counts by Status and display results IList<KeyValuePair<AFStatus, int>> statusCounts = AFNotificationRule.GetCounts(myDB); foreach (var item in statusCounts) { Console.WriteLine("{0} = {1}", item.Key, item.Value); } // Get notification rule counts by Category and display results IList<KeyValuePair<AFCategory, int>> catCounts = AFNotificationRule.GetCounts<AFCategory>(myDB); foreach (var item in catCounts) { Console.WriteLine("{0} = {1}", item.Key, item.Value); } // Get notification rule counts by Template and display results IList<KeyValuePair<AFNotificationRuleTemplate, int>> tmplCounts = AFNotificationRule.GetCounts<AFNotificationRuleTemplate>(myDB); foreach (var item in tmplCounts) { Console.WriteLine("{0} = {1}", item.Key, item.Value); }
' This example demonstrates how to call the GetCounts method to return ' the number of notification rules based upon different filters. ' Get the Database Dim myPISystems As New PISystems() Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystem.Databases.DefaultDatabase ' Create some filter objects Dim myCategory1 As AFCategory = myDB.NotificationRuleCategories.Add("MyCategory#1") Dim myCategory2 As AFCategory = myDB.NotificationRuleCategories.Add("MyCategory#2") Dim myElementTemplate As AFElementTemplate = myDB.ElementTemplates.Add("MyElementTemplate#1") Dim myTemplate As AFNotificationRuleTemplate = New AFNotificationRuleTemplate("MyTemplate#1", myElementTemplate, createEnabled:=True) myTemplate.Categories.Add(myCategory1) ' Create some Notification Rules Dim myElement As AFElement = myDB.Elements.Add("MyElement#1", myElementTemplate) Dim myNotificationRule0 As New AFNotificationRule("MyNotificationRule#0") myNotificationRule0.Description = "This is the analysis with no categories or template" myNotificationRule0.SetStatus(AFStatus.Enabled) myElement.NotificationRules.Add(myNotificationRule0) Dim myNotificationRule1 As New AFNotificationRule("MyNotificationRule#1", myTemplate, myElement) myNotificationRule1.Description = "This is the first analysis example from template" Dim myNotificationRule2 As New AFNotificationRule("MyNotificationRule#2", target:=myElement) myNotificationRule2.Description = "This is the second analysis example with no template" myNotificationRule2.Categories.Add(myCategory2) myNotificationRule2.SetStatus(AFStatus.NotReady) myDB.CheckIn() ' Get notification rules counts by Status and display results Dim statusCounts As IList(Of KeyValuePair(Of AFStatus, Integer)) = AFNotificationRule.GetCounts(myDB) For Each item As KeyValuePair(Of AFStatus, Integer) In statusCounts Console.WriteLine("{0} = {1}", item.Key, item.Value) Next ' Get notification rules counts by Category and display results Dim catCounts As IList(Of KeyValuePair(Of AFCategory, Integer)) = AFNotificationRule.GetCounts(Of AFCategory)(myDB) For Each item As KeyValuePair(Of AFCategory, Integer) In catCounts Console.WriteLine("{0} = {1}", item.Key, item.Value) Next ' Get notification rules counts by Template and display results Dim tmplCounts As IList(Of KeyValuePair(Of AFNotificationRuleTemplate, Integer)) = AFNotificationRule.GetCounts(Of AFNotificationRuleTemplate)(myDB) For Each item As KeyValuePair(Of AFNotificationRuleTemplate, Integer) In tmplCounts Console.WriteLine("{0} = {1}", item.Key, item.Value) Next
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.