/// <summary> /// Parses the input entered by the user over console /// Calls WcsCliCmProxy class for processing the input /// </summary> private static void ContinuousConsoleUserInputCapture() { String inputString = null; bool _tobreak = false; while (true) { Console.Write(WcsCliConstants.consoleString + " " + ""); inputString = Console.ReadLine(); if (inputString == null) { continue; } if (inputString.Equals("exit", StringComparison.InvariantCultureIgnoreCase) || inputString.Equals("quit", StringComparison.InvariantCultureIgnoreCase)) { inputString = "wcscli"; inputString += " "; inputString += "-" + WcsCliConstants.terminateCmConnection; _tobreak = true; } WcsCliCmProxy.InteractiveParseUserCommandGetCmResponse(false, inputString); if (_tobreak) { break; } } // While loop ends return; }
/// <summary> /// Main program where the console command-line user interface starts /// </summary> /// <param name="args"></param> static void Main(string[] args) { if (!Environment.UserInteractive) { // running as service using (var service = new WcscliSerialService()) ServiceBase.Run(service); } else { // Command-line specific code goes here Console.Title = "Chassis Manager Command-line Interface."; WcsCliCmProxy.InteractiveParseUserCommandGetCmResponse(false, ConvertConsoleCommandLineArgsToCommandInput(args)); if (isBatchOrVersionCmd) { // If batch file is specified as input then do not get in to interactive mode.. quit.. return; } if (!WcsCli2CmConnectionManager.TestConnectionToCmService()) { Console.WriteLine("Please try again by executing \"{0}\" \n", WcsCliConstants.wcscliConsoleParameterHelp); return; } ContinuousConsoleUserInputCapture(); } }
/// <summary> /// Parses the input entered by the user over serial /// Calls WcsCliCmProxy class for processing the input /// </summary> private static void ContinuousSerialUserInputCapture() { String inputString = null; while (_continue) { // Blocking call that will wait until the user enters a command delimited by carriage return or new line inputString = CliSerialPort.ReadUserInputStringFromSerial(new char[] { '\n', '\r' }); if (inputString != null) { if (inputString.Equals("exit", StringComparison.InvariantCultureIgnoreCase) || inputString.Equals("quit", StringComparison.InvariantCultureIgnoreCase)) { inputString = "wcscli "; inputString += "-" + WcsCliConstants.terminateCmConnection; } // Execute the command WcsCliCmProxy.InteractiveParseUserCommandGetCmResponse(true, inputString); } Console.Write(WcsCliConstants.consoleString + " " + ""); // Write response data from console out to serial CliSerialPort.WriteConsoleOutToSerial(); } // While loop ends }
/// <summary> /// Main program where the console command-line user interface starts /// </summary> /// <param name="args"></param> static void Main(string[] args) { bool runApplication = false; // Check if we run as application or a service if (args != null) { // List of valid command line parameters List <string> validParams = new List <string> { "-h", "-p", "-s", "-u", "-x", "-b", "-v" }; for (int i = 0; i < args.Length; i++) { // If the command line argument contains a valid parameter, run as application foreach (string validParam in validParams) { if ((args[i].Trim().Equals(@validParam, StringComparison.InvariantCultureIgnoreCase))) { runApplication = true; break; } } // Found a valid flag if (runApplication) { break; } } } if ((!runApplication) && (!Environment.UserInteractive)) { // running as service using (var service = new WcscliSerialService()) ServiceBase.Run(service); } else { // Command-line specific code goes here Console.Title = "Chassis Manager Command-line Interface."; WcsCliCmProxy.InteractiveParseUserCommandGetCmResponse(false, ConvertConsoleCommandLineArgsToCommandInput(args)); if (isBatchOrVersionCmd) { // If batch file is specified as input then do not get in to interactive mode.. quit.. return; } if (!WcsCli2CmConnectionManager.TestConnectionToCmService()) { Console.WriteLine("Please try again by executing \"{0}\" \n", WcsCliConstants.wcscliConsoleParameterHelp); return; } ContinuousConsoleUserInputCapture(); } }
/// <summary> /// Parses the input entered by the user over console /// Calls WcsCliCmProxy class for processing the input /// </summary> private static void ContinuousConsoleUserInputCapture() { String inputString = null; bool _tobreak = false; consoleObj = new ConsoleOperations(); while (true) { inputString = consoleObj.ProcessInput(); if (inputString == null) { continue; } if (inputString.Equals("exit", StringComparison.InvariantCultureIgnoreCase) || inputString.Equals("quit", StringComparison.InvariantCultureIgnoreCase)) { inputString = "wcscli"; inputString += " "; inputString += "-" + WcsCliConstants.terminateCmConnection; _tobreak = true; } if (inputString.ToLower().Contains(" -v")) { inputString = "wcscli "; inputString += "-" + WcsCliConstants.establishCmConnection; inputString += " -v"; } WcsCliCmProxy.InteractiveParseUserCommandGetCmResponse(false, inputString); if (_tobreak) { break; } } // While loop ends return; }