Share via


Enabling and Configuring Logging on Your New On-Demand Publishing Point

banner art

Previous Next

Enabling and Configuring Logging on Your New On-Demand Publishing Point

Logging events on your publishing point can provide valuable statistical feedback for you and your advertising partners. It can tell you how many times a particular media element has been streamed, as well as how many unique players have been connected to your server. The following Visual Basic .NET, C#, and C++ examples show you how to configure logging for your new publishing point—specifically, how to log each time that an advertisement is streamed from your publishing point.

Visual Basic .NET Example

Imports Microsoft.WindowsMediaServices.Interop
Imports System.Runtime.InteropServices

' Declare variables.
Dim Server As WMSServer
Dim LogAdmin As IWMSLoggingAdmin
Dim ODPubPoint As IWMSOnDemandPublishingPoint
Dim Plugin As IWMSPlugin

Try
    ' Create the WMSServer object.
    Server = New WMSServer()

    ' Retrieve an on-demand publishing point.
    ODPubPoint = Server.PublishingPoints.Item("NewPubPointII")

    ' Retrieve the plug-in to be configured.
    Plugin = ODPubPoint.EventHandlers.Item("WMS Client Logging")

    ' Retrieve the custom interface of the plug-in.
    LogAdmin = Plugin.CustomInterface

    ' Configure the plug-in to log only events that
    ' fulfill certain requirements.
    LogAdmin.LoggedEvents = WMS_LOG_EVENT_TYPE.WMS_LOG_EVENT_PLAYER Or _
                    WMS_LOG_EVENT_TYPE.WMS_LOG_EVENT_LOCAL Or _
                    WMS_LOG_EVENT_TYPE.WMS_LOG_EVENT_FILTER_ON_ROLE

    ' Configure the filter so that only content with
    ' an "Advertisement" role gets logged.
    LogAdmin.RoleFilter = "Advertisement"

    ' Be sure the logging plug-in is enabled.
    Plugin.Enabled = True

    ' Cycle the log so that the new configuration
    ' will take effect immediately.
    LogAdmin.CycleNow()

Catch errCom As COMException
    ' TODO: Handle COM exceptions.
Catch err As Exception
    ' TODO: Exception handler goes here.
Finally
' TODO: Clean-up code goes here.
End Try

C# Example

using Microsoft.WindowsMediaServices.Interop;
using System.Runtime.InteropServices;

// Declare variables.
WMSServer Server;
IWMSLoggingAdmin LogAdmin;
IWMSOnDemandPublishingPoint ODPubPoint;
IWMSPlugins Plugins;
IWMSPlugin Plugin;

try 
{
    // Create the WMSServer object.
    Server = new WMSServerClass();

    // Retrieve an on-demand publishing point.
    ODPubPoint = 
(IWMSOnDemandPublishingPoint)Server.PublishingPoints["NewPubPointII"];

    // Retrieve the plug-in to be configured.
    Plugins = Server.EventHandlers;
    for (int i = 0; i< Plugins.Count; i++)
    {
        if ("WMS Client Logging" == Plugins[i].Name)
        {
            Plugin = Plugins[i];

            // Retrieve the custom interface of the plug-in.
            LogAdmin = (IWMSLoggingAdmin)Plugin.CustomInterface;

            // Configure the plug-in to log only events that
            // fulfill certain requirements.
            LogAdmin.LoggedEvents = 
                          WMS_LOG_EVENT_TYPE.WMS_LOG_EVENT_PLAYER |
                          WMS_LOG_EVENT_TYPE.WMS_LOG_EVENT_LOCAL |
                          WMS_LOG_EVENT_TYPE.WMS_LOG_EVENT_FILTER_ON_ROLE;

            // Configure the filter so that only content with
            // an "Advertisement" role gets logged.
            LogAdmin.RoleFilter = "Advertisement";

            // Be sure the logging plug-in is enabled.
            Plugin.Enabled = true;

            // Cycle the log so that the new configuration
            // will take effect immediately.
            LogAdmin.CycleNow();
            break;
        }
    }
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception exc) 
{
    // TODO: Handle exceptions.
}
finally 
{
    // Clean-up code goes here.
}

C++ Example

#include <windows.h>
#include <atlbase.h>    // Includes CComBSTR.
#include "wmsserver.h"

// Declare variables and interfaces.
IWMSServer              *pServer;
IWMSPublishingPoints    *pPubPoints;
IWMSPublishingPoint     *pPubPoint;
IWMSPlugins             *pPlugins;
IWMSPlugin              *pPlugin;
IDispatch               *pDispatch;
IWMSLoggingAdmin        *pLogAdmin;

HRESULT         hr;
CComVariant     varIndex;
CComVariant     varName;
CComBSTR        bstrFilter;

// Initialize the COM library and retrieve a pointer
// to an IWMSServer interface.
hr = CoInitialize(NULL);
hr = CoCreateInstance(CLSID_WMSServer,
                      NULL,
                      CLSCTX_ALL,
                      IID_IWMSServer,
                      (void **)&pServer);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the IWMSPublishingPoints
// interface.
hr = pServer->get_PublishingPoints(&pPubPoints);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to a publishing point.
varName = L"NewPubPointII";
hr = pPubPoints->get_Item(varName, &pPubPoint);

// Retrieve a pointer to an IWMSPlugins interface
// containing event handler plug-ins.
hr = pPubPoint->get_EventHandlers(&pPlugins);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to an IWMSPlugin interface
// of the plug-in to be configured.
varIndex = "WMS Client Logging";
hr = pPlugins->get_Item(varIndex, &pPlugin);
if (FAILED(hr)) goto EXIT;

// Retrieve a pointer to the custom interface
// of the plug-in.
hr = pPlugin->get_CustomInterface(&pDispatch);
if (FAILED(hr)) goto EXIT;

// Query the specific administration interface
// for the plug-in.
hr = pDispatch->QueryInterface(IID_IWMSLoggingAdmin,
                              (void **)&pLogAdmin);
if (FAILED(hr)) goto EXIT;

// Configure the plug-in to log only events that
// fulfill certain requirements.
DWORD dwLogEvents;
dwLogEvents = WMS_LOG_EVENT_PLAYER | WMS_LOG_EVENT_LOCAL |
              WMS_LOG_EVENT_FILTER_ON_ROLE;
hr = pLogAdmin->put_LoggedEvents((WMS_LOG_EVENT_TYPE)dwLogEvents);
if (FAILED(hr)) goto EXIT;

// Configure the filter so that only content with
// an "Advertisement" role gets logged.
bstrFilter = "Advertisement";
hr = pLogAdmin->put_RoleFilter(bstrFilter);
if (FAILED(hr)) goto EXIT;

// Be sure the logging plug-in is enabled.
hr = pPlugin->put_Enabled(VARIANT_TRUE);
if (FAILED(hr)) goto EXIT;

// Cycle the log so that the new configuration
// will take effect immediately.
hr = pLogAdmin->CycleNow();
if (FAILED(hr)) goto EXIT;

EXIT:
    // TODO: Release temporary COM objects and uninitialize COM.

See Also (General)

See Also (Visual Basic .NET)

See Also (C#)

See Also (C++)

Previous Next