Esempio n. 1
0
 internal void CloseConnection(CometClient cometClient)
 {
     Console.WriteLine("Closing comet connection {0}", cometClient);
     lock (_lock)
     {
         _clients.Remove(cometClient.CometId);
         string path = cometClient.Path;
         List<CometClient> clients = _pathIndex[path];
         clients.Remove(cometClient);
         if (clients.Count == 0)
         {
             _pathIndex.Remove(path);
         }
         if (cometClient.User != null)
         {
             string name = cometClient.User.Identity.Name;
             clients = _usernameIndex[name];
             clients.Remove(cometClient);
             if (clients.Count == 0)
             {
                 _usernameIndex.Remove(name);
             }
         }
     }
 }
Esempio n. 2
0
 internal CometClient AcceptClient(CometRequestHandler requestHandler)
 {
     Console.WriteLine("AcceptClient");
     CometClient cometClient;
     lock (_lock)
     {
         Console.WriteLine("Got lock");
         if (_clients.ContainsKey(requestHandler.CometId))
         {
             Console.WriteLine("Client already exists");
             throw new Exception("Client already exists!");
         }
         else
         {
             /*
              if (!_requestPaths.Contains(requestHandler.Path))
              {
              Console.WriteLine("Invalid request path: \"{0}\"", requestHandler.Path);
              throw new Exception("Invalid request path");
              }
              */
             cometClient = new CometClient(requestHandler);
             _clients.Add(requestHandler.CometId, cometClient);
             Console.WriteLine("Client created!");
         }
     }
     List<CometClient> clients;
     lock (_lock)
     {
         Console.WriteLine("Adding client to path index");
         if (!_pathIndex.TryGetValue(requestHandler.Path, out clients))
         {
             clients = new List<CometClient>();
             _pathIndex.Add(requestHandler.Path, clients);
         }
         clients.Add(cometClient);
         if (requestHandler.User != null)
         {
             Console.WriteLine("Adding client to username index: {0}", requestHandler.User.Identity.Name);
             if (!_usernameIndex.TryGetValue(requestHandler.User.Identity.Name, out clients))
             {
                 clients = new List<CometClient>();
                 _usernameIndex.Add(requestHandler.User.Identity.Name, clients);
             }
             clients.Add(cometClient);
         }
     }
     //requestHandler.WriteConnectionEstablished();
     //Console.WriteLine("Connection established for comet id: {0}", cometClient.CometId);
     return cometClient;
 }