Share via


Monitoring Advertisements

Logging plug-ins create logs that record information about a client and about the content that has been received and/or played by the client. When a client renders a playlist entry for which the role attribute equals "Advertisement", it sends a log in which the cs-media-role value is also set to "Advertisement". You can then parse the log to obtain information about the ad. For more information, see Advertisement Support. For general information about logging plug-ins, see Creating Logging Plug-ins.

In the following examples, the WMS Client Logging plug-in included with Windows Media Services is configured by using its administration interface. The examples illustrate how to configure the system logging plug-in to log only information pertaining to advertisements.

Note

   To use the C++ system plug-in interfaces, the following line must appear in your code exactly as shown, or the interfaces will not be properly defined. When this import statement is used, it is not necessary to include a reference to the file "WMSServer.h."

  •                                    raw_interfaces_only
    

Visual Basic .NET Example

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

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

Try

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

    ' Retrieve the plug-in to be configured.
    Plugin = Server.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"

    ' If the plug-in is already enabled, cycle the log so
    ' that the new configuration will take effect immediately.
    If Plugin.Enabled = True Then
        LogAdmin.CycleNow()
    Else
        Plugin.Enabled = True
    End If

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;
IWMSPlugin Plugin;
IWMSPlugins Plugins;
IWMSLoggingAdmin LogAdmin;
int i;

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

    // Retrieve the plug-in to be configured.
    Plugins = Server.EventHandlers;
    for (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";

          // If the plug-in is already enabled, cycle the log so
          // that the new configuration will take effect immediately.
          if (Plugin.Enabled == true)
          {
               LogAdmin.CycleNow();
          }
          else
          {
              Plugin.Enabled = true;
          }
       }
    }
}
catch (COMException comExc)
{
    // TODO: Handle COM exceptions.
}
catch (Exception exc)
{
     // TODO: Exception handler goes here.
}
finally
{
    // TODO: Clean-up code goes here.
}

C++ Example

#include <windows.h>
#include <atlbase.h>    // Includes CComBSTR and CComVariant.

// To access system plug-in interfaces, the
// entire type library must be imported as shown.
#import "WMSServerTypeLib.dll" no_namespace named_guids \
                               raw_interfaces_only

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

HRESULT         hr;
VARIANT_BOOL    bEnabled;
CComVariant     varIndex;
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 an IWMSPlugins interface
// containing event handler plug-ins.
hr = pServer->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;

// If the plug-in is already enabled, cycle the log so
// that the new configuration will take effect immediately.
hr = pPlugin->get_Enabled(&bEnabled);
if (FAILED(hr)) goto EXIT;

if (bEnabled == VARIANT_TRUE)
{
   hr = pLogAdmin->CycleNow();
   if (FAILED(hr)) goto EXIT;
}
else
{
   hr = pPlugin->put_Enabled(VARIANT_TRUE);
   if (FAILED(hr)) goto EXIT;
}

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

See Also

Concepts

Programming the Server Object Model