Notification Services—Creating a Subscription
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Creating a Subscription
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); }
The NSApplication class represents a Notification Services application. The
Subscription class represents a subscription in a Notification Services application.
Both subscriptions use the subscriber device named StockWatchSubscriberDevice created
in the "Creating a Subscriber and Subscriber Device" section earlier in this
chapter. The subscription for KristinHamilton is for events for ticker symbol ABC,
while the subscription for subscriber TonyHamilton is for events for ticker symbol DEF.
The results can be seen in the notifications shown in Figures 18-7 and 18-8.
The SubscriptionEnumeration class represents a collection of subscriptions as
Subscription objects in a Notification Services application. Use the SubscriptionEnumeration
class 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.
|

