/// <summary> /// Perform logoff/disconnect process. /// </summary> private void DoLogoff() { if (_AppClient.IsConnected) { Dictionary <string, ACloseMode> aCloseModes = AGlobals.GetSingleton().CloseModes; ACloseMode aCloseMode = aCloseModes[uCloseModeCombo.Text.ToLower()]; _AppClient.CloseConnection(_DefaultReceiver, 0, aCloseMode); } }
/// <summary> /// Helper function to determinte the error message from an error code. /// </summary> /// <param name="iErrCode">Error code.</param> /// <returns>Error message.</returns> public string GetErrorMessage(int iErrCode) { Dictionary <int, string> aErrMap = AGlobals.GetSingleton().ErrorMessages; if (!aErrMap.ContainsKey(iErrCode)) { iErrCode = 0; } return(aErrMap[iErrCode]); }
/// <summary> /// Helper function to determine the request type name from a request type value. /// </summary> /// <param name="iReqType">Request type code.</param> /// <returns>Request name.</returns> public string GetRequestName(int iReqType) { List <string> aReqList = AGlobals.GetSingleton().RequestNames; if (iReqType < 0 || iReqType >= aReqList.Count) { iReqType = 0; } return(aReqList[iReqType]); }
static void Main(string[] args) { globals = AGlobals.GetSingleton(); bool quit = false; string inputLine; string[] inputArgs; char[] delim = { ' ' }; string cmd; // AReturnReceiver defaultReceiver = new AReturnReceiver(); defaultReceiver.ReturnOutputEvent += new EventHandler <AAsyncEventArgs>(ResponseHandler); AAppClient appClient = new AAppClient("localhost", 8081, defaultReceiver, "Demo"); do { Console.Write("> "); inputLine = Console.ReadLine(); inputLine = inputLine.Trim(); inputArgs = inputLine.Split(delim); cmd = inputArgs[0].ToLower(); if (cmd == "quit" || cmd == "exit") { quit = true; } else if (cmd == "connect") { appClient.Host = inputArgs[1]; appClient.Port = ushort.Parse(inputArgs[2]); appClient.OpenConnection(defaultReceiver); } else if (cmd == "disconnect") { appClient.CloseConnection(defaultReceiver, 0, ACloseMode.Disconnect); } else if (cmd == "logon") { appClient.Logon(defaultReceiver, inputArgs[1], inputArgs[2]); } else if (cmd == "logoff") { appClient.Logoff(defaultReceiver); } else if (cmd == "getsessions") { appClient.GetSessions(defaultReceiver, inputArgs[1]); } else if (cmd == "opensession") { appClient.OpenSession(defaultReceiver, inputArgs[1]); } else if (cmd == "closesession") { // close mode // 0 - default // 1 - disconnect // 2 - soft // 3 - firm // 4 - hard appClient.CloseSession(defaultReceiver, int.Parse(inputArgs[1]), int.Parse(inputArgs[2])); } else if (cmd == "connectsession") { appClient.ConnectSession(defaultReceiver, int.Parse(inputArgs[1])); } else if (cmd == "eval_display") { appClient.Eval(defaultReceiver, "(display \"hello world\")", null, 0); } else if (cmd == "eval_add") { appClient.Eval(defaultReceiver, "(+ 1 2)", null, 0); } else if (cmd == "help" || cmd == "?") { Console.WriteLine("connect [host] [port]"); Console.WriteLine("logon [username] [password]"); Console.WriteLine("logoff"); Console.WriteLine("eval [command]"); Console.WriteLine("getsessions [context]"); Console.WriteLine("disconnect"); Console.WriteLine("status"); Console.WriteLine("quit"); } else { Console.WriteLine("Unknown command: " + cmd); } } while (!quit); }
// Handler for Async Events private void defaultResponseHandler(object iSrc, AAsyncEventArgs iArgs) { if (iArgs.Status == 0) { switch (iArgs.RequestType) { case ARequestType.OpenConnection: // Successfully connected, try logging on. if (cAppClient.IsConnected) { cAppClient.Logon(cReceiver, cUsername, cPassword); } break; case ARequestType.CloseConnection: cConnectForm.setConnected(false); cConnectForm.setConnected(false); cConnectForm.enableServerIPText(true); cConnectForm.enableServerPortText(true); cConnectForm.enableUserNameText(true); cConnectForm.enablePasswordText(true); Globals.ThisAddIn.cCLIForm.enableSubmitButton(false); Globals.ThisAddIn.cCLIForm.enableCommandText(false); cGsmDemoForm.displayStatusBar("Disonnected"); cGsmDemoForm.setStatusBarImg(global::AisExcel2003.Properties.Resources.disconnected); break; case ARequestType.Logon: if (iArgs.Status == 0) { cConnectForm.setConnected(true); cConnectForm.enableServerIPText(false); cConnectForm.enableServerPortText(false); cConnectForm.enableUserNameText(false); cConnectForm.enablePasswordText(false); Globals.ThisAddIn.cCLIForm.enableSubmitButton(true); Globals.ThisAddIn.cCLIForm.enableCommandText(true); cAppClient.OpenSession(cReceiver, "GSMDemo"); } else { //There was an error on logon displayText("Logon Error: " + iArgs.Error + Environment.NewLine); } break; case ARequestType.OpenSession: cSessionId = iArgs.ReturnValue; displayText("Logged on successful" + Environment.NewLine); cGsmDemoForm.displayStatusBar("Connected"); cGsmDemoForm.setStatusBarImg(global::AisExcel2003.Properties.Resources.connected); break; case ARequestType.Display: case ARequestType.Eval: if (iArgs.Out.StartsWith("***DisplayGenerateData***")) { displayGenerateDataResults(iArgs); } else if (iArgs.Out.StartsWith("***DisplayWorkSheet***")) { Excel.Workbook aWorkbook = Globals.ThisAddIn.Application.Workbooks.get_Item(1); Excel.Sheets aCurrentSheets = aWorkbook.Sheets as Excel.Sheets; Excel.Worksheet aWorkSheet; string aOutText = iArgs.Out.Replace("***DisplayWorkSheet***", ""); // Parse the results, delimited by "***Marker***" as sent in the Run Command // of Generate Data form. string[] aOutArray = aOutText.Split(new string[] { "***Marker***" }, StringSplitOptions.None); string aTestName = ""; if (aOutArray.Length > 0) { aTestName = aOutArray[0]; } if (aOutArray.Length > 1) { // Process the Test case's Results.txt file try { aWorkSheet = aCurrentSheets.get_Item("Results") as Excel.Worksheet; } catch (Exception) { // Worksheet does not exist, create a new one aWorkSheet = (Excel.Worksheet)aCurrentSheets.Add(aCurrentSheets[1], Type.Missing, Type.Missing, Type.Missing); aWorkSheet.Name = "Results"; } displayWorkSheet(aWorkSheet, aOutArray[1], 1, 1, "\n", "\t"); } if (aOutArray.Length > 2) { // Process the Test case's Estimates.txt file try { aWorkSheet = aCurrentSheets.get_Item("Estimates") as Excel.Worksheet; } catch (Exception) { // Worksheet does not exist, create a new one aWorkSheet = (Excel.Worksheet)aCurrentSheets.Add(aCurrentSheets[1], Type.Missing, Type.Missing, Type.Missing); aWorkSheet.Name = "Estimates"; } displayWorkSheet(aWorkSheet, aOutArray[2], 1, 1, "\n", "\t"); } if (aOutArray.Length > 3) { // Process the Test case's Statistics.txt file try { aWorkSheet = aCurrentSheets.get_Item("Statistics") as Excel.Worksheet; } catch (Exception) { // Worksheet does not exist, create a new one aWorkSheet = (Excel.Worksheet)aCurrentSheets.Add(aCurrentSheets[1], Type.Missing, Type.Missing, Type.Missing); aWorkSheet.Name = "Statistics"; } displayWorkSheet(aWorkSheet, aOutArray[3], 1, 1, "\n", "\t"); } if (iArgs.Display != "") { string aTextToDisplay = iArgs.Display.Replace("\n", Environment.NewLine); displayText(aTextToDisplay); } Globals.ThisAddIn.cWaitForm.setVisible(false); MessageBox.Show("GSM Test finished", "Information"); } else { string aTextToDisplay = iArgs.Display.Replace("\n", Environment.NewLine); displayText(aTextToDisplay); if (iArgs.Out != "") { displayText(iArgs.Out); } } break; case ARequestType.LogStatus: displayText("Log: " + iArgs.Out); break; default: displayText("Default: " + iArgs.Out); break; } } else { if (iArgs.Error.Length == 0) { if (AGlobals.GetSingleton().ErrorMessages.ContainsKey(iArgs.Status)) { iArgs.Error = AGlobals.GetSingleton().ErrorMessages[iArgs.Status]; } else { iArgs.Error = AGlobals.GetSingleton().ErrorMessages[(int)AErrorCodes.Generic]; } } switch (iArgs.RequestType) { case ARequestType.OpenConnection: displayText("Open Connection Error: " + iArgs.Error); break; case ARequestType.CloseConnection: displayText("Close Connection Error: " + iArgs.Error); cConnectForm.setConnected(false); cConnectForm.enableServerIPText(true); cConnectForm.enableServerPortText(true); cConnectForm.enableUserNameText(true); cConnectForm.enablePasswordText(true); Globals.ThisAddIn.cCLIForm.enableSubmitButton(false); Globals.ThisAddIn.cCLIForm.enableCommandText(false); cGsmDemoForm.displayStatusBar("Disonnected"); cGsmDemoForm.setStatusBarImg(global::AisExcel2003.Properties.Resources.disconnected); break; case ARequestType.Logon: displayText("Logon Error" + iArgs.Error); break; case ARequestType.OpenSession: displayText("Open Session Error" + iArgs.Error); break; default: break; } } }
/// <summary> /// Secondary response handler. /// </summary> /// <param name="iSrc"></param> /// <param name="iArgs"></param> private void SecondaryResponseHandler(object iSrc, AAsyncEventArgs iArgs) { if (iArgs.Status == 0) { StatusInfo("Ready"); switch (iArgs.RequestType) { case ARequestType.GetCurrentContexts: SetAvailableContexts(iArgs.Out); break; case ARequestType.GetSessions: SetActiveSessions(iArgs.Out); break; case ARequestType.GetExtentNames: SetActiveExtents(iArgs.Out); break; case ARequestType.GetExtentTypes: DoGetNextLevel(); break; case ARequestType.GetNextLevel: SetActiveNodes(null); break; case ARequestType.OpenSession: SetCurrentSession(iArgs.ReturnValue.ToString()); DoRefreshSessions(); DoSetLogLevel(); break; case ARequestType.SetLogLvl: _AppClient.SetExtentTypeOptions(".Memory", "#(1 1 1)"); break; case ARequestType.ConnectSession: SetCurrentSession(iArgs.ReturnValue.ToString()); DoRefreshSessions(); break; default: AppendToLog("Request Id: " + iArgs.RequestId); AppendToLog("Request Type: " + iArgs.RequestType.ToString()); AppendToLog("Status: " + iArgs.Status); AppendToLog("Return: " + iArgs.ReturnValue); AppendToLog("Error: " + iArgs.Error); AppendToLog("Display: " + iArgs.Display); AppendToLog("Out: " + iArgs.Out); AppendToLog("-----"); break; } } else { if (iArgs.Error.Length == 0) { if (AGlobals.GetSingleton().ErrorMessages.ContainsKey(iArgs.Status)) { iArgs.Error = AGlobals.GetSingleton().ErrorMessages[iArgs.Status]; } else { iArgs.Error = AGlobals.GetSingleton().ErrorMessages[(int)AErrorCodes.Generic]; } } StatusError(iArgs.Error); } }
/// <summary> /// Default response handler. /// </summary> /// <param name="iSrc"></param> /// <param name="iArgs"></param> private void DefaultResponseHandler(object iSrc, AAsyncEventArgs iArgs) { if (iArgs.Status == 0) { StatusInfo("Ready"); switch (iArgs.RequestType) { case ARequestType.OpenConnection: InitLogon(); break; case ARequestType.CloseConnection: SetConnectionState(false); if (_Reconnect == true) { InitConnection(); _Reconnect = false; } _LoggedOn = false; break; case ARequestType.Logon: SetConnectionState(true); _LoggedOn = true; break; case ARequestType.Display: case ARequestType.Eval: if (iArgs.Display.Length > 0) { AppendToConsole(iArgs.Display); } if (iArgs.Out.Length > 0) { AppendToConsole(iArgs.Out); } break; case ARequestType.LogStatus: if (iArgs.Out.StartsWith("_icon")) { bool iEnable = iArgs.Out.EndsWith("off"); SetEngineIdle(iEnable); } else { StatusInfo(iArgs.Out); } break; default: AppendToLog("Request Id: " + iArgs.RequestId); AppendToLog("Request Type: " + iArgs.RequestType.ToString()); AppendToLog("Status: " + iArgs.Status); AppendToLog("Return: " + iArgs.ReturnValue); AppendToLog("Error: " + iArgs.Error); AppendToLog("Display: " + iArgs.Display); AppendToLog("Out: " + iArgs.Out); AppendToLog("-----"); break; } } else { if (iArgs.Error.Length == 0) { if (AGlobals.GetSingleton().ErrorMessages.ContainsKey(iArgs.Status)) { iArgs.Error = AGlobals.GetSingleton().ErrorMessages[iArgs.Status]; } else { iArgs.Error = AGlobals.GetSingleton().ErrorMessages[(int)AErrorCodes.Generic]; } } StatusError(iArgs.Error); SetEnable(true); } if (iArgs.RequestType == ARequestType.Eval) { SetEnable(true); } }