void IWMSCacheProxy.RemoveCacheItem( string stringOriginUrl, IWMSCacheProxyCallback pCallback, object varContext ) { Debug.WriteLine("IWMSCacheProxy.RemoveCacheItem entered"); RemoveEntryFromDatabase(stringOriginUrl,true); pCallback.OnRemoveCacheItem(0,varContext); return; }
void IWMSCacheProxy.RemoveAllCacheItems( IWMSCacheProxyCallback pCallback, object varContext ) { Debug.WriteLine("IWMSCacheProxy.RemoveAllCacheItems entered"); DataTable dt = DS.Tables["CachedItems"]; DataRow[] drows = dt.Select(); foreach(DataRow row in drows) { string File = Convert.ToString(row["OriginUrl"]); RemoveEntryFromDatabase(File,true); } pCallback.OnRemoveAllCacheItems(0,varContext); return; }
void IWMSCacheProxy.QueryCacheMissPolicy( string bstrOriginUrl , IWMSContext pUserContext , IWMSCommandContext pCommandContext , IWMSContext pPresentationContext , object pCachePluginContext , int lQueryType , IWMSCacheProxyCallback pCallback , object varContext ) { Debug.WriteLine("IWMSCacheProxy.QueryCacheMissPolicy entered"); 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); ContentInfo ci = new ContentInfo(bstrOriginUrl,null); if((nOpenFlag & lQueryType)!=0) // open query { if(nReverseProxy==0) //normal mode { // get content information ci.CacheProxyCallback = pCallback; ci.varContext = varContext; CacheProxyServer.GetContentInformation(bstrOriginUrl,pPresentationContext,null, null,this,ci); } else // it's a reverse proxy mode { // we simply look up our table to see if there is a mapping between the requested //Url and the RP url and return it // we distinguish the table entry if it's a reverse proxy or not by // checking the CDL data // we store a special string "ReverseProxy" there for the distinction // one can simply add another entry in the table to be safer // as there might be some CDL data written as "ReverseProxy" !! 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; if((ciRP.ContentType & 1 )!=0) // it's a brodcast content { Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_BROADCAST; } else { Response = WMS_CACHE_QUERY_MISS_RESPONSE.WMS_CACHE_QUERY_MISS_PLAY_ON_DEMAND; } IWMSContext ContentInfoContext = null; GetContentInfoContext(ci,out ContentInfoContext); pCallback.OnQueryCacheMissPolicy(0,Response,ciRP.CacheUrl,null,ContentInfoContext,varContext); } } if((nGCI & lQueryType)!=0) // GCI query from downstream server { 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); } 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); } return; }
// // IWMSCacheProxy // void IWMSCacheProxy.QueryCache(string bstrOriginUrl , IWMSContext pUserContext , IWMSCommandContext pCommandContext , IWMSContext pPresentationContext , int lQueryType , IWMSCacheProxyCallback pCallback , object varContext ) { Debug.WriteLine("IWMSCacheProxy.QueryCache entered"); // we simply return a hard coded URL for the request WMS_CACHE_QUERY_OPEN for now 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 open or GCI is called // for GCI we don't care about CompareContentInformation // if not upto date, we treat as a miss if((nOpen!=0)||(nGCI!=0)) { // allocate ContentInfoContext and DataContainerObject // stuff it with the information // and call back IWMSContext Context; WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS; ContentInfo ci; //gets allocated here GetContentInfo(bstrOriginUrl,out ci); ci.CacheProxyCallback = pCallback; ci.varContext = varContext; GetContentInfoContext(ci,out Context); bool bQueryCache = true; bool bOnDemand = true; if((ci.CacheUrl!=null) && (nReverseProxy==0)) // there is something in the cache { // if content is not expired, this is a hit DateTime now = DateTime.Now; Debug.WriteLine(string.Format("Current local time={0}",now)); //covert to UTC time now = now.ToUniversalTime(); Debug.WriteLine(string.Format("Current UTC time={0}",now)); Debug.WriteLine(string.Format("Expiration time={0}",ci.ExpirationTime)); if(ci.ExpirationTime > now) { if((ci.ContentType & 1 )!=0) // it's a brodcast content { Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_BROADCAST; bOnDemand = false; } else { Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_HIT_PLAY_ON_DEMAND; bOnDemand = true; } } else // content appears expired, we will have to call CompareContentInformation { if(nOpen!=0) // only for open queries { bQueryCache = false; } } } if(bQueryCache) { string CacheUrl = ci.CacheUrl; if(bOnDemand) { CacheUrl = string.Format("file://{0}",ci.CacheUrl); } pCallback.OnQueryCache( 0, Response, CacheUrl, Context, null, varContext); } else { CacheProxyServer.CompareContentInformation(bstrOriginUrl,Context,pPresentationContext, this,null,this,(object)ci); } } else { // see of this 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) { // we declare it as a miss // and on QCP, we ask the cachemanager to forward it WMS_CACHE_QUERY_RESPONSE Response = WMS_CACHE_QUERY_RESPONSE.WMS_CACHE_QUERY_MISS; pCallback.OnQueryCache( 0, Response, bstrOriginUrl, null, null, varContext); } } return; }
void IWMSCacheProxy.AddCacheItem( string bstrOriginUrl , string bstrPrestuffUrl , int lExpiration , int lBandwidth , int lRemoteEventFlags , IWMSCacheProxyCallback pCallback , object varContext ) { Debug.WriteLine("IWMSCacheProxy.AddCacheItem entered"); //first remove the entry from database ContentInfo ci = new ContentInfo(bstrOriginUrl,bstrPrestuffUrl); ci.lExpiration = lExpiration; 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); CacheProxyServer.GetContentInformation(bstrOriginUrl,pPresentationContext,null, null,this,ci); return; }
public ContentInfo(string o, string c) { Debug.WriteLine("ContentInfo::ContentInfo entered"); OriginUrl = o; CacheUrl = c; CacheFlags=0; ContentSize = 0; SubscriptionFlag=0; ContentType=0; EntityTags = new ArrayList(); LastModified = System.DateTime.Now; ExpirationTime = System.DateTime.Now; CacheProxyCallback = null; varContext = null; lExpiration = 0; CDL = new ArrayList(); }