使用 XML 事件載入程式 API

如果您想要將 XML 資料提交至 Notification Services 應用程式,請使用 XML 事件載入器 API。使用這個 API,您可以從單一 XML 文件中產生通知批次。

XML 事件載入器 API 有一個類別:EventLoader

建立及初始化 EventLoader 類別

您可以建立及初始化 EventLoader 物件,做法是使用參數化建構函式,來傳遞 NSApplication 物件 (代表所要的 Notification Services 應用程式)、事件提供者的名稱、事件類別的名稱和 SQL 註解的 XML 結構描述檔名稱,這個結構描述檔將 XML 文件結構中的資料對應至事件類別結構

如需有關撰寫 SQL 註解的 XML 結構描述檔的詳細資訊,請參閱 Microsoft MSDN Library 中的<Authoring and Using Custom Schemas Backgrounder>(英文)。

提交事件資料

在建立及初始化 EventLoader 物件之後,請使用 LoadXml 方法,將 XML 資料來源中的一或多個事件的事件批次寫至 Notification Services 應用程式資料庫

範例

這個範例使用下列命名空間:

public bool Run()
{
    // These variables would normally be defined for
    // the class. They would be set based on the values
    // provided by the args argument of the Initialize method.
    string instanceName = "MyInstanceName";
    string applicationName = "MyApplicationName";
    string eventClassName = "MyEventClassName";
    string eventProviderName = "MyEventProviderName";
    string eventSchema = "MyEventSchemaPathAndName";
    string xmlDoc = "MyXMLDocPathAndName";

    bool returnValue = true;
    DateTime currentTime = DateTime.Now;

    try
    {
        // Get the Notification Services instance.
        NSInstance testInstance = new NSInstance(instanceName);

        // Get the Notification Services application.
        NSApplication testApplication =
            new NSApplication(testInstance, applicationName);

        // Create the EventLoader object.
        EventLoader testEventLoader =
            new EventLoader(testApplication, eventProviderName,
            eventClassName, eventSchema);

        // Write the event records from the XML data 
        // source to the application database.
        int eventsSubmitted = testEventLoader.LoadXml(xmlDoc);
    }
    catch(Exception e)
    {
        //Add code to handle errors here.
    }

    return returnValue;
}

請參閱

其他資源

開發自訂事件提供者
定義事件提供者

說明及資訊

取得 SQL Server 2005 協助