Exemple #1
0
        public void Do_Work()
        {
            client = new TerminalClient();

            CurrentState = eState.Offline;
            eCommands    = eCentralCommand.Idle;


            if (client.Open())
            {
                while (!_shouldStop)
                {
                    if (!_shouldStop && client.AcceptClient())
                    {
                        System.Diagnostics.Debug.WriteLine("Do_Work");


                        if (CurrentState != client.Response.ResponseState)
                        {
                            CurrentState = client.Response.ResponseState;
                            OnTerminalStateChange(new TerminalEventArgs(client.Response));
                        }

                        if (eCommands != client.Response.CentralCommand)
                        {
                            eCommands = client.Response.CentralCommand;
                            OnRecieveCommand(new TerminalEventArgs(client.Response));
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void RunCommand(TerminalEventArgs args)
        {
            label3.Text = args.Response.CentralCommand.ToString();

            eCentralCommand ReceiveCommand = args.Response.CentralCommand;

            if (ReceiveCommand == eCentralCommand.Shutdown)
            {
                // MessageBox.Show("System Will shutdown...");
                Process.Start("shutdown", "/s /t 0");
            }
            else if (ReceiveCommand == eCentralCommand.Restart)
            {
                // MessageBox.Show("System Will restart...");
                Process.Start("shutdown", "/r /t 0");
            }
        }
        public bool EvaluateResponse()
        {
            if (RecieveByteArray.Length == 0)
            {
                return(false);
            }
            else
            {
                byte[] state = new byte[4];
                Array.Copy(RecieveByteArray, state, 4);


                //byte[] response = new byte[4];


                if (state.SequenceEqual(Constants.TERMINALSTATUS))
                {
                    if (this.ResponseState == eState.InService)
                    {
                        ReponseByteArray = Constants.INSERVICE;
                    }
                    else if (this.ResponseState == eState.Maintenance)
                    {
                        ReponseByteArray = Constants.MAINTENANCE;
                    }
                    else if (this.ResponseState == eState.Offline)
                    {
                        ReponseByteArray = Constants.OFFLINE;
                    }
                    else if (this.ResponseState == eState.Online)
                    {
                        ReponseByteArray = Constants.ONLINE;
                    }
                    else if (this.ResponseState == eState.OutofService)
                    {
                        ReponseByteArray = Constants.OUTOFSERVICE;
                    }
                }

                else if (state.SequenceEqual(Constants.TERMINALCOMMAND))
                {
                    if (!this.IsHasCurrentTransaction)
                    {
                        byte[] command = new byte[5];
                        Array.Copy(RecieveByteArray, command, 5);
                        if (command.SequenceEqual(Constants.CSHUTDOWN))
                        {
                            this.CentralCommand = eCentralCommand.Shutdown;
                        }
                        else if (command.SequenceEqual(Constants.CRESTART))
                        {
                            this.CentralCommand = eCentralCommand.Restart;
                        }
                        else if (command.SequenceEqual(Constants.COUTOFSERVICE))
                        {
                            this.CentralCommand = eCentralCommand.OutofServiceMode;
                            this.ResponseState  = eState.OutofService;
                        }
                        else if (command.SequenceEqual(Constants.CMAINTENANCE))
                        {
                            this.CentralCommand = eCentralCommand.MaintenanceMode;
                            this.ResponseState  = eState.Maintenance;
                        }
                        else if (command.SequenceEqual(Constants.CINSERVICE))
                        {
                            this.CentralCommand = eCentralCommand.InService;
                            this.ResponseState  = eState.InService;
                        }
                        ReponseByteArray = Constants.CRECEIVE;
                    }
                    else
                    {
                        ReponseByteArray = Constants.CIGNORE;
                    }
                }
                return(true);
            }
        }