Partager via


NotificationClass Class

Represents a notification class in a Notification Services application.

Espace de noms: Microsoft.SqlServer.Management.Nmo
Assembly: Microsoft.SqlServer.Smo (in microsoft.sqlserver.smo.dll)

Syntaxe

'Déclaration
Public NotInheritable Class NotificationClass
    Inherits NamedSmoObject
public sealed class NotificationClass : NamedSmoObject
public ref class NotificationClass sealed : public NamedSmoObject
public final class NotificationClass extends NamedSmoObject
public final class NotificationClass extends NamedSmoObject

Notes

A notification class defines one type of notification generated by your application. When you define a Notification Services application, you create one notification class for each type of notification that is supported by your application.

For more information, see Définition des classes de notification.

Inheritance Hierarchy

System.Object
   Microsoft.SqlServer.Management.Smo.SmoObjectBase
     Microsoft.SqlServer.Management.Smo.SqlSmoObject
       Microsoft.SqlServer.Management.Smo.NamedSmoObject
        Microsoft.SqlServer.Management.Nmo.NotificationClass

Exemple

The following examples show how to define a complete notification class and then add it to an application:

// Create a notification class
NotificationClass flightNotifications = 
    new NotificationClass(myApplication, "FlightNotifications");


flightNotifications.FileGroup = "PRIMARY";
flightNotifications.NotificationBatchSize = 500;

// Define a LeavingFrom notification field and use it for grouping 
// digest messages. Add it to the end of the field collection
NotificationField notificationOrgin = 
    new NotificationField(flightNotifications, "LeavingFrom");
notificationOrgin.Type = "nvarchar(6)";
notificationOrgin.DigestGrouping = true;
flightNotifications.NotificationFields.Add(notificationOrgin);

// Define a Price field and add it at position 1 in the collection
NotificationField notificationPrice = 
    new NotificationField(flightNotifications, "Price");
notificationPrice.Type = "float";
flightNotifications.NotificationFields.Add(notificationPrice, 1);

// Define a GoingTo field and add it before the Price field
NotificationField notificationDestination = 
    new NotificationField(flightNotifications, "GoingTo");
notificationDestination.Type = "nvarchar(6)";
flightNotifications.NotificationFields.Add(
    notificationDestination, "Price");

NotificationComputedField computedPrice = 
    new NotificationComputedField(flightNotifications, 
    "FormattedPrice");
computedPrice.SqlExpression = "CONVERT(NVARCHAR(10), Price, 1)";
flightNotifications.NotificationComputedFields.Add(computedPrice);

// Add the XSLT content formatter to the notification class
ContentFormatter contentFormatter = 
    new ContentFormatter(flightNotifications, "XsltFormatter");

// Define content formatter arguments
ContentFormatterArgument contentFormatterArgument1 = 
    new ContentFormatterArgument(
    contentFormatter, "XsltBaseDirectoryPath");
contentFormatterArgument1.Value = @"C:\NS\Full\XSLFiles";
ContentFormatterArgument contentFormatterArgument2 = 
    new ContentFormatterArgument(contentFormatter, "XsltFileName");
contentFormatterArgument2.Value = "NoOp.xslt";

// Add arguments to content formatter
contentFormatter.ContentFormatterArguments.Add(
    contentFormatterArgument1);
contentFormatter.ContentFormatterArguments.Add(
    contentFormatterArgument2);

// Assign the content formatter to the notification class
flightNotifications.ContentFormatter = contentFormatter;

// Enable digest delivery
flightNotifications.DigestDelivery = true;

// Disable multicast (either digest or multicast not both)
flightNotifications.MulticastDelivery = false;

// Define a file protocol for notification delivery
NotificationClassProtocol fileProtocol = 
    new NotificationClassProtocol(flightNotifications, "File");

// Define fields, which map notification fields to protocol fields
ProtocolField fileProtocolField1 = 
    new ProtocolField(fileProtocol, "LeavingFrom");
fileProtocolField1.FieldReference = "LeavingFrom";
fileProtocol.ProtocolFields.Add(fileProtocolField1);

ProtocolField fileProtocolField3 = 
    new ProtocolField(fileProtocol, "Price");
fileProtocolField3.FieldReference = "FormattedPrice";
fileProtocol.ProtocolFields.Add(fileProtocolField3, 1);

ProtocolField fileProtocolField2 = 
    new ProtocolField(fileProtocol, "GoingTo");
fileProtocolField2.FieldReference = "GoingTo";
fileProtocol.ProtocolFields.Add(fileProtocolField2, "Price");

// Add file protocol to notification class
flightNotifications.NotificationClassProtocols.Add(fileProtocol);

// Define an SMTP protocol for notification delivery
NotificationClassProtocol smtpProtocol = 
    new NotificationClassProtocol(flightNotifications, "SMTP");

// Define fields for the SMTP notifications
ProtocolField smtpProtocolField1 = 
    new ProtocolField(smtpProtocol, "Subject");
smtpProtocolField1.SqlExpression = 
    "'Flight notification: '+CONVERT (NVARCHAR(30), GETDATE())";
smtpProtocol.ProtocolFields.Add(smtpProtocolField1);

ProtocolField smtpBodyField = 
    new ProtocolField(smtpProtocol, "BodyFormat");
smtpBodyField.SqlExpression = "'html'";
smtpProtocol.ProtocolFields.Add(smtpBodyField);

ProtocolField smtpFromField = 
    new ProtocolField(smtpProtocol, "From");
smtpFromField.SqlExpression = @"'sender@adventure-works.com'";
smtpProtocol.ProtocolFields.Add(smtpFromField);

ProtocolField smtpPriorityField = 
    new ProtocolField(smtpProtocol, "Priority");
smtpPriorityField.SqlExpression = "'Normal'";
smtpProtocol.ProtocolFields.Add(smtpPriorityField);

ProtocolField smtpToField = 
    new ProtocolField(smtpProtocol, "To");
smtpToField.SqlExpression = "DeviceAddress";
smtpProtocol.ProtocolFields.Add(smtpToField);

// Define protocol execution settings
smtpProtocol.FailuresBeforeEventLog = 2;
smtpProtocol.FailureEventLogInterval = new TimeSpan(0, 10, 0);
smtpProtocol.FailuresBeforeAbort = 10;
smtpProtocol.MulticastRecipientLimit = 50;
smtpProtocol.WorkItemTimeout = new TimeSpan(0, 20, 0);

// Add the SMTP protocol to the notification class
flightNotifications.NotificationClassProtocols.Add(smtpProtocol);

// Set expiration for notifications from this notification class
flightNotifications.ExpirationAge = new TimeSpan(2, 0, 0);

// Add notification class to application
myApplication.NotificationClasses.Add(flightNotifications);
' Create a notification class
Dim flightNotifications As NotificationClass = _
    New NotificationClass(myApplication, "FlightNotifications")


flightNotifications.FileGroup = "PRIMARY"
flightNotifications.NotificationBatchSize = 500

' Define a LeavingFrom field and use it for grouping
' digest messages. Add it to the end of the collection.
Dim notificationOrgin As NotificationField = _
    New NotificationField(flightNotifications, "LeavingFrom")
notificationOrgin.Type = "nvarchar(6)"
notificationOrgin.DigestGrouping = True
flightNotifications.NotificationFields.Add(notificationOrgin)

' Define a Price field and add it at position 1 
' in the collection.
Dim notificationPrice As NotificationField = _
    New NotificationField(flightNotifications, "Price")
notificationPrice.Type = "float"
flightNotifications.NotificationFields.Add( _
    notificationPrice, 1)

' Define a GoingTo field and add it before the Price field.
Dim notificationDestination As NotificationField = _
    New NotificationField(flightNotifications, "GoingTo")
notificationDestination.Type = "nvarchar(6)"
flightNotifications.NotificationFields.Add( _
    notificationDestination, "Price")

Dim computedPrice As NotificationComputedField = _
    New NotificationComputedField(flightNotifications, _
    "FormattedPrice")
computedPrice.SqlExpression = "CONVERT(NVARCHAR(10), Price, 1)"
flightNotifications.NotificationComputedFields.Add( _
    computedPrice)

' Add the XSLT content formatter to the notification class
Dim contentFormatter As ContentFormatter = _
    New ContentFormatter(flightNotifications, "XsltFormatter")

' Define content formatter arguments
Dim contentFormatterArgument1 As ContentFormatterArgument = _
    New ContentFormatterArgument(contentFormatter, _
    "XsltBaseDirectoryPath")
contentFormatterArgument1.Value = "C:\NS\Full\XSLFiles"
Dim contentFormatterArgument2 As ContentFormatterArgument = _
    New ContentFormatterArgument(contentFormatter, _
    "XsltFileName")
contentFormatterArgument2.Value = "NoOp.xslt"

' Add arguments to content formatter
contentFormatter.ContentFormatterArguments.Add( _
    contentFormatterArgument1)
contentFormatter.ContentFormatterArguments.Add( _
    contentFormatterArgument2)

' Assign the content formatter to the notification class
flightNotifications.ContentFormatter = contentFormatter

' Enable digest delivery
flightNotifications.DigestDelivery = True

' Disable multicast (use either digest or multicast, not both)
flightNotifications.MulticastDelivery = False

' Define a file protocol for notification delivery
Dim fileProtocol As NotificationClassProtocol = _
    New NotificationClassProtocol(flightNotifications, "File")

' Define fields, which map notification fields to protocol fields
Dim fileProtocolField1 As ProtocolField = _
    New ProtocolField(fileProtocol, "LeavingFrom")
fileProtocolField1.FieldReference = "LeavingFrom"
fileProtocol.ProtocolFields.Add(fileProtocolField1)

Dim fileProtocolField3 As ProtocolField = _
    New ProtocolField(fileProtocol, "Price")
fileProtocolField3.FieldReference = "FormattedPrice"
fileProtocol.ProtocolFields.Add(fileProtocolField3, 1)

Dim fileProtocolField2 As ProtocolField = _
    New ProtocolField(fileProtocol, "GoingTo")
fileProtocolField2.FieldReference = "GoingTo"
fileProtocol.ProtocolFields.Add(fileProtocolField2, "Price")

' Add file protocol to notification class
flightNotifications.NotificationClassProtocols.Add(fileProtocol)

' Define an SMTP protocol for notification delivery
Dim smtpProtocol As NotificationClassProtocol = _
    New NotificationClassProtocol(flightNotifications, "SMTP")

' Define fields for the SMTP notifications
Dim smtpProtocolField1 As ProtocolField = _
    New ProtocolField(smtpProtocol, "Subject")
smtpProtocolField1.SqlExpression = _
    "'Flight notification: '+CONVERT (NVARCHAR(30), GETDATE())"
smtpProtocol.ProtocolFields.Add(smtpProtocolField1)

Dim smtpBodyField As ProtocolField = _
    New ProtocolField(smtpProtocol, "BodyFormat")
smtpBodyField.SqlExpression = "'html'"
smtpProtocol.ProtocolFields.Add(smtpBodyField)

Dim smtpFromField As ProtocolField = _
    New ProtocolField(smtpProtocol, "From")
smtpFromField.SqlExpression = "'sender@adventure-works.com'"
smtpProtocol.ProtocolFields.Add(smtpFromField)

Dim smtpPriorityField As ProtocolField = _
    New ProtocolField(smtpProtocol, "Priority")
smtpPriorityField.SqlExpression = "'Normal'"
smtpProtocol.ProtocolFields.Add(smtpPriorityField)

Dim smtpToField As ProtocolField = _
    New ProtocolField(smtpProtocol, "To")
smtpToField.SqlExpression = "DeviceAddress"
smtpProtocol.ProtocolFields.Add(smtpToField)

' Define protocol execution settings
smtpProtocol.FailuresBeforeEventLog = 2
smtpProtocol.FailureEventLogInterval = New TimeSpan(0, 10, 0)
smtpProtocol.FailuresBeforeAbort = 10
smtpProtocol.MulticastRecipientLimit = 50
smtpProtocol.WorkItemTimeout = New TimeSpan(0, 20, 0)

' Add the SMTP protocol to the notification class
flightNotifications.NotificationClassProtocols.Add(smtpProtocol)

' Set expiration for notifications from this notification class
flightNotifications.ExpirationAge = New TimeSpan(2, 0, 0)

' Add notification class to application
myApplication.NotificationClasses.Add(flightNotifications)

Sécurité des threads

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Plateformes

Plateformes de développement

Pour obtenir la liste des plateformes prises en charge, consultez Configuration matérielle et logicielle requise pour l'installation de SQL Server 2005.

Plateformes cibles

Pour obtenir la liste des plateformes prises en charge, consultez Configuration matérielle et logicielle requise pour l'installation de SQL Server 2005.

Voir aussi

Référence

NotificationClass Members
Microsoft.SqlServer.Management.Nmo Namespace

Autres ressources

Définition des classes de notification
NotificationClass Element (ADF)