Share via


IWMSCacheProxyCallback.OnQueryCache (C#)

banner art

Previous Next

IWMSCacheProxyCallback.OnQueryCache (C#)

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

Syntax

  

Parameters

lHr

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

Response

[in] Member of the WMS_CACHE_QUERY_RESPONSE enumeration type indicating the response of the cache plug-in. This must be one of the following values.

Value Description
WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND The requested content is in the cache and is current. Therefore, it may be streamed from the cache or proxied from an upstream server. Each client request requires a separate connection.
WMS_CACHE_QUERY_HIT_PLAY_BROADCAST The requested content is in the cache and is current. Therefore, it may be streamed from the cache or proxied from an upstream server. A single stream can be split to multiple downstream clients.
WMS_CACHE_QUERY_HIT_PROCESS_REQUEST The requested content is in the cache. The server must process the request and send information about the result to the downstream client. 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 The requested content is not in the cache or is not current.

bstrCacheUrl

[in] string containing the cache URL.

pContentInfo

[in] IWMSContext object containing a content description context.

pCachePluginContext

[in] object containing information defined by the cache plug-in. The server does not use this information. It passes the pointer back to the plug-in when it calls IWMSCacheProxy.QueryCacheMissPolicy.

varContext

[in] object containing a value defined by the server to identify which call to IWMSCacheProxy.QueryCache the plug-in is responding to when it calls OnQueryCache. 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 content information context identified by the pContentInfo parameter does not exist, and the plug-in returned WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND in the Response parameter.
0x80070057 The VarContext parameter does not contain a valid reference.
0x80070057 The plug-in returned WMS_CACHE_QUERY_HIT_PROCESS_REQUEST in the Response parameter when the server called QueryCache and specified WMS_CACHE_QUERY_GET_CONTENT_INFO or WMS_CACHE_QUERY_CACHE_EVENT.

Example Code

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

void IWMSCacheProxy.QueryCache(string bstrOriginUrl , 
            IWMSContext pUserContext , 
            IWMSCommandContext pCommandContext , 
            IWMSContext pPresentationContext , 
            int lQueryType , 
            IWMSCacheProxyCallback pCallback , 
            object varContext )
{
  try
  {
    int nFlag = (int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_OPEN;
    int nOpen = lQueryType & nFlag;
    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);
            
    // Either a get content information (GCI) or an open call is made.
    if((nOpen!=0)||(nGCI!=0)) 
    {
      // Allocate a content information context.
      IWMSContext Context;
      WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;

      // The ContentInfo object is user-defined.
      ContentInfo ci;
      GetContentInfo(bstrOriginUrl,out ci);
      ci.CacheProxyCallback = pCallback;
      ci.varContext = varContext;

      // Retrieve the new content information context.
      GetContentInfoContext(ci,out Context);

      bool bQueryCache = true;
      bool bOnDemand = true;

      // This is not a reverse proxy, and content has been cached.
      if((ci.CacheUrl!=null) && (nReverseProxy==0))
      {
        // Convert the current time to UTC time.
        DateTime now = DateTime.Now;
        now = now.ToUniversalTime();

        // If the content has not expired, declare a cache hit.
        if(ci.ExpirationTime > now)
        {
          // The content is a broadcast. Declare a cache
          // hit and set the cache policy to play the broadcast.
          if((ci.ContentType & 1 )!=0)
          {
            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_BROADCAST;
            bOnDemand = false;
          }
          // The content is on-demand content. Declare a cache
          // hit and set the cache policy to play the content on demand.
          else
          {
            Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND;
            bOnDemand = true;
          }
        }

        // The content has expired. 
        else
        {
          if(nOpen!=0)
          {
            bQueryCache = false;
          }
        }
      }

      // The content has not expired. Call OnQueryCache() and send the
      // Response parameter back to the server and the content
      // information context back to the server. 
      if(bQueryCache)
      {
        // Retrieve the cache URL from the user-defined content
        // information object.
        string CacheUrl = ci.CacheUrl;
        if(bOnDemand)
        {
          CacheUrl = string.Format("file://{0}",ci.CacheUrl);
        }
        pCallback.OnQueryCache( 0,
                            Response,
                            CacheUrl,
                            Context,
                            null,
                            varContext);
      }

      // The content has expired. Call CompareContentInformation() (for
      // open requests only).
      else
      {
        CacheProxyServer.CompareContentInformation(bstrOriginUrl,
                                                 Context,
                                                 pPresentationContext,
                                                 this,
                                                 null,
                                                 this,
                                                 (object)ci);
      }

    }

    // The request is not a GCI or open call. Determine what the
    // request is. 
    else
    {
      // Determine whether the call is for event propagation.
      int nCacheEvent = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_CACHE_EVENT);
      int nLocalEvent = lQueryType & ((int)WMS_CACHE_QUERY_TYPE_FLAGS.WMS_CACHE_QUERY_LOCAL_EVENT);
      if((nCacheEvent | nLocalEvent)!=0)
      {
        // Declare a cache miss and ask the server to
        // forward the request.
        WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS;
        pCallback.OnQueryCache( 0,
                              Response,
                              bstrOriginUrl,
                              null,
                              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