IWMSCacheProxyCallback.OnQueryCacheMissPolicy (C#)

banner art

Previous Next

IWMSCacheProxyCallback.OnQueryCacheMissPolicy (C#)

The OnQueryCacheMissPolicy method is called by the cache plug-in to respond when the server calls IWMSCacheProxy.QueryCacheMissPolicy.

Syntax

  

Parameters

lHr

[in] int indicating whether the call to IWMSCacheProxy.QueryCacheMissPolicy was successful.

CacheMissPolicy

[in] Member of the WMS_CACHE_QUERY_MISS_RESPONSE enumeration type identifying the cache-miss policy of the plug-in. This must be one of the following values.

Value Description
WMS_CACHE_QUERY_MISS_SKIP The cache proxy plug-in indicates that it will not process the request. The server queries the next plug-in.
WMS_CACHE_QUERY_MISS_DISCONNECT The cache proxy plug-in indicates that it will not process the request and that no other plug-in can process it. This forces the server to disconnect the client.
WMS_CACHE_QUERY_MISS_REDIRECT The cache proxy plug-in indicates that the server must redirect the client to an alternate URL specified by the plug-in. The server does not query the remaining plug-ins.
WMS_CACHE_QUERY_MISS_REDIRECT_TO_PROXY The cache proxy plug-in indicates that the server must redirect the client to an alternate cache proxy server specified by the plug-in. The client requests the same URL, but through a different proxy.
WMS_CACHE_QUERY_MISS_PLAY_BROADCAST The cache proxy plug-in directs that the stream be proxied to the client that requested it and shared to other clients that request it.
WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND The cache proxy plug-in directs that the stream be proxied only to the client that requested it. This can also be used to indicate that a broadcast stream must be sent to a single client.
WMS_CACHE_QUERY_MISS_FORWARD_REQUEST The cache proxy plug-in directs that the stream be forwarded to an upstream origin server specified by the requested URL. This response is only valid if the server has called QueryCache and specified either WMS_CACHE_QUERY_GET_CONTENT_INFO or WMS_CACHE_QUERY_CACHE_EVENT.
WMS_CACHE_QUERY_MISS_PROCESS_REQUEST The cache proxy plug-in indicates that it will process the client request. If the server has called QueryCache and specified WMS_CACHE_QUERY_GET_CONTENT_INFO, the plug-in supplies the content information BLOB. If the server has specified WMS_CACHE_QUERY_CACHE_EVENT, the plug-in enables the server to receive the event notice as if it is the origin server. The server can log and process the event.

bstrUrl

[in] string containing the URL.

pProxyContext

[in] IWMSProxyContext object that enables the server to retrieve client credentials and the name and port number of the proxy server that handles the client request.

pContentInfo

[in] IWMSContext object containing content information.

varContext

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

Return Values

This method does not return a value.

If this method fails, it throws an exception.

Number Description
0x80070057 The VarContext parameter does not contain a valid reference.
0x80070057 The plug-in returned WMS_CACHE_QUERY_MISS_DISCONNECT, WMS_CACHE_QUERY_MISS_REDIRECT_TO_PROXY, or WMS_CACHE_QUERY_MISS_REDIRECT when the server called QueryCache and specified WMS_CACHE_QUERY_LOCAL_EVENT.
0x80070057 The plug-in returned WMS_CACHE_QUERY_MISS_PLAY_BROADCAST or WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND when the server called QueryCache and specified WMS_CACHE_QUERY_GET_CONTENT_INFO or WMS_CACHE_QUERY_LOCAL_EVENT.
0x80070057 The plug-in returned WMS_CACHE_QUERY_MISS_FORWARD_REQUEST when the server called QueryCache and specified WMS_CACHE_QUERY_OPEN.
0x80070057 The plug-in returned WMS_CACHE_QUERY_MISS_PROCESS_REQUEST when the server called QueryCache and specified WMS_CACHE_QUERY_OPEN.

Example Code

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

Previous Next