Ejemplo n.º 1
0
 private void M_server_OnMessageRecived(object sender, string e)
 {
     try
     {
         CommandRecievedEventArgs crea = CommandRecievedEventArgs.FromJson(e);
         bool result;
         if (crea.CommandID == (int)CommandEnum.CloseCommand)
         {
             m_server.SendCommand(new
                                  CommandRecievedEventArgs((int)CommandEnum.CloseCommand, null, crea.Args[0]));
             GUIServer.Instance.Write("Close " + crea.Args[0]);
             return;
         }
         string         res           = this.m_controller.ExecuteCommand(crea.CommandID, crea.Args, out result);
         IClientHandler clientHandler = (IClientHandler)sender;
         clientHandler.Write(this, res);
     }
     catch
     {
         Debug.Write("we are on GUIServer InM_server_OnMessageRecived and it isnt good!");
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// the method execute the commands that the client send
 /// </summary>
 /// <param name="sender">the object that sent the data</param>
 /// <param name="data">the data that received</param>
 public void ExecuteTcpServer(Object sender, DataReceivedEventArgs data)
 {
     try
     {
         bool res;
         CommandRecievedEventArgs command   = CommandRecievedEventArgs.FromJson(data.Message);
         DataReceivedEventArgs    eventArgs = new DataReceivedEventArgs();
         eventArgs.Message = m_controller.ExecuteCommand(command.CommandID, command.Args, out res);
         if (command.CommandID == (int)CommandEnum.CloseCommand)
         {
             this.closeHandler(command.Args[0]);
             this.m_tcpServer.NotifyAll(command.Args[0]);
         }
         else
         {
             IClientHandler client = (IClientHandler)sender;
             client.Write(this, eventArgs);
         }
     } catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.ToString());
     }
 }