SubscriptionClass Class
Represents a subscription class in a Notification Services application.
Spazio dei nomi: Microsoft.SqlServer.Management.Nmo
Assembly : Microsoft.SqlServer.Smo (in microsoft.sqlserver.smo.dll)
Sintassi
'Dichiarazione
Public NotInheritable Class SubscriptionClass
Inherits NamedSmoObject
public sealed class SubscriptionClass : NamedSmoObject
public ref class SubscriptionClass sealed : public NamedSmoObject
public final class SubscriptionClass extends NamedSmoObject
public final class SubscriptionClass extends NamedSmoObject
Osservazioni
A subscription class defines one type of subscription for your application. When you define a Notification Services application, you must create one subscription class for each type of subscription that is supported by your application.
When Notification Services creates the application, it creates tables, views, basic indexes, and stored procedures for the subscription class. The core subscription class properties define the names and locations for these database objects.
Inheritance Hierarchy
System.Object
Microsoft.SqlServer.Management.Smo.SmoObjectBase
Microsoft.SqlServer.Management.Smo.SqlSmoObject
Microsoft.SqlServer.Management.Smo.NamedSmoObject
Microsoft.SqlServer.Management.Nmo.SubscriptionClass
Esempio
The following examples show a complete subscription class. A subscription class in a real application would probably not use all of the properties shown here, but this shows the available properties and how to define them:
// Create a subscription class
SubscriptionClass flightSubscriptions =
new SubscriptionClass(myApplication, "FlightSubscriptions");
flightSubscriptions.FileGroup = "PRIMARY";
// Define subscription class fields
// Define a DeviceName field that cannot be NULL
// Add the field to the end of the field collection
SubscriptionField subDevice =
new SubscriptionField(flightSubscriptions, "DeviceName");
subDevice.Type = "nvarchar(255)";
subDevice.TypeModifier = "not null";
flightSubscriptions.SubscriptionFields.Add(subDevice);
// Define a SubscriberLocale field that cannot be NULL
// Add the field to the end of the field collection
SubscriptionField subLocale =
new SubscriptionField(flightSubscriptions, "SubscriberLocale");
subLocale.Type = "nvarchar(10)";
subLocale.TypeModifier = "not null";
flightSubscriptions.SubscriptionFields.Add(subLocale);
// Add a GoingTo field and add it at position 2
SubscriptionField subDestination =
new SubscriptionField(flightSubscriptions, "GoingTo");
subDestination.Type = "nvarchar(6)";
flightSubscriptions.SubscriptionFields.Add(subDestination, 2);
// Define a LeavingFrom field and add it before the GoingTo field
SubscriptionField subOrgin =
new SubscriptionField(flightSubscriptions, "LeavingFrom");
subOrgin.Type = "nvarchar(6)";
flightSubscriptions.SubscriptionFields.Add(subOrgin, "GoingTo");
// Define a Price field and add to the end of the collection
SubscriptionField subPrice =
new SubscriptionField(flightSubscriptions, "Price");
subPrice.Type = "float";
flightSubscriptions.SubscriptionFields.Add(subPrice);
// Add an index to the subscription class.
flightSubscriptions.IndexSqlStatements.Add(
"CREATE INDEX FlightSubscriptionsIndex ON " +
"MyAppSchema.FlightSubscriptions ( LeavingFrom, GoingTo )");
// Add a rule to generate basic event-triggered notifications
SubscriptionEventRule flightEventRule =
new SubscriptionEventRule(flightSubscriptions,
"FlightSubscriptionsEventRule");
flightEventRule.Action = "INSERT INTO FlightNotifications " +
"(SubscriberId, DeviceName, SubscriberLocale, " +
"LeavingFrom, GoingTo, Price) " +
"SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " +
"E.LeavingFrom, E.GoingTo, E.Price " +
"FROM FlightEvents E, FlightSubscriptions S " +
"WHERE E.LeavingFrom = S.LeavingFrom " +
"AND E.GoingTo = S.GoingTo " +
"AND E.Price < S.Price";
flightEventRule.ActionTimeout = new TimeSpan(0, 1, 0);
flightEventRule.EventClassName = "FlightEvents";
flightSubscriptions.SubscriptionEventRules.Add(flightEventRule);
// Add a rule to generate basic scheduled notifications
SubscriptionScheduledRule flightScheduledRule =
new SubscriptionScheduledRule(
flightSubscriptions, "FlightScheduledRule");
flightScheduledRule.Action = "INSERT INTO FlightNotifications " +
"(SubscriberId, DeviceName, SubscriberLocale, " +
" LeavingFrom, GoingTo, Price) " +
" SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " +
" EC.LeavingFrom, EC.GoingTo, EC.Price " +
" FROM FlightEventChronicle EC, FlightSubscriptions S " +
" WHERE EC.LeavingFrom = S.LeavingFrom " +
" AND EC.GoingTo = S.GoingTo " +
" AND EC.Price < S.Price";
flightScheduledRule.ActionTimeout = new TimeSpan(0, 0, 30);
flightSubscriptions.SubscriptionScheduledRules.Add(
flightScheduledRule);
// Add a rule to generate condition-based, event notifications
SubscriptionConditionEventRule flightConditionEventRule =
new SubscriptionConditionEventRule(
flightSubscriptions, "FlightConditionEventRule");
flightConditionEventRule.EventClassName = "FlightEvents";
flightConditionEventRule.ActionTimeout = new TimeSpan(0, 2, 0);
flightConditionEventRule.SqlLoginName = "MyLowPrivLogin";
flightConditionEventRule.SqlUserName = "MyLowPrivUser";
flightConditionEventRule.InputTypeName = "FlightEvents";
flightConditionEventRule.InputTypeSchema = "MyAppSchema";
flightConditionEventRule.SqlExpression =
"INSERT INTO MyAppSchema.FlightNotifications (SubscriberId, " +
"DeviceName, SubscriberLocale, LeavingFrom, GoingTo, Price) " +
"SELECT [Subscription.SubscriberId], [Subscription.DeviceName], " +
"[Subscription.SubscriberLocale], " +
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " +
"FROM MyAppSchema.FlightConditionEventRule;";
flightSubscriptions.SubscriptionConditionEventRules.Add(
flightConditionEventRule);
// Add a rule to generate condition-based, scheduled notifications
SubscriptionConditionScheduledRule flightConditionScheduledRule =
new SubscriptionConditionScheduledRule(
flightSubscriptions, "FlightConditionScheduledRule");
flightConditionScheduledRule.ActionTimeout =
new TimeSpan(0, 2, 0);
flightConditionScheduledRule.SqlLoginName = "MyLowPrivLogin";
flightConditionScheduledRule.SqlUserName = "MyLowPrivUser";
flightConditionScheduledRule.InputTypeName = "FlightEventChronicle";
flightConditionScheduledRule.InputTypeSchema = "MyAppSchema";
flightConditionScheduledRule.SqlExpression =
"INSERT INTO MyAppSchema.FlightNotifications (SubscriberId, " +
"DeviceName, SubscriberLocale, LeavingFrom, GoingTo, Price) " +
"SELECT [Subscription.SubscriberId], " +
"[Subscription.DeviceName], [Subscription.SubscriberLocale], " +
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " +
"FROM MyAppSchema.FlightConditionScheduledRule;";
flightSubscriptions.SubscriptionConditionScheduledRules.Add(
flightConditionScheduledRule);
// Define a chronicle for the subscription class
SubscriptionChronicle sc1 = new SubscriptionChronicle(
flightSubscriptions, "FlightSubChronicle");
sc1.SqlStatements.Add(
"CREATE TABLE MyAppSchema.FlightSubChronicle " +
" (SubscriptionId bigint, LeavingFrom nvarchar(6), " +
" GoingTo nvarchar(6), Price float);");
sc1.SqlStatements.Add(
"CREATE INDEX FlightSubChronicleIndex " +
" ON MyAppSchema.FlightSubChronicle " +
" ( LeavingFrom, GoingTo );");
flightSubscriptions.SubscriptionChronicles.Add(sc1);
// Add the subscription class to the application
myApplication.SubscriptionClasses.Add(flightSubscriptions);
' Create a subscription class
Dim flightSubscriptions As SubscriptionClass = _
New SubscriptionClass(myApplication, "FlightSubscriptions")
flightSubscriptions.FileGroup = "PRIMARY"
' Define subscription class fields
' Define a DeviceName field that cannot be NULL
' Add the field to the end of the field collection
Dim subDevice As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "DeviceName")
subDevice.Type = "nvarchar(255)"
subDevice.TypeModifier = "not null"
flightSubscriptions.SubscriptionFields.Add(subDevice)
' Define a SubscriberLocale field that cannot be NULL
' Add the field to the end of the field collection
Dim subLocale As SubscriptionField = _
New SubscriptionField(flightSubscriptions, _
"SubscriberLocale")
subLocale.Type = "nvarchar(10)"
subLocale.TypeModifier = "not null"
flightSubscriptions.SubscriptionFields.Add(subLocale)
' Add a GoingTo field and add it at position 2
Dim subDestination As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "GoingTo")
subDestination.Type = "nvarchar(6)"
flightSubscriptions.SubscriptionFields.Add(subDestination, 2)
' Define a LeavingFrom field and add it before the GoingTo field
Dim subOrgin As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "LeavingFrom")
subOrgin.Type = "nvarchar(6)"
flightSubscriptions.SubscriptionFields.Add(subOrgin, "GoingTo")
' Define a Price field and add to the end of the collection
Dim subPrice As SubscriptionField = _
New SubscriptionField(flightSubscriptions, "Price")
subPrice.Type = "float"
flightSubscriptions.SubscriptionFields.Add(subPrice)
' Add an index to the subscription class to help improve performance
flightSubscriptions.IndexSqlStatements.Add( _
"CREATE INDEX FlightSubscriptionsIndex ON " + _
"MyAppSchema.FlightSubscriptions ( LeavingFrom, GoingTo )")
' Add a rule to generate basic event-triggered notifications
Dim flightEventRule As SubscriptionEventRule = _
New SubscriptionEventRule(flightSubscriptions, _
"FlightSubscriptionsEventRule")
flightEventRule.Action = _
"INSERT INTO FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, " + _
"LeavingFrom, GoingTo, Price) " + _
"SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " + _
"E.LeavingFrom, E.GoingTo, E.Price " + _
"FROM FlightEvents E, FlightSubscriptions S " + _
"WHERE E.LeavingFrom = S.LeavingFrom " + _
"AND E.GoingTo = S.GoingTo " + _
"AND E.Price < S.Price"
flightEventRule.ActionTimeout = New TimeSpan(0, 1, 0)
flightEventRule.EventClassName = "FlightEvents"
flightSubscriptions.SubscriptionEventRules.Add(flightEventRule)
' Add a rule to generate basic scheduled notifications
Dim flightScheduledRule As SubscriptionScheduledRule = _
New SubscriptionScheduledRule(flightSubscriptions, _
"FlightScheduledRule")
flightScheduledRule.Action = _
"INSERT INTO FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, " + _
"LeavingFrom, GoingTo, Price) " + _
"SELECT S.SubscriberId, S.DeviceName, S.SubscriberLocale, " + _
"EC.LeavingFrom, EC.GoingTo, EC.Price " + _
"FROM FlightEventChronicle EC, FlightSubscriptions S " + _
"WHERE EC.LeavingFrom = S.LeavingFrom " + _
"AND EC.GoingTo = S.GoingTo " + _
"AND EC.Price < S.Price"
flightScheduledRule.ActionTimeout = New TimeSpan(0, 0, 30)
flightSubscriptions.SubscriptionScheduledRules.Add( _
flightScheduledRule)
' Add a rule to generate condition-based, event notifications
Dim flightConditionEventRule As _
SubscriptionConditionEventRule = _
New SubscriptionConditionEventRule( _
flightSubscriptions, "FlightConditionEventRule")
flightConditionEventRule.EventClassName = "FlightEvents"
flightConditionEventRule.ActionTimeout = New TimeSpan(0, 2, 0)
flightConditionEventRule.SqlLoginName = "MyLowPrivLogin"
flightConditionEventRule.SqlUserName = "MyLowPrivUser"
flightConditionEventRule.InputTypeName = "FlightEvents"
flightConditionEventRule.InputTypeSchema = "MyAppSchema"
flightConditionEventRule.SqlExpression = _
"INSERT INTO MyAppSchema.FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, LeavingFrom, " + _
"GoingTo, Price) SELECT [Subscription.SubscriberId], " + _
"[Subscription.DeviceName], [Subscription.SubscriberLocale], " + _
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " + _
"FROM MyAppSchema.FlightConditionEventRule;"
flightSubscriptions.SubscriptionConditionEventRules.Add( _
flightConditionEventRule)
' Add a rule to generate condition-based, scheduled notifications
Dim flightConditionScheduledRule As _
SubscriptionConditionScheduledRule = _
New SubscriptionConditionScheduledRule( _
flightSubscriptions, "FlightConditionScheduledRule")
flightConditionScheduledRule.ActionTimeout = _
New TimeSpan(0, 2, 0)
flightConditionScheduledRule.SqlLoginName = "MyLowPrivLogin"
flightConditionScheduledRule.SqlUserName = "MyLowPrivUser"
flightConditionScheduledRule.InputTypeName = _
"FlightEventChronicle"
flightConditionScheduledRule.InputTypeSchema = "MyAppSchema"
flightConditionScheduledRule.SqlExpression = _
"INSERT INTO MyAppSchema.FlightNotifications " + _
"(SubscriberId, DeviceName, SubscriberLocale, LeavingFrom, " + _
"GoingTo, Price) SELECT [Subscription.SubscriberId], " + _
"[Subscription.DeviceName], [Subscription.SubscriberLocale], " + _
"[Input.LeavingFrom], [Input.GoingTo], [Input.Price] " + _
"FROM MyAppSchema.FlightConditionScheduledRule;"
flightSubscriptions.SubscriptionConditionScheduledRules.Add( _
flightConditionScheduledRule)
' Define a chronicle for the subscription class
Dim sc1 As SubscriptionChronicle = New SubscriptionChronicle( _
flightSubscriptions, "FlightSubChronicle")
sc1.SqlStatements.Add( _
"CREATE TABLE MyAppSchema.FlightSubChronicle " + _
"(SubscriptionId bigint, LeavingFrom nvarchar(6), " + _
"GoingTo nvarchar(6), Price float);")
sc1.SqlStatements.Add( _
"CREATE INDEX FlightSubChronicleIndex " + _
"ON MyAppSchema.FlightSubChronicle " + _
"( LeavingFrom, GoingTo );")
flightSubscriptions.SubscriptionChronicles.Add(sc1)
' Add the subscription class to the application
myApplication.SubscriptionClasses.Add(flightSubscriptions)
Thread Safety
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.
Piattaforme
Piattaforme di sviluppo
Per un elenco delle piattaforme supportate, vedere Requisiti hardware e software per l'Installazione di SQL Server 2005.
Piattaforme di destinazione
Per un elenco delle piattaforme supportate, vedere Requisiti hardware e software per l'Installazione di SQL Server 2005.
Vedere anche
Riferimento
SubscriptionClass Members
Microsoft.SqlServer.Management.Nmo Namespace
Altre risorse
Definizione delle classi di sottoscrizione
SubscriptionClass Element (ADF)