Notification Services—Creating a Notification Class, Content Formatter, and Notification Class Protocol
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
Creating a Notification Class, Content Formatter, and Notification Class Protocol
A notification class named StockWatchNotifications, a content formatter named
XsltFormatter, and two notification class protocols named File and SMTP are created
in the CreateNotificationClass( ) method of Example 18-1. The code follows:
private static void CreateNotificationClass( ) { NotificationClass nc = new NotificationClass(a, "StockWatchNotifications"); NotificationField nf; nf = new NotificationField(nc, "Symbol"); nf.Type = "nvarchar(6)"; nc.NotificationFields.Add(nf); nf = new NotificationField(nc, "Price"); nf.Type = "float"; nc.NotificationFields.Add(nf); ContentFormatter cf = new ContentFormatter (nc, "XsltFormatter"); ContentFormatterArgument cfa; cfa = new ContentFormatterArgument (cf, "XsltBaseDirectoryPath"); cfa.Value = a.BaseDirectoryPath + @"\AppDefinition"; cf.ContentFormatterArguments.Add(cfa); cfa = new ContentFormatterArgument(cf, "XsltFileName"); cfa.Value = "StockWatch.xslt"; cf.ContentFormatterArguments.Add(cfa); nc.ContentFormatter = cf; nc.DigestDelivery = true; ProtocolField pf; // add file notification class protocol NotificationClassProtocol ncpFile = new NotificationClassProtocol(nc, "File"); pf = new ProtocolField(ncpFile, "Symbol"); pf.FieldReference = "Symbol"; ncpFile.ProtocolFields.Add(pf); pf = new ProtocolField(ncpFile, "Price"); pf.FieldReference = "Price"; ncpFile.ProtocolFields.Add(pf); nc.NotificationClassProtocols.Add(ncpFile); // add email notification class protocol NotificationClassProtocol ncpEmail = new NotificationClassProtocol(nc, "SMTP"); pf = new ProtocolField(ncpEmail, "Subject"); pf.SqlExpression = "'Stock watch: ' + CONVERT(nvarchar(30), GETDATE( ))"; ncpEmail.ProtocolFields.Add(pf); pf = new ProtocolField(ncpEmail, "BodyFormat"); pf.SqlExpression = "'html'"; ncpEmail.ProtocolFields.Add(pf); pf = new ProtocolField(ncpEmail, "From"); pf.SqlExpression = "'notification@StockWatchService.com'"; ncpEmail.ProtocolFields.Add(pf); pf = new ProtocolField(ncpEmail, "Priority"); pf.SqlExpression = "'Normal'"; ncpEmail.ProtocolFields.Add(pf); pf = new ProtocolField(ncpEmail, "To"); pf.SqlExpression = "DeviceAddress"; ncpEmail.ProtocolFields.Add(pf); nc.NotificationClassProtocols.Add(ncpEmail); nc.ExpirationAge = new TimeSpan(1, 0, 0); a.NotificationClasses.Add(nc); Console.WriteLine("Added notification class: " + nc.Name); }
The NotificationClass object represents a type of notification supported by a Notification
Services application. A NotificationField object represents a field in a notification
class schema. The notification class in this example has two fields—Symbol of
type nvarchar(6) and Price of type float.
The NMO classes for managing notification classes and fields are described in Table 18-7.
Table 18-7. NMO classes for managing notification classes and fields
| Class | Description |
NotificationClass
| Represents a notification class. |
NotificationClassCollection
| Represents a collection of notification classes as
|
NotificationComputedField
| Represents a computed field in a notification class schema. |
NotificationComputedFieldCollection
| Represents a collection of computed fields as
|
NotificationField
| Represents a noncomputed field in a notification class schema. |
NotificationFieldCollection
| Represents a collection of fields as NotificationField objects.
The |
A content formatter formats notifications for a notification class. Each notification class has one content formatter that can perform different formatting based on field values in the notification. The content formatter takes three arguments:
false.The NMO classes for managing content formatters are described in Table 18-8.
Table 18-8. NMO classes for managing content formatters
| Class | Description |
ContentFormatter
| Represents a content formatter. The ContentFormatter property
of the |
ContentFormatterArgument
| Represents a name-value pair for a content formatter initialization
argument. |
ContentFormatterArgumentCollection
| Represents a collection of initialization arguments as ContentFormatterArgument objects. The ContentFormatterArguments property of the ContentFormatter class returns the initialization arguments for
the content formatter. |
A notification class protocol represents a delivery protocol for a notification class. A ProtocolField object represents a protocol header field used by some delivery protocols. Protocol field headers are different for file and email notification—examine the code and examine the file and email notifications shown in Figure 18-7 and Figure 18-8 to see the result of setting the protocol fields. The value of the ProtocolField object is set using either the SqlExpression or FieldReference property. This lets you use either a T-SQL expression or a notification field to define a protocol field value.
The NMO classes for managing protocols are described in Table 18-9.
Table 18-9. NMO classes for managing protocols
| Class | Description |
NotificationClassProtocol
| Represents a delivery protocol for a notification class. |
NotificationClassProtocolCollection
| Represents a collection of notification class protocols as NotificationClassProtocol objects. The NotificationClassProtocols property of the NotificationClass class returns the delivery classes for the notification class.
|
ProtocolDefinition
| Represents a custom delivery protocol. |
ProtocolDefinitionCollection
| Represents a collection of custom delivery protocols as ProtocolDefinition objects. The ProtocolDefinitions
property of the |
ProtocolField
| Represents a protocol header field. |
ProtocolFieldCollection
| Represents a collection of protocol header fields as ProtocolField objects. The ProtocolFields property of the NotificationClassProtocol class returns the protocol header fields for the delivery protocol.
|
ProtocolRetrySchedule
| Represents a retry schedule interval. |
ProtocolRetryScheduleCollection
| Represents a collection of retry schedule intervals as ProtocolRetrySchedule objects. The ProtocolRetrySchedules property of the NotificationClassProtocol class returns the retry schedules for notifications sent using the delivery protocol.
|
|

