Notification Services—Creating a Subscription Class and Subscription Event Rule

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:Articles
Database Articles

Notification Services

© 2006 O'Reilly Media, Inc.

Creating a Subscription Class and Subscription Event Rule

A subscription class with a single subscription event rule is created in the CreateSubscriptionClassMethod( ) method of Example 18-1. The code follows:

private static void CreateSubscriptionClass( )
{
  SubscriptionClass sc = 
    new SubscriptionClass(a, 
    "StockWatchSubscriptions");
  SubscriptionField sf;
  sf = new SubscriptionField(sc, 
    "DeviceName");
  sf.Type = "nvarchar(255)";
  sc.SubscriptionFields.Add(sf);
  sf = new SubscriptionField(sc, 
    "SubscriberLocale");
  sf.Type = "nvarchar(10)";
  sc.SubscriptionFields.Add(sf);
  sf = new SubscriptionField(sc, "Symbol");
  sf.Type = "nvarchar(6)";
  sc.SubscriptionFields.Add(sf);
  sf = new SubscriptionField(sc, "Price");
  sf.Type = "float";
  sc.SubscriptionFields.Add(sf);
  SubscriptionEventRule ser =
    new SubscriptionEventRule
    (sc, "StockWatchSubscriptionsEventRule");
  ser.Action = @"INSERT INTO StockWatchNotifications (" +
    "SubscriberId, DeviceName, SubscriberLocale, Symbol, Price) " +
    "SELECT s.SubscriberId, s.DeviceName, s.SubscriberLocale, " +
    "e.Symbol, e.Price " +
    "FROM StockWatchEvents e, StockWatchSubscriptions s " +
    "WHERE e.Symbol = s.Symbol";
  ser.EventClassName = "StockWatchEvents";
  sc.SubscriptionEventRules.Add(ser);
  a.SubscriptionClasses.Add(sc);
  Console.WriteLine("Added subscription class: " + sc.Name);
}

A SubscriptionEventRule object represents a rule that uses T-SQL queries to generate notifications when event batches arrive. The Action property represents the T-SQL query for the SubscriptionEventRule object. In this example, notifications are generated when the ticker symbol of an event matches the ticker symbol specified in a subscription.

The NMO classes for managing the different types of subscription rules are described in Table 18-6.

Table 18-5. NMO classes for managing subscription chronicles, classes, and fields

Class Description
SubscriptionChronicle Represents a subscription chronicle.
SubscriptionChronicleCollection Represents a collection of subscription chronicles as SubscriptionChronicle objects. The SubscriptionChronicles

property of the SubscriptionClass class returns the subscription chronicles for the subscription class.

SubscriptionClass Represents a subscription class.
SubscriptionClassCollection Represents a collection of subscription classes as SubscriptionClass

objects. The SubscriptionClasses property of the Application class returns the subscription classes for the Notification Services application.

SubscriptionField Represents a field in the subscription class schema.
SubscriptionFieldCollection Represents a collection of fields as SubscriptionField objects. The

SubscriptionFields property of the SubscriptionClass class returns the fields for the subscription class schema.

A SubscriptionEventRule object represents a rule that uses T-SQL queries to generate notifications when event batches arrive. The Action property represents the T-SQL query for the SubscriptionEventRule object. In this example, notifications are generated when the ticker symbol of an event matches the ticker symbol specified in a subscription.

The NMO classes for managing the different types of subscription rules are described in Table 18-6.

Table 18-6. NMO classes for managing subscription rules

Class Description
SubscriptionConditionEventRule Represents a subscription rule that the generator runs

against subscriptions that use conditions to generate notifications.

SubscriptionConditionEventRuleCollection Represents a collection of subscription condition event

rules as SubscriptionConditionEventRule objects. The SubscriptionConditionEventRules property of the SubscriptionClass class returns the subscription condition event rules for the subscription class.

SubscriptionConditionScheduledRule Represents a subscription rule that the generator runs

against scheduled subscriptions that use conditions to generate notifications.

SubscriptionConditionScheduledRuleCollection Represents a collection of subscription condition scheduled

rules as SubscriptionConditionScheduledRule objects. The SubscriptionConditionScheduledRules property of the SubscriptionClass class returns the subscription condition scheduled rules for the subscription class.

SubscriptionEventRule Represents an event rule that contains simple (not conditional)

actions.

SubscriptionEventRuleCollection Represents a collection of subscription event rules as

SubscriptionEventRule objects. The SubscriptionEventRules property of the SubscriptionClass class returns the subscription event rules for the subscription class.

SubscriptionScheduledRule Represents a scheduled rule that contains actions that do

not use conditions to generate notifications.

SubscriptionScheduledRuleCollection Represents a collection of scheduled rules as

SubscriptionScheduledRule objects. The SubscriptionScheduledRules property of the SubscriptionClass class returns the scheduled rules for the subscription class.


Previous_Page_.gif Next_Page_.gif


Personal tools