Share via


IWMSCacheProxy.AddCacheItem (C#)

banner art

Previous Next

IWMSCacheProxy.AddCacheItem (C#)

The AddCacheItem method is called by the server to prestuff a cache.

Syntax

  

Parameters

bstrOriginUrl

[in] string containing the URL on the origin server of the content to be cached.

bstrPrestuffUrl

[in] string containing the URL identifying the location for the cache. If NULL, the method uses bstrOriginUrl.

lExpiration

[in] int containing the amount of time, in seconds, that the cache item is available to be streamed after it has been cached. For example, a value of 86,400 indicates that cached content can be streamed for 24 hours after it is downloaded from the origin server.

lBandwidth

[in] int containing the maximum bandwidth that the server can use when streaming content into cache storage.

lRemoteEventFlags

[in] int containing the remote events that must be passed back to the origin server. This must be one of the following values. For more information, see the WMS_EVENT_TYPE enumeration value.

Event Description
WMS_EVENT_REMOTE_CACHE_OPEN A remote cache proxy server has opened cached content or established a connection to an upstream server.
WMS_EVENT_REMOTE_CACHE_CLOSE A remote cache proxy server has closed a content file or disconnected a client from an upstream server.
WMS_EVENT_REMOTE_CACHE_LOG A client submitted a rendering log to indicate that it streamed content from a local cache, or a cache proxy server submitted a remote log to indicate that it either streamed content from cache or proxied it from an upstream server.

pCallback

[in] IWMSCacheProxyCallback object containing the callback function. This can be null if no callback is requested.

varContext

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

Return Values

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 IWMSEventLog object 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

This method can be called whenever an item must be added to a cache. It is always called by the server when the IWMSCacheProxyPlugin.PreStuff method is called. The plug-in calls IWMSCacheProxyCallback.OnAddCacheItem to respond to the AddCacheItem method.

Example Code

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

void IWMSCacheProxy.AddCacheItem( string bstrOriginUrl , 
                                  string bstrPrestuffUrl, 
                                  int lExpiration,
                                  int lBandwidth,
                                  int lRemoteEventFlags,
                                  IWMSCacheProxyCallback pCallback,
                                  object varContext )
{
  try
  {
    // The ContentInfo class is user-defined and contains
    // information about cached content.
    ContentInfo ci = new ContentInfo(bstrOriginUrl,bstrPrestuffUrl);
    ci.lExpiration = lExpiration;
    
    // Create a presentation context.
    IWMSContext pPresentationContext=null;
    Type t = typeof(IWMSContext);
    Guid guid = t.GUID;
    System.IntPtr punk;
    ClassObject.AllocIWMSContext(
                       ref guid,
                       WMS_CONTEXT_TYPE.WMS_PRESENTATION_CONTEXT_TYPE,
                       null,
                       out punk);
    pPresentationContext = (IWMSContext)Marshal.GetObjectForIUnknown(punk);

    // Retrieve content information. The CacheProxyServer
    // object is your plug-in's implementation of the 
    // IWMSCacheProxyServer interface.
    CacheProxyServer.GetContentInformation(bstrOriginUrl,
                                           pPresentationContext,
                                           null,
                                           null,
                                           this,
                                           ci);

    // The server calls OnGetContentInformation() in response
    // to the preceding call and sends the plug-in a cache
    // information context. The context contains a reference to
    // an IWMSDataContainerVersion object that the plug-in can use
    // to retrieve content information and place it in the
    // user-defined ContentInfo class. If the 
    // WMS_DATA_CONTAINER_VERSION_CACHE_FLAGS enumeration member
    // indicates that the content can be downloaded, the plug-in calls 
    // DownloadContent(). When the download is complete, the 
    // OnGetContentInformation() function can call OnAddCacheItem() to
    // signal that the appropriate event notices should be raised.

  }
  catch(Exception e)
  {
    throw new COMException("NO ERROR",1);
  }
}

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