Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

AFNotificationRule.GetCounts Method (AFDatabase)

  • Last UpdatedJan 12, 2026
  • 3 minute read
AFNotificationRule.GetCounts Method (AFDatabase)
Get the number of notification rules for each status.

Namespace:  OSIsoft.AF.Notification
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.2.0.7

Syntax

public static IList<KeyValuePair<AFStatus, int>> GetCounts(
	AFDatabase database
)
Public Shared Function GetCounts ( 
	database As AFDatabase
) As IList(Of KeyValuePair(Of AFStatus, Integer))

Dim database As AFDatabase
Dim returnValue As IList(Of KeyValuePair(Of AFStatus, Integer))

returnValue = AFNotificationRule.GetCounts(database)
public:
static IList<KeyValuePair<AFStatus, int>>^ GetCounts(
	AFDatabase^ database
)
static member GetCounts : 
        database : AFDatabase -> IList<KeyValuePair<AFStatus, int>> 

Parameters

database
Type: OSIsoft.AFAFDatabase
The database to search for notification rules counts by status.

Return Value

Type: IListKeyValuePairAFStatus, Int32
Returns a list of KeyValuePairTKey, TValue items where the key is the notification rule's AFStatus and the value is the number of notification rules with that status.

Remarks

This method will make one call to the server to get the number of notification rules for each status.

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);
}

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0, 2.10.11, 2.10.5, 2.10.0, 2.10, 2.9.5, 2.9, 2.8.5, 2.8

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in