private void RunCommand() { if (string.IsNullOrEmpty(CommandTextBox.Text)) { CommandTextBox.Text = string.Empty; } if (mRecording) { ActConsoleCommand ACC = new ActConsoleCommand(); ACC.Description = "Command: " + CommandTextBox.Text; ACC.LocateBy = eLocateBy.NA; ACC.AddOrUpdateInputParamValue("Free Command", CommandTextBox.Text); ACC.ConsoleCommand = ActConsoleCommand.eConsoleCommand.FreeCommand; mBusinessFlow.AddAct(ACC); } ConsoleWriteCommand(CommandTextBox.Text); //Checking Console Driver Platform if (mConsoleDriver.Platform.ToString() == "Unix") { //Unix then only \n is required mConsoleDriver.taskFinished = false; mConsoleDriver.SendCommand(CommandTextBox.Text + "\n"); } else { //Dos then \r\n is required mConsoleDriver.SendCommand(CommandTextBox.Text + Environment.NewLine); } CommandTextBox.Text = ""; }
public override string GetCommandText(ActConsoleCommand act) { string cmd = ""; switch (act.ConsoleCommand) { case ActConsoleCommand.eConsoleCommand.FreeCommand: return(GetParameterizedCommand(act)); case ActConsoleCommand.eConsoleCommand.ParametrizedCommand: return(GetParameterizedCommand(act)); case ActConsoleCommand.eConsoleCommand.Script: VerifyFTPConnected(); if (!UnixFTPClient.Exists(workdir + @"/Ginger")) { UnixFTPClient.CreateDirectory(workdir + @"/Ginger"); } string SHFilesPath = mScriptsFolder; string UnixScriptFilePath = workdir + @"/Ginger/" + act.ScriptName; using (var f = File.OpenRead(SHFilesPath + act.ScriptName)) { UnixFTPClient.UploadFile(f, UnixScriptFilePath, null); } UnixFTPClient.ChangePermissions(UnixScriptFilePath, 777); foreach (var p in act.InputValues) { if (!string.IsNullOrEmpty(p.Value)) { cmd += " " + p.ValueForDriver; } } if (UnixScriptFilePath.Trim().EndsWith(".sh", StringComparison.CurrentCultureIgnoreCase)) { return("dos2unix " + UnixScriptFilePath + ";sh " + UnixScriptFilePath + cmd); } else { return("dos2unix " + UnixScriptFilePath + "; " + UnixScriptFilePath + cmd); } default: Reporter.ToLog(eLogLevel.WARN, "Error - unknown command"); ErrorMessageFromDriver += "Error - unknown command"; return("Error - unknown command"); } }
public ActConsoleCommandEditPage(ActConsoleCommand actConsoleCommand) { InitializeComponent(); this.mActConsoleCommand = actConsoleCommand; List <object> list = GetActionListPlatform(); GingerCore.General.FillComboFromEnumObj(ConsoleActionComboBox, actConsoleCommand.ConsoleCommand, list); GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ConsoleActionComboBox, ComboBox.TextProperty, actConsoleCommand, ActConsoleCommand.Fields.ConsoleCommand); GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(CommandTextBox, TextBox.TextProperty, actConsoleCommand, ActConsoleCommand.Fields.Command); GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ScriptNameComboBox, ComboBox.TextProperty, actConsoleCommand, ActConsoleCommand.Fields.ScriptName); GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(txtWait, TextBox.TextProperty, actConsoleCommand, ActConsoleCommand.Fields.WaitTime); xDelimiterVE.BindControl(Context.GetAsContext(actConsoleCommand.Context), actConsoleCommand, nameof(ActConsoleCommand.Delimiter)); txtExpected.Init(Context.GetAsContext(mActConsoleCommand.Context), mActConsoleCommand, ActConsoleCommand.Fields.ExpString); }
private string GetParameterizedCommand(ActConsoleCommand act) { string s = act.Command; foreach (ActInputValue AIV in act.InputValues) { if (s != null) { s = s + " " + AIV.ValueForDriver; } else { s = AIV.ValueForDriver; } } return(s); }
public override string GetCommandText(ActConsoleCommand act) { //TODO: Enhance Handling for commands copyfile, dir switch (act.ConsoleCommand) { case ActConsoleCommand.eConsoleCommand.FreeCommand: return(GetParameterizedCommand(act)); case ActConsoleCommand.eConsoleCommand.CopyFile: return("copy " + GetParameterizedCommand(act)); case ActConsoleCommand.eConsoleCommand.IsFileExist: return("dir " + GetParameterizedCommand(act)); default: Reporter.ToLog(eAppReporterLogLevel.INFO, "Unkonwn Console command"); ErrorMessageFromDriver = "Unkonwn Console command"; return("Error - unknown command"); } }
private string GetParameterizedCommand(ActConsoleCommand act) { string command = act.Command; foreach (ActInputValue AIV in act.InputValues) { string calcValue; if (string.IsNullOrEmpty(AIV.Value) == false && AIV.Value.StartsWith("~"))//workaround for keeping the ~ to work on linux { string prefix; if (AIV.Value.StartsWith("~/") || AIV.Value.StartsWith("~\\")) { prefix = AIV.Value.Substring(0, 2); } else { prefix = "~"; } calcValue = AIV.ValueForDriver.Replace(WorkSpace.Instance.Solution.Folder.TrimEnd(new char[] { '/', '\\' }) + Path.DirectorySeparatorChar, prefix); } else { calcValue = AIV.ValueForDriver; } if (command != null) { command = command + " " + calcValue; } else { command = calcValue; } } return(command); }
// Get the action command to be send to the specific derived driver public abstract string GetCommandText(ActConsoleCommand act);
public override void RunAction(Act act) { //TODO: add func to Act + Enum for switch string actClass = act.GetType().ToString(); //TODO: avoid hard coded string... actClass = actClass.Replace("GingerCore.Actions.", ""); switch (actClass) { case "ActConsoleCommand": mWait = ((ActConsoleCommand)act).WaitTime; ValueExpression VE = new ValueExpression(this.Environment, this.BusinessFlow); string ExpString = ((ActConsoleCommand)act).ExpString; VE.Value = ExpString; mExpString = VE.ValueCalculated; ActConsoleCommand ACC = (ActConsoleCommand)act; string command = GetCommandText(ACC); act.ExInfo = command; taskFinished = false; if (command.StartsWith("GINGER_RC=")) { //This is FTP command and we already have the result act.AddOrUpdateReturnParamActual("GINGER_RC", command.Replace("GINGER_RC=", "")); } else { string sRC; //Send the command via driver if (ACC.ConsoleCommand == ActConsoleCommand.eConsoleCommand.Script) { //TODO: externalize static const for ~~~GINGER_RC_END~~~ and all hard coded multi use strings sRC = mConsoleDriverWindow.RunConsoleCommand(command, "~~~GINGER_RC_END~~~"); } else { sRC = mConsoleDriverWindow.RunConsoleCommand(command); } if (mExpString != null && sRC.Contains(mExpString) == false) { act.Error = @"Expected String """ + mExpString + @""" not found in command output"; act.Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; return; } act.AddOrUpdateReturnParamActual("Result", sRC); sRC = sRC.Replace("\r", ""); sRC = sRC.Replace("\t", ""); string[] RCValues = sRC.Split('\n'); foreach (string RCValue in RCValues) { if (RCValue.Trim().Length > 0) { string Param; string Value; int i = -1; if (!string.IsNullOrEmpty(ACC.Delimiter)) { i = RCValue.IndexOf(ACC.Delimiter); } else { i = RCValue.IndexOf('='); } if ((i > 0) && (i != RCValue.IndexOf("==")) && (i != RCValue.IndexOf("!=") + 1)) { Param = (RCValue.Substring(0, i)).Trim(); //the rest is the value Value = RCValue.Substring(Param.Length + 1); Value = new string(Value.Where(ch => !char.IsControl(ch)).ToArray()); act.AddOrUpdateReturnParamActual(Param, Value); } } } } break; case "ActScreenShot": TakeScreenShot(act); break; default: throw new Exception("Action unknown/Not Impl in Driver - " + this.GetType().ToString()); } }