Creating Important Aspects of Notification Services - Creating a Subscription
(Page 5 of 7 )
Two subscriptions are created in the CreateSubscription() method of Example 18-1. The code follows:
private static void CreateSubscription()
{
ns.NSInstance swnsi = new ns.NSInstance("StockWatch");
ns.NSApplication a = new ns.NSApplication(swnsi, "StockWatchApp");
ns.Subscription s;
// add subscriptions
s = new ns.Subscription();
s.Initialize(a, "StockWatchSubscriptions");
s.SetFieldValue("DeviceName", "StockWatchSubscriberDevice");
s.SetFieldValue("SubscriberLocale", "en-us");
s.SubscriberId = "KristinHamilton";
s.SetFieldValue("Symbol", "ABC");
s.SetFieldValue("Price", "0.00");
s.Add();
Console.WriteLine("Added subscription: " + s.SubscriberId);
s = new ns.Subscription();
s.Initialize(a, "StockWatchSubscriptions");
s.SetFieldValue("DeviceName", "StockWatchSubscriberDevice");
s.SetFieldValue("SubscriberLocale", "en-us");
s.SubscriberId = "TonyHamilton";
s.SetFieldValue("Symbol", "DEF");
s.SetFieldValue("Price", "0.00");
s.Add();
Console.WriteLine("Added subscription: " + s.SubscriberId);
}
TheNSApplication class represents a Notification Services application. TheSubscriptionclass represents a subscription in a Notification Services application. Both subscriptions use the subscriber device namedStockWatchSubscriberDevicecreated in the “Creating a Subscriber and Subscriber Device” section earlier in this chapter. The subscription forKristinHamilton is for events for ticker symbolABC, while the subscription for subscriberTonyHamilton is for events for ticker symbolDEF. The results can be seen in the notifications shown in Figures 18-7 and 18-8.
TheSubscriptionEnumeration class represents a collection of subscriptions asSubscription objects in a Notification Services application. Use the
SubscriptionEnumerationclass to iterate over a collection of subscriptions for an application and manage the individual subscriptions in the collection. These two classes are implemented in the Microsoft.SqlServer.NotificationServices namespace.
Next: Enumerating a Notification Services Instance Database >>
More MS SQL Server Articles
More By O'Reilly Media
|
This article is excerpted from chapter 18 of 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.
|
|