Compartir a través de


IWMSCacheProxy.QueryCacheMissPolicy (C#)

The server calls the QueryCacheMissPolicy method to query the cache plug-in for a cache-miss policy.

void IWMSCacheProxy.QueryCacheMissPolicy(
  string bstrOriginUrl,
  IWMSContext pUserContext,
  IWMSCommandContext pCommandContext,
  IWMSContext pPresentationContext,
  object pCachePluginContext,
  int lQueryType,
  IWMSCacheProxyCallback pCallback,
  object varContext
);

Arguments

[in] string containing the origin URL.

[in] IWMSContextIWMSContext Object (C#) containing the User Context.

[in] IWMSCommandContextIWMSCommandContext Object (C#) containing the Command Context.

[in] IWMSContext object containing the Presentation Context.

[in] object containing a cache plug-in context.

[in] Member of the WMS_CACHE_QUERY_TYPE_FLAGS enumeration type that indicates why the server called IWMSCacheProxy.QueryCache. This must be a bitwise OR of one or more of the following values.

Value

Description

WMS_CACHE_QUERY_OPEN

A client using a downstream proxy requested content.

WMS_CACHE_QUERY_GET_CONTENT_INFO

A downstream proxy requested information about content cached on the remote computer.

WMS_CACHE_QUERY_CACHE_EVENT

A cache event notice is being sent upstream. If WMS_CACHE_QUERY_LOCAL_EVENT is set, the cache event was generated by the local computer. Otherwise, it was sent by a downstream proxy server.

WMS_CACHE_QUERY_REVERSE_PROXY

A downstream server is configured to be a reverse proxy server. If a cache proxy plug-in supports reverse proxy, it can use this flag to determine whether it must map client requests to an upstream server farm.

WMS_CACHE_QUERY_LOCAL_EVENT

The local server is generating an event to send upstream.

[in] IWMSCacheProxyCallbackIWMSCacheProxyCallback Object (C#) containing the callback function. The cache plug-in calls IWMSCacheProxyCallback.OnQueryCacheMissPolicy to respond to a call to QueryCache.

[in] object containing a value defined by the server to identify which call to QueryCacheMissPolicy the plug-in is responding to when it calls IWMSCacheProxyCallback.OnQueryCacheMissPolicy. You must pass this value back unaltered.

Return Value

This method does not return a value. To report an error, the plug-in can throw a COMException object to the server. If the plug-in uses the IWMSEventLogIWMSEventLog Object (C#) to log error information, it is recommended that it throw NS_E_PLUGIN_ERROR_REPORTED (0xC00D157D). Typically, the server attempts to make plug-in error information available to the server object model, the Windows Event Viewer, and the troubleshooting list in the details pane of the Windows Media Services MMC. However, if the plug-in uses the IWMSEventLog object to send custom error information to the Windows Event Viewer, throwing NS_E_PLUGIN_ERROR_REPORTED stops the server from also logging to the event viewer. For more information about plug-in error information, see Identifying Plug-in Errors.

Remarks

A proxy server must call QueryCache on the cache plug-in and receive a cache miss before it calls QueryCacheMissPolicy. A custom cache plug-in can use the WMS_CACHE_QUERY_TYPE_FLAGS enumeration type in the lQueryType parameter to direct implementation of a cache-miss policy.

Example

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

void IWMSCacheProxy.QueryCacheMissPolicy ( string bstrOriginUrl,
                                   IWMSContext pUserContext,
                                   IWMSCommandContext pCommandContext,
                                   IWMSContext pPresentationContext,
                                   object pCachePluginContext,
                                   int lQueryType,
                                   IWMSCacheProxyCallback pCallback,
                                   object varContext )
{
  try
  {
    int nOpenFlag = (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_OPEN;
    int nGCI = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_GET_CONTENT_INFO);
    int nReverseProxy = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_REVERSE_PROXY);

    // The ContentInfo class is user-defined and includes 
    // information about a cached item. 
    ContentInfo ci = new ContentInfo(bstrOriginUrl,null);

    // An open request was issued.
    if((nOpenFlag & lQueryType)!=0)
    {
      // Retrieve content information for normal mode.
      if(nReverseProxy==0)
      {
        ci.CacheProxyCallback = pCallback;
        ci.varContext = varContext;
        CacheProxyServer.GetContentInformation(bstrOriginUrl,
                                             pPresentationContext,
                                             null,
                                             null,
                                             this,
                                             ci);
      }
      // Reverse proxy mode:
      // Map the requested URL to the reverse proxy URL.
      // The call to the user-defined GetContentInfo() searches
      // a user-defined reverse proxy ContentInfo object for a 
      // "ReverseProxy" string. 
      else
      {
        ContentInfo ciRP = null;
        GetContentInfo(bstrOriginUrl,out ciRP);
        WMS_CACHE_QUERY_MISS_RESPONSE Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;

        // Play the content as a broadcast stream.
        if((ciRP.ContentType & 1 )!=0)
        {
          Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_BROADCAST;
        }
        // Play the content on demand.
        else
        {
          Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND;
        }

        // Create a content information context.
        IWMSContext ContentInfoContext = null;
        GetContentInfoContext(ci,out ContentInfoContext);

        // Call OnQueryCacheMissPolicy().
        pCallback.OnQueryCacheMissPolicy(0,
                                       Response,
                                       ciRP.CacheUrl,
                                       null,
                                       ContentInfoContext,
                                       varContext);

      }
    }

    // A get content information (GCI) request was issued. 
    if((nGCI & lQueryType)!=0)
    {
      // Forward the request upstream.
      WMS_CACHE_QUERY_MISS_RESPONSE Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_FORWARD_REQUEST;
      IWMSContext ContentInfoContext = null;
      GetContentInfoContext(ci,out ContentInfoContext);
      pCallback.OnQueryCacheMissPolicy(0,
                                     Response,
                                     bstrOriginUrl,
                                     null,
                                     ContentInfoContext,
                                     varContext);
    }

    // A downstream cache proxy server propagated a remote
    // cache proxy event. Forward the event to an upstream server.
    if((lQueryType & (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT)!=0)
    {
      pCallback.OnQueryCacheMissPolicy(0,
                                     WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_FORWARD_REQUEST,
                                     null,
                                     this,
                                     null,
                                     varContext);
    }
  }

  catch(Exception e)
  {
    throw new COMException();
  }

  return;
}

Requirements

Reference: Add a reference to Microsoft.WindowsMediaServices.

Namespace: Microsoft.WindowsMediaServices.Interop.

Assembly: Microsoft.WindowsMediaServices.dll.

Library: WMSServerTypeLib.dll.

Platform: Windows Server 2003, Enterprise Edition; Windows Server 2003, Datacenter Edition; Windows Server 2008.

See Also

Concepts

IWMSCacheProxy Object (C#)