Пример #1
0
 internal void Renew(Client client, int clientLeaseTime)
 {
     if (client.ClientLeaseTime == clientLeaseTime)
     {
         //Keep the client in the cache.
         HttpRuntime.Cache.Get(client.Id);
         return;
     }
     lock (this.SyncRoot)
     {
         if (client.ClientLeaseTime < clientLeaseTime)
         {
             log.Debug(__Res.GetString(__Res.Client_Lease, client.Id, client.ClientLeaseTime, clientLeaseTime));
             client.SetClientLeaseTime(clientLeaseTime);
         }
         if (clientLeaseTime == 0)
         {
             log.Debug(__Res.GetString(__Res.Client_Lease, client.Id, client.ClientLeaseTime, clientLeaseTime));
             client.SetClientLeaseTime(0);
         }
         if (client.ClientLeaseTime != 0)
         {
             HttpRuntime.Cache.Remove(client.Id);
             // Add the FlexClient to the Cache with the expiration item
             HttpRuntime.Cache.Insert(client.Id, client, null,
                 Cache.NoAbsoluteExpiration,
                 new TimeSpan(0, client.ClientLeaseTime, 0),
                 CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(this.RemovedCallback));
         }
         else
             HttpRuntime.Cache.Remove(client.Id);
     }
 }
Пример #2
0
 /// <summary>
 /// Returns an existing client from a client id or creates a new one if not found.
 /// </summary>
 /// <param name="id">The identity of the client to return.</param>
 /// <returns>The client object.</returns>
 public IClient GetClient(string id)
 {
     lock (this.SyncRoot)
     {
         if (_clients.ContainsKey(id))
         {
             HttpRuntime.Cache.Get(id);
             return _clients[id] as Client;
         }
         if (id == null || id == "nil" || id == string.Empty)
             id = Guid.NewGuid().ToString("D");
         Client client = new Client(this, id);
         _clients[id] = client;
         int clientLeaseTime = 1;
         log.Debug(__Res.GetString(__Res.Client_Create, id));
         Renew(client, clientLeaseTime);
         //client.NotifyCreated();
         return client;
     }
 }