次の方法で共有


NotificationClass Class

Notification Services アプリケーション内の通知クラスを表します。

名前空間: Microsoft.SqlServer.Management.Nmo
アセンブリ: Microsoft.SqlServer.Smo (microsoft.sqlserver.smo.dll 内)

構文

'宣言
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

解説

通知クラスは、アプリケーションによって生成される通知を 1 種類定義します。Notification Services アプリケーションを定義するときには、アプリケーションによってサポートされる通知の種類ごとに、通知クラスを 1 つ作成します。

詳細については、「通知クラスの定義」を参照してください。

継承階層

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

使用例

次の例は、完全な通知クラスを定義してアプリケーションに追加する方法を示しています。

// 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)

スレッド セーフ

この型の public static (Microsoft Visual Basic では共有 ) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

プラットフォーム

開発プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

対象プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

参照

関連項目

NotificationClass Members
Microsoft.SqlServer.Management.Nmo Namespace

その他の技術情報

通知クラスの定義
NotificationClass 要素 (ADF)