MS SQL Server
  Home arrow MS SQL Server arrow Creating Important Aspects of Notification...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Creating Important Aspects of Notification Services
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-03-22

    Table of Contents:
  • Creating Important Aspects of Notification Services
  • Creating an Event Provider
  • Creating a Generator
  • Creating a Vacuum Schedule
  • Creating a Subscription
  • Enumerating a Notification Services Instance Database
  • Enumerating a Notification Services Application Database

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating Important Aspects of Notification Services


    (Page 1 of 7 )

    In this final part of a three-part article, you will learn how to create a notification class, event provider, and much more. It is excerpted from chapter 18 of Programming SQL Server 2005, written by Bill Hamilton (O'Reilly, 2006; ISBN: 0596004796). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    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 FileandSMTPare created in theCreateNotificationClass()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);
      }

    TheNotificationClass object represents a type of notification supported by a Notification Services application. ANotificationFieldobject represents a field in a notification class schema. The notification class in this example has two fields—Symbolof typenvarchar(6)andPriceof typefloat.

    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 NotificationClassobjects. TheNotificationClasses property of theApplicationclass returns the notification classes for the Notification Services application.
    NotificationComputedField Represents a computed field in a notification class schema.
    NotificationComputedFieldCollection Represents a collection of computed fields as NotificationComputedFieldobjects. The NotificationComputedFieldsproperty of the NotificationClassclass returns the computed fields for the notification class.
    NotificationField Represents a noncomputed field in a notification class schema.
    NotificationFieldCollection Represents a collection of fields asNotificationFieldobjects. TheNotificationFieldsproperty of the NotificationClassclass returns the fields for the notification class.

    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:

    XsltBaseDirectoryPath
      
    The root directory for all XSLT files.

    XsltFileName
      
    The name of the XSLT file used to transform raw
       notification data into formatted data for notification
       delivery.

    DisableEscaping
      
    An optional Boolean argument indicating that the
       event data contains either HTML or XML data
       preventing further transformation. The default value
       isfalse.

    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. TheContentFormatterproperty of theNotificationClassclass returns the content formatter for the notification class.
    ContentFormatterArgument Represents a name-value pair for a content formatter initialization argument.
    ContentFormatterArgumentCollectionRepresents a collection of initialization arguments as ContentFormatterArgumentobjects. The ContentFormatterArgumentsproperty of the ContentFormatterclass returns the initialization arguments for the content formatter.

    A notification class protocol represents a delivery protocol for a notification class. AProtocolFieldobject 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 theProtocolField object is set using either theSqlExpressionorFieldReferenceproperty. 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 NotificationClassProtocolobjects. The NotificationClassProtocolsproperty of the NotificationClassclass returns the delivery classes for the notification class.

    ProtocolDefinition

    Represents a custom delivery protocol.

    ProtocolDefinitionCollection

    Represents a collection of custom delivery protocols as ProtocolDefinitionobjects. TheProtocolDefinitions property of theInstanceclass returns the custom delivery protocols for the Notification Services instance.

     ProtocolField

    Represents a protocol header field.

     ProtocolFieldCollection

    Represents a collection of protocol header fields asProtocolField objects. TheProtocolFieldsproperty of the NotificationClassProtocolclass returns the protocol header fields for the delivery protocol.

     ProtocolRetrySchedule

    Represents a retry schedule interval.

     ProtocolRetryScheduleCollection

    Represents a collection of retry schedule intervals as ProtocolRetryScheduleobjects. The ProtocolRetrySchedulesproperty of the NotificationClassProtocolclass returns the retry schedules for notifications sent using the delivery protocol.

     

    More MS SQL Server Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming SQL Server 2005," published by...
     

    Buy this book now. 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.

    MS SQL SERVER ARTICLES

    - Windows Server 2008 as a Workstation OS
    - An Overview of Windows Server 2008 R2
    - LINQ to MySQL, Oracle and PostgreSQL Provide...
    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT