Delving Deeper into Notification Services - Creating a Subscription Class and Subscription Event Rule
(Page 4 of 4 )
A subscription class with a single subscription event rule is created in the CreateSubscriptionClassMethod() method of Example 18-1. The code follows:
CreateSubscriptionClassMethod( ) method of Example 18-1. The code follows: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);
}
ASubscriptionClass object defines a type of subscription within a Notification Services application. TheSubscriptionField objects added to theSubscriptionobject represent fields in the subscription class schema. ASubscriptionChronicleobject lets you store subscription information outside of tables used by the subscription class—this example does not use a subscription chronicle.
The NMO classes for managing subscription chronicles, subscription classes, and subscription fields are described in Table 18-5.
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 SubscriptionChronicleobjects. TheSubscriptionChronicles property of theSubscriptionClassclass returns the subscription chronicles for the subscription class. |
| SubscriptionClass | Represents a subscription class. |
| SubscriptionClassCollection | Represents a collection of subscription classes asSubscriptionClass objects. TheSubscriptionClassesproperty of theApplication 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 asSubscriptionFieldobjects. The SubscriptionFieldsproperty of theSubscriptionClassclass returns the fields for the subscription class schema. |
ASubscriptionEventRule object represents a rule that uses T-SQL queries to generate notifications when event batches arrive. TheActionproperty represents the T-SQL query for theSubscriptionEventRuleobject. 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 rulesClass | Description |
SubscriptionCondition EventRule | Represents a subscription rule that the generator runs against subscriptions that use conditions to generate notifications. |
SubscriptionCondition EventRuleCollection | Represents a collection of subscription condition event rules as SubscriptionConditionEventRule objects. The subscriptionConditionEvent-Rulesproperty of the SubscriptionClassclass returns the subscription condition event rules for the subscription class. |
SubscriptionCondition ScheduledRule | Represents a subscription rule that the generator runs against scheduled subscriptions that use conditions to generate notifications. |
SubscriptionCondition ScheduledRuleCollection | Represents a collection of subscription condition scheduled rules as SubscriptionConditionScheduled-Ruleobjects. The SubscriptionCondition-ScheduledRulesproperty of the SubscriptionClassclass returns the subscription condition scheduled rules for the subscription class. |
SubscriptionEventRule | Represents an event rule that contains simple (not conditional) actions. |
SubscriptionEvent RuleCollection | Represents a collection of subscription event rules as SubscriptionEventRuleobjects. The SubscriptionEventRulesproperty of the SubscriptionClassclass returns the subscription event rules for the subscription class. |
SubscriptionScheduled Rule | Represents a scheduled rule that contains actions that do not use conditions to generate notifications. |
SubscriptionScheduled RuleCollection | Represents a collection of scheduled rules as SubscriptionScheduledRuleobjects. The SubscriptionScheduledRulesproperty of the SubscriptionClassclass returns the scheduled rules for the subscription class. |
Please check back next week for the conclusion of this article.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
|
This article is excerpted from chapter 18 of the book Programming SQL Server 2005, written by Bill Hamilton (O'Reilly, 2006; ISBN: 0596004796). Check it out today at your favorite bookstore. Buy this book now.
|
|