//Recieve Data from client public override void CycleRequest() { if (stack.CurrentDirect == FlowDirect.WaitingInput) { string strRec = null; strRec = (client as GW28Client).RecieveData(); BaseDCTAction action = null; if (strRec != null) { if (strRec.IndexOf("ALL RIGHTS") < 0 && strRec != String.Empty) { try { if (IsInputedLoginCmd == false && strRec == "10") { return; } string receivedData = strRec; if (receivedData == EXIT) { IsInputedLoginCmd = false; } else if (receivedData == LOGIN && IsInputedLoginCmd == true) // 输入LOGIN,要先退出 { receivedData = EXIT; IsInputedLoginCmd = false; } if (receivedData == EXIT || IsInputedLoginCmd == false) { stack = new BaseActionStack(); //stack.CurrentDirect = FlowDirect.WaitingOutPut; } DealSuperCommand(receivedData); if (!client.Authorized) { Login(); } bool bIsLoginCmd = false; if (IsInputedLoginCmd == false && !client.Authorized) // 如果还没有输入登录命令,而且客户端没有登录 { bIsLoginCmd = true; IsInputedLoginCmd = true; } if (client.Authorized || bIsLoginCmd == false) // 如果是登录命令,则不用再次执行Action,以免将命令当做用户名 { // 获取现在的Action action = stack.GetNextAction(); /* joe 20070903 GW28 输入和输出在一个界面,不需要输出原始输入 * // 输出原始输入 * UserControl.Messages inputMsg = new UserControl.Messages(); * string strInput = receivedData; * if (action is Action.ActionPassword) * { * strInput = new string('*', receivedData.Length); * } * inputMsg.Add(new UserControl.Message(strInput)); * stack.SendMessage(client, inputMsg); */ // 执行Action if (stack.CancelActionOutput == false) { stack.SendMessage(client, action.Do(client), ""); } else { action.Do(client); stack.CancelActionOutput = false; } //stack.CurrentDirect = action.FlowDirect; } /* * SuperCommand(strRec); * * action = stack.GetNextAction(); * stack.SendMessage(client,action.Do(client)); * stack.CurrentDirect = action.FlowDirect; */ } catch (Exception ex) { UserControl.FileLog.FileLogOut("DCTControlPanel.log", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ex.StackTrace); UserControl.Messages msg = new UserControl.Messages(); msg.Add(new UserControl.Message(ex)); stack.SendMessage(client, msg, ""); if (action != null) { //stack.CurrentDirect = action.FlowDirect; } } } } } }
public void RequestInputFromRoot(string receivedData) { BaseDCTAction action = null; if (receivedData != null) { ((DSC19Client)client).RecieveDataFromRoot(receivedData); if (receivedData.IndexOf("ALL RIGHTS") < 0 && receivedData != String.Empty) { client.RecievedData = receivedData; try { if (receivedData.IndexOf("DCS-19 SELF-RESET OK") >= 0) // 终端启动 { receivedData = "LOGIN"; UserControl.Messages loginMsg = new UserControl.Messages(); loginMsg.Add(new UserControl.Message("$DCT_LOGIN")); stack.SendMessage(client, loginMsg, ""); /* * if (timer == null) * { * timer = new System.Threading.Timer(new System.Threading.TimerCallback(this.ResponseTimerCallback), this, 0, System.Threading.Timeout.Infinite); * } */ if (threadResponse == null) { System.Threading.ThreadStart threadStart = new System.Threading.ThreadStart(this.ResponseTimerCallback); threadResponse = new System.Threading.Thread(threadStart); threadResponse.Start(); } return; } bInRequestExecute = true; if (receivedData == EXIT) { IsInputedLoginCmd = false; } else if (receivedData == LOGIN && IsInputedLoginCmd == true) // 输入LOGIN,要先退出 { receivedData = EXIT; IsInputedLoginCmd = false; } if (receivedData == EXIT) { this.RaiseAfterLogout(); /* * if (timer != null) * { * timer = null; * System.Threading.Thread.Sleep(20); * System.Windows.Forms.Application.DoEvents(); * } */ if (threadResponse != null) { threadResponse.Abort(); System.Threading.Thread.Sleep(20); System.Windows.Forms.Application.DoEvents(); threadResponse = null; } stack = new BaseActionStack(); } DealSuperCommand(receivedData); if (!client.Authorized) { Login(); } bool bIsLoginCmd = false; if (IsInputedLoginCmd == false && !client.Authorized) // 如果还没有输入登录命令,而且客户端没有登录 { bIsLoginCmd = true; IsInputedLoginCmd = true; } if (client.Authorized || bIsLoginCmd == false) // 如果是登录命令,则不用再次执行Action,以免将命令当做用户名 { // 获取现在的Action action = stack.GetNextAction(); // 输出原始输入 UserControl.Messages inputMsg = new UserControl.Messages(); string strInput = receivedData; if (action is Action.ActionPassword) { strInput = new string('*', receivedData.Length); } inputMsg.Add(new UserControl.Message(strInput)); stack.SendMessage(client, inputMsg, ""); // 执行Action if (stack.CancelActionOutput == false) { stack.SendMessage(client, action.Do(client), ""); } else { action.Do(client); stack.CancelActionOutput = false; } //stack.CurrentDirect = action.FlowDirect; } /* * if (timer == null) * { * timer = new System.Threading.Timer(new System.Threading.TimerCallback(this.ResponseTimerCallback), this, 0, System.Threading.Timeout.Infinite); * } */ if (threadResponse == null) { System.Threading.ThreadStart threadStart = new System.Threading.ThreadStart(this.ResponseTimerCallback); threadResponse = new System.Threading.Thread(threadStart); threadResponse.Start(); } } catch (Exception ex) { UserControl.Messages msg = new UserControl.Messages(); msg.Add(new UserControl.Message(ex)); stack.SendMessage(client, msg, ""); // Added by Icyer 2006/12/14 if (action != null && action.NeedCancel == true) { action.NeedCancel = false; //this.Cancel(); UserControl.Messages msgTmp = new UserControl.Messages(); msgTmp.Add(new UserControl.Message(UserControl.MessageType.Normal, "$DCT_Please_Input_SN_OR_Directive")); stack.SendMessage(client, msgTmp, ""); } // Added end if (action != null) { //stack.CurrentDirect = action.FlowDirect; } } bInRequestExecute = false; } } }