取得訂閱者的裝置及訂閱
Subscriber 類別提供 GetSubscriptions 及 GetDevices 方法,來提供對訂閱者裝置和與指定的訂閱者相關的訂閱記錄的存取權。
使用 GetSubscriptions 方法 (屬於 Subscriber 類別) 傳回 SubscriptionEnumeration 物件,來代表指定的訂閱者的一個應用程式中的一個訂閱類別的所有訂閱的集合。
使用 GetDevices 方法 (屬於 Subscriber 類別) 傳回 SubscriberDeviceEnumeration 物件,來代表指定的訂閱者的所有裝置的集合。
Managed 程式碼範例:傳回訂閱
下列程式碼範例顯示如何使用 Managed 程式碼中的 Subscriber 物件,來傳回訂閱類別中的所有訂閱者訂閱的訂閱欄位的值。
string instanceName = "Tutorial";
string applicationName = "Weather";
string subscriptionClassName = "WeatherCity";
string subscriptionFieldName = "City";
// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);
// Create the Subscriber object.
Subscriber testSubscriber = new Subscriber(testInstance);
// Set the subscriber ID so that the
// correct records are retrieved.
testSubscriber.SubscriberId = "TestUser1";
// Create the NSApplication object.
NSApplication testApplication =
new NSApplication(testInstance, applicationName);
// Retrieve the subscriber's subscriptions.
SubscriptionEnumeration testSubscriptionEnumeration =
testSubscriber.GetSubscriptions
(testApplication, subscriptionClassName);
foreach (Subscription singleSub in testSubscriptionEnumeration)
{
Console.WriteLine(singleSub[subscriptionFieldName].ToString());
}
Console.ReadLine();
Managed 程式碼範例:傳回裝置
下列範例顯示如何使用 Managed 程式碼中的 Subscriber 物件,來傳回屬於單一訂閱者的所有裝置。
string instanceName = "Tutorial";
// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);
// Create the Subscriber object.
Subscriber testSubscriber = new Subscriber(testInstance);
// Set the subscriber ID so that the
// correct records are retrieved.
testSubscriber.SubscriberId = "TestUser1";
// Retrieve the subscriber's devices.
SubscriberDeviceEnumeration testSubscriberDeviceEnumeration =
testSubscriber.GetDevices();
// Print each device to the console.
foreach (SubscriberDevice singleSubDevice in
testSubscriberDeviceEnumeration)
{
Console.WriteLine(singleSubDevice.DeviceName);
}
Console.ReadLine();
COM Interop 範例:傳回訂閱
下列 VBScript 程式碼範例顯示如何使用 Managed 程式碼中的 Subscriber 物件,來傳回訂閱類別中的所有訂閱者訂閱的訂閱欄位的值。
Dim testInstance, testSubscriber, _
testApplication, testSubscriptionEnumeration
const instanceName = "Tutorial"
const applicationName = "Weather"
const subscriptionClassName = "WeatherCity"
const subscriptionFieldName = "City"
' Create the NSInstance object.
set testInstance = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName
' Create the Subscriber object.
set testSubscriber = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.Subscriber")
testSubscriber.Initialize (testInstance)
' Create the NSApplication object.
set testApplication = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSApplication")
testApplication.Initialize (testInstance), applicationName
' Set the subscriber ID
testSubscriber.SubscriberID = "TestUser2"
' Retrieve a subscriber's subscriptions.
set testSubscriptionEnumeration = _
testSubscriber.GetSubscriptions((testApplication), _
subscriptionClassName)
' Print field value
for each subscription in testSubscriptionEnumeration
Wscript.Echo "Field Value", _
subscription.GetFieldValue(subscriptionFieldName)
next
wscript.echo "Done!"
COM Interop 範例:傳回裝置
下列 VBScript 範例顯示如何使用 Managed 程式碼中的 Subscriber 物件,來傳回屬於單一訂閱者的所有裝置。
Dim testInstance, testSubscriber, testSubscriberDeviceEnumeration
const instanceName = "Tutorial"
' Create the NSInstance object.
set testInstance = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName
' Create the Subscriber object.
set testSubscriber = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.Subscriber")
testSubscriber.Initialize (testInstance)
' Set the subscriber ID so that the
testSubscriber.SubscriberId = "TestUser2"
' Retrieve the subscriber's devices.
set testSubscriberDeviceEnumeration = testSubscriber.GetDevices
for each singleSubDevice in testSubscriberDeviceEnumeration
Wscript.Echo "Device Name:", singleSubDevice.DeviceName
next
wscript.echo "Done!"
請參閱
概念
建立訂閱者物件
新增訂閱者記錄
更新訂閱者記錄
刪除訂閱者記錄
刪除相關的訂閱資訊