Notification Services—Creating a Subscriber and Subscriber Device


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

Notification Services

© 2006 O'Reilly Media, Inc.

Creating a Subscriber and Subscriber Device

Two subscribers, each with a single subscriber device, are created in the CreateSubscriber( ) method of Example 18-1. The code follows:

private static void CreateSubscriber( )
{
  ns.NSInstance swnsi = 
    new ns.NSInstance("StockWatch");
  ns.Subscriber s;
  ns.SubscriberDevice sd;
 
  // create a subscriber
  s = new ns.Subscriber(swnsi);
  s.SubscriberId = @"KristinHamilton";
  s.Add( );
  Console.WriteLine("Added subscriber: " + 
    s.SubscriberId);
  
  // create a file subscriber device
  sd = new ns.SubscriberDevice( );
  sd.Initialize(swnsi);
  sd.DeviceName = "StockWatchSubscriberDevice";
  sd.SubscriberId = "KristinHamilton";
  sd.DeviceTypeName = "File";
  sd.DeviceAddress = "KristinH@StockWatch.ns";
  sd.DeliveryChannelName = 
    "StockWatchFileDeliveryChannel";
  sd.Add( );
  Console.WriteLine("Added subscriber file device.");
 
  // create a subscriber
  s = new ns.Subscriber(swnsi);
  s.SubscriberId = @"TonyHamilton";
  s.Add( );
  Console.WriteLine("Added subscriber: " + s.SubscriberId);
  
  // create an email subscriber device
  sd = new ns.SubscriberDevice( );
  sd.Initialize(swnsi);
  sd.DeviceName = "StockWatchSubscriberDevice";
  sd.SubscriberId = "TonyHamilton";
  sd.DeviceTypeName = "Email";
  sd.DeviceAddress = "TonyH@StockWatchNS.ns";
  sd.DeliveryChannelName = "StockWatchEmailDeliveryChannel";
  sd.Add( );
  Console.WriteLine("Added subscriber email device.");
}

The NSInstance class represents a Notification Services instance that is registered in the Windows registry.

The Subscriber class represents a subscriber in a Notification Services instance. The SubscriberEnumeration class represents a collection of subscribers as Subscriber objects in a Notification Services instance.

The SubscriberEnumeration class is used to retrieve a Subscriber object from the collection of subscribers to the Notification Services instance. The Delete( ) method removes a subscriber, the Add( ) method adds a subscriber, and the Update( ) method updates the information for an existing subscriber. The following code deletes the subscriber AnySubscriber from a Notification Service instance named HelloWorld:

NSInstance nins = new NSInstance("HelloWorld");
SubscriberEnumeration se = new SubscriberEnumeration(nins);
se["AnySubscriber"].Delete( );

The SubscriberDevice class represents a device that can receive notifications. A single subscriber device is added to each subscriber. Each subscriber device specifies the following properties:

DeviceName
The name of the subscriber device.
SubscriberId
The ID of the subscriber with which the subscriber device is associated.
DeviceTypeName
The name of the device type for the subscriber device.
DeviceAddress
The address used to contact the device.
DeliveryChannelName
The name of the delivery channel that the device uses. This example assigns the StockWatchFileDeliveryChannel delivery channel to one subscriber and the StockWatchEmailDeliveryChannel delivery channel to the other—these delivery channels are created in the code described in the "Creating a Delivery Channel" section earlier in this chapter.

The SubscriberDeviceEnumeration class is used to retrieve a SubscriberDevice object from the collection of devices for a subscriber. The Delete( ) method removes a device, the Add( ) method adds a device, and the Update( ) method updates the information for an existing device.


Previous_Page_.gif Next_Page_.gif


Personal tools