Ejemplo n.º 1
0
 private void SendHistory(PipeConnection connection)
 {
     foreach (var message in messageStorage.GetMessages())
     {
         connection.SendMessage(message.ToString());
     }
     ;
 }
Ejemplo n.º 2
0
        private void RedirectClient()
        {
            string         newConnectionName = GenerateConnectionName();
            PipeConnection newConnection     = new PipeConnection(newConnectionName);

            connections.Add(newConnection);
            StartConnectionForClient(newConnection);
            // Send to client it's new connection name
            mainConnection.SendMessage(newConnectionName);
        }
Ejemplo n.º 3
0
 private void StartConnectionForClient(PipeConnection pipeConnection)
 {
     ThreadPool.QueueUserWorkItem(state =>
     {
         pipeConnection.StartConnection();
         SendHistory(pipeConnection);
         while (true)
         {
             string input    = pipeConnection.WaitMessage();
             Message message = new Message
             {
                 Text       = input,
                 ClientName = pipeConnection.GetClientName(),
                 Date       = DateTime.Now
             };
             this.messageStorage.Add(message);
             Console.WriteLine(message.ToString());
             BroadcastMessage(message.ToString());
         }
     });
 }
Ejemplo n.º 4
0
 public Server()
 {
     connections    = new ConcurrentBag <PipeConnection>();
     mainConnection = new PipeConnection(mainPipeName);
     messageStorage = new MessageStorage(10);
 }