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
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
| Represents a subscription class. |
SubscriptionClassCollection
| Represents a collection of subscription classes as SubscriptionClass
objects. The |
SubscriptionField
| Represents a field in the subscription class schema. |
SubscriptionFieldCollection
| Represents a collection of fields as SubscriptionField objects. The
|
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 |
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 |
SubscriptionEventRule
| Represents an event rule that contains simple (not conditional)
actions. |
SubscriptionEventRuleCollection
| Represents a collection of subscription event rules as
|
SubscriptionScheduledRule
| Represents a scheduled rule that contains actions that do
not use conditions to generate notifications. |
SubscriptionScheduledRuleCollection
| Represents a collection of scheduled rules as
|
|

