private bool SetDBConnection() { //TODO: add on null or not found throw execption so it will fail string AppNameCalculated = ValueExpression.Calculate(this.AppName); EnvApplication App = (from a in RunOnEnvironment.Applications where a.Name == AppNameCalculated select a).FirstOrDefault(); if (App == null) { Error = "The mapped Environment Application '" + AppNameCalculated + "' was not found in the '" + RunOnEnvironment.Name + "' Environment which was selected for execution."; return(false); } string DBNameCalculated = ValueExpression.Calculate(DBName); DB = (Database)(from d in App.Dbs where d.Name == DBNameCalculated select d).FirstOrDefault(); if (DB == null) { Error = "The mapped DB '" + DBNameCalculated + "' was not found in the '" + AppNameCalculated + "' Environment Application."; return(false); } DB.DSList = DSList; DB.ProjEnvironment = RunOnEnvironment; DB.BusinessFlow = RunOnBusinessFlow; return(true); }
} // eImageType.Help = LifeRing in FontAwesomeIcon public override void Execute() { string jsonContent = String.Empty; ReqisFromFile = false; //temp WA if (ReqisFromFile == true) { String FilePath = JsonInput.ValueForDriver.ToString(); if (FilePath == null || FilePath == String.Empty) { throw new System.ArgumentException("Please provide a valid file name"); } //if (FilePath.Contains("~\\")) //{ // FilePath = FilePath.Replace("~\\", SolutionFolder); //} FilePath = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.SolutionRepository.ConvertSolutionRelativePath(FilePath); jsonContent = System.IO.File.ReadAllText(FilePath); } else { jsonContent = JsonInput.ValueForDriver.ToString(); } XmlDocument doc = null; if (((jsonContent[0] == '[') && (jsonContent[jsonContent.Length - 1] == ']'))) { doc = Newtonsoft.Json.JsonConvert.DeserializeXmlNode("{\"root\":" + jsonContent + "}", "root"); } else { doc = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(jsonContent, "root"); } XmlNode root = doc.DocumentElement; List <General.XmlNodeItem> outputTagsList = new List <General.XmlNodeItem>(); outputTagsList = GingerCore.General.GetXMLNodesItems(doc); foreach (General.XmlNodeItem outputItem in outputTagsList) { foreach (ActInputValue aiv in DynamicElements) { string calculatedValue = ValueExpression.Calculate(@aiv.Param); if (outputItem.path == "/root/" + calculatedValue) { AddOrUpdateReturnParamActualWithPath(outputItem.param, outputItem.value.ToString(), calculatedValue); if (aiv.Value == null || aiv.Value == String.Empty) { } } } } }
private void updateQueryParams() { foreach (ActInputValue AIV in QueryParams) { if (!String.IsNullOrEmpty(AIV.Value)) { AIV.ValueForDriver = ValueExpression.Calculate(AIV.Value); } } }
public void GoToPageURL() { if (mWinExplorer == null) { Reporter.ToUser(eUserMsgKey.POMAgentIsNotRunning); return; } string calculatedValue = ValueExpression.Calculate(null, null, mPOM.PageURL, null); GoToPage(calculatedValue); }
//TODO: move to Run SetAction private void SaveBFResults(ReportInfo RI, string folder, bool statusByGroupActivity) { if (DynamicParameters.Count > 0) { ValueExpression VE = new ValueExpression(RI.Environment, null); for (int i = 0; i < DynamicParameters.Count; i++) { DynamicParameters[i].ValueForDriver = VE.Calculate(DynamicParameters[i].Value); } } TestNGResultReport TNGReport = new TestNGResultReport(); string xml = TNGReport.CreateReport(RI, statusByGroupActivity, DynamicParameters); System.IO.File.WriteAllLines(folder + @"\testng-results.xml", new string[] { xml }); //TODO: let the user select file prefix }
public void GoToPageURL() { if (mWinExplorer == null) { Reporter.ToUser(eUserMsgKey.POMAgentIsNotRunning); return; } string calculatedValue = ValueExpression.Calculate(null, null, mPOM.PageURL, null); ActGotoURL act = new ActGotoURL() { LocateBy = eLocateBy.NA, Value = calculatedValue, ValueForDriver = calculatedValue, Active = true }; mAgent.Driver.RunAction(act); }
private bool CalculateArguments() { try { mJavaWSEXEPath_Calc = ValueExpression.Calculate(mJavaWSEXEPath); if (string.IsNullOrEmpty(mJavaWSEXEPath_Calc)) { mJavaWSEXEPath_Calc = CommonLib.GetJavaHome(); } return(true); } catch (Exception ex) { Error = "Error occurred while calculating the action arguments. Error=" + ex.Message; return(false); } }
private List <Tuple <string, object> > FieldsValueToTupleList(string updatedFieldsValue) { List <Tuple <string, object> > columnNameAndValue = new List <Tuple <string, object> >(); if (String.IsNullOrEmpty(updatedFieldsValue)) { return(columnNameAndValue); } bool isError = false; string result = System.Text.RegularExpressions.Regex.Replace(updatedFieldsValue, @",(?=[^']*'(?:[^']*'[^']*')*[^']*$)", "~^GINGER-EXCEL-COMMA-REPLACE^~"); string[] varColMaps = result.Split(','); varColMaps.ToList().ForEach(c => { result = System.Text.RegularExpressions.Regex.Replace(c, @"=(?=[^']*'(?:[^']*'[^']*')*[^']*$)", "~^GINGER-EXCEL-EQUAL-REPLACE^~"); string[] setData = result.Split('='); if (setData.Length == 2) { string rowToSet = setData[0].Replace("[", "").Replace("]", ""); string valueToSet = setData[1].Replace("~^GINGER-EXCEL-COMMA-REPLACE^~", ",").Replace("~^GINGER-EXCEL-EQUAL-REPLACE^~", "=") .TrimStart('\'').TrimEnd('\''); string fieldValue = valueToSet; //keeping the translation of vars to support previous implementation VariableBase var = RunOnBusinessFlow.GetHierarchyVariableByName(Value); if (var != null) { var.Value = ValueExpression.Calculate(valueToSet); fieldValue = var.Value; } columnNameAndValue.Add(new Tuple <string, object>(rowToSet, fieldValue)); } else { Reporter.ToLog(eLogLevel.INFO, "Invalid data added to 'SetDataUsed' text box"); isError = true; } }); return(isError ? null : columnNameAndValue); }
private List <string> ProcessData(string l) { string DataFilePath; if (DataFileName.StartsWith("~")) { //DataFilePath = System.IO.Path.Combine(SolutionFolder, DataFileName.Replace("~\\", "")); DataFilePath = amdocs.ginger.GingerCoreNET.WorkSpace.Instance.SolutionRepository.ConvertSolutionRelativePath(DataFileName); } else { DataFilePath = DataFileName; } // TODO: process params VE // Process Data for each line use l as template string[] lines = convertExcelToStringArray(DataFilePath, "Sheet1"); string[] headers = lines[0].Split(','); //get col headers List <string> results = new List <string>(); string template = l; for (int i = 1; i < lines.Length; i++) { template = l; string[] tmp = lines[i].Split(','); for (int j = 0; j < tmp.Length; j++) { if (headers.Length < j) { continue; } template = template.Replace(",,", ",#,"); template = template.Replace("{Param=" + headers[j] + "}", tmp[j]); } results.Add(ValueExpression.Calculate(template)); } return(results); }
public void WriteData() { string sql = ""; string ConnString = GetConnectionString(); string result = System.Text.RegularExpressions.Regex.Replace(GetInputParamCalculatedValue("ColMappingRules"), @",(?=[^']*'(?:[^']*'[^']*')*[^']*$)", "~^GINGER-EXCEL-COMMA-REPLACE^~"); string[] varColMaps = result.Split(','); string sSetDataUsed = ""; using (OleDbConnection Conn = new OleDbConnection(ConnString)) { try { Conn.Open(); } catch (Exception ex) { System.Threading.Thread.Sleep(3000); Conn.Open(); Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.StackTrace}", ex); } OleDbCommand Cmd = new OleDbCommand(); Cmd.Connection = Conn; string SheetName = GetInputParamCalculatedValue("SheetName").Trim(); if (String.IsNullOrEmpty(SheetName)) { this.Error += "Sheet Name is empty or not selected. Please Select correct sheet name on action configurations"; Conn.Close(); return; } if (!SheetName.EndsWith("$")) { SheetName += "$"; } if (SelectAllRows == false) { sql = "Select TOP 1 * from [" + SheetName + "]"; } else { sql = "Select * from [" + SheetName + "]"; } string where = GetInputParamCalculatedValue("SelectRowsWhere"); if (!string.IsNullOrEmpty(where)) { sql += " WHERE " + where; } Cmd.CommandText = sql; DataTable dt = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter(); da.SelectCommand = Cmd; string updateSQL = ""; try { da.Fill(dt); if (!string.IsNullOrEmpty(GetInputParamCalculatedValue("SetDataUsed"))) { sSetDataUsed = @", " + GetInputParamCalculatedValue("SetDataUsed"); } // we expect only 1 record if (dt.Rows.Count == 1 && SelectAllRows == false) { DataRow r = dt.Rows[0]; //Read data to variables foreach (string vc in varColMaps) { string strPrimaryKeyColumn = GetInputParamCalculatedValue("PrimaryKeyColumn"); if (strPrimaryKeyColumn.Contains("`")) { strPrimaryKeyColumn = strPrimaryKeyColumn.Replace("`", ""); } string rowKey = r[strPrimaryKeyColumn].ToString(); int res; int.TryParse(rowKey, out res); if (res == 0 || r[strPrimaryKeyColumn].GetType() == typeof(System.String)) { rowKey = "'" + rowKey + "'"; } //TODO: fix me in OO Style //Do mapping string ColName = vc.Split('=')[0]; string Value = vc.Split('=')[1]; Value = Value.Replace("~^GINGER-EXCEL-COMMA-REPLACE^~", ","); string txt = Value; //keeping the translation of vars to support prevoius implementation VariableBase var = RunOnBusinessFlow.GetHierarchyVariableByName(Value); if (var != null) { var.Value = ValueExpression.Calculate(var.Value); txt = var.Value; } //remove '' from value txt = txt.TrimStart(new char[] { '\'' }); txt = txt.TrimEnd(new char[] { '\'' }); //TODO: create one long SQL to do the update in one time and not for each var updateSQL = @"UPDATE [" + GetInputParamCalculatedValue("SheetName") + "$] SET " + ColName + " = '" + txt + "'" + sSetDataUsed + " WHERE " + GetInputParamCalculatedValue("PrimaryKeyColumn") + "=" + rowKey + ";"; this.ExInfo += updateSQL + Environment.NewLine; OleDbCommand myCommand = new OleDbCommand(); myCommand.Connection = Conn; myCommand.CommandText = updateSQL; myCommand.ExecuteNonQuery(); } // Do the update that row is used } else if (dt.Rows.Count > 0 && SelectAllRows == true) { updateSQL = @"UPDATE [" + GetInputParamCalculatedValue("SheetName") + "$] SET "; foreach (string vc in varColMaps) { //TODO: fix me in OO Style //Do mapping string ColName = vc.Split('=')[0]; string Value = vc.Split('=')[1]; Value = Value.Replace("~^GINGER-EXCEL-COMMA-REPLACE^~", ","); string txt = Value; //keeping the translation of vars to support prevoius implementation VariableBase var = RunOnBusinessFlow.GetHierarchyVariableByName(Value); if (var != null) { var.Value = ValueExpression.Calculate(var.Value); if (var != null) { txt = var.Value; } else { txt = Value; } } //remove '' from value txt = txt.TrimStart(new char[] { '\'' }); txt = txt.TrimEnd(new char[] { '\'' }); //TODO: create one long SQL to do the update in one time and not for each var updateSQL = updateSQL + ColName + " = '" + txt + "',"; } updateSQL = updateSQL.Substring(0, updateSQL.Length - 1); updateSQL = updateSQL + sSetDataUsed; if (!string.IsNullOrEmpty(where)) { updateSQL += " WHERE " + where + ";"; } this.ExInfo += updateSQL + Environment.NewLine; OleDbCommand myCommand = new OleDbCommand(); myCommand.Connection = Conn; myCommand.CommandText = updateSQL; myCommand.ExecuteNonQuery(); } else if (dt.Rows.Count == 0) { this.ExInfo = "No Rows updated with given criteria"; } } catch (Exception ex) { // Reporter.ToLog(eAppReporterLogLevel.ERROR, "Wrting into excel got error " + ex.Message); this.Error = "Error when trying to update the excel: " + ex.Message + Environment.NewLine + "UpdateSQL=" + updateSQL; } finally { Conn.Close(); } // then show a message if needed if (dt.Rows.Count == 0) { //TODO: reporter // Reporter.ToUser("No rows found in excel file matching criteria - " + sql); // throw new Exception("No rows found in excel file matching criteria - " + sql); } } }
private string ProcessLine(string line) { return(ValueExpression.Calculate(line)); }
private string CalculateValue(string valueTocalc) { return(ValueExpression.Calculate(valueTocalc).Trim()); }
public override void Execute() { VariableBase Var = RunOnBusinessFlow.GetHierarchyVariableByName(VariableName); if (Var == null) { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = GingerDicser.GetTermResValue(eTermResKey.Variable) + " was not found."; return; } string calculatedValue = string.Empty; if (ValueExpression != null) { ValueExpression.DecryptFlag = false; calculatedValue = ValueExpression.Calculate(this.Value); } else { calculatedValue = this.Value; } if (SetVariableValueOption == VariableBase.eSetValueOptions.SetValue) { if (Var.GetType() == typeof(VariableString)) { ((VariableString)Var).Value = calculatedValue; } else if (Var.GetType() == typeof(VariableSelectionList)) { if (((VariableSelectionList)Var).OptionalValuesList.Where(pv => pv.Value == calculatedValue).SingleOrDefault() != null) { ((VariableSelectionList)Var).Value = calculatedValue; } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "The value '" + calculatedValue + "' is not part of the possible values of the '" + Var.Name + "' " + GingerDicser.GetTermResValue(eTermResKey.Variable) + "."; return; } } else if (Var.GetType() == typeof(VariableList)) { string[] possibleVals = ((VariableList)Var).Formula.Split(','); if (possibleVals != null && possibleVals.Contains(calculatedValue)) { ((VariableList)Var).Value = calculatedValue; } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "The value '" + calculatedValue + "' is not part of the possible values of the '" + Var.Name + "' " + GingerDicser.GetTermResValue(eTermResKey.Variable) + "."; return; } } else if (Var.GetType() == typeof(VariableDynamic)) { ((VariableDynamic)Var).ValueExpression = this.Value; } else if (Var.GetType() == typeof(VariableNumber)) { try { var varNumber = ((VariableNumber)Var); if (varNumber.CheckNumberInRange(float.Parse(calculatedValue))) { varNumber.Value = calculatedValue; } else { Error = $"The value {calculatedValue} is not in the range, {Var.Name}:-[Min value: {varNumber.MinValue}, Max value: {varNumber.MaxValue}] {GingerDicser.GetTermResValue(eTermResKey.Variable) }."; return; } } catch (System.Exception ex) { Error = $"Error occurred during SetValue for Variable number type..:- {ex.Message}"; return; } } else if (Var.GetType() == typeof(VariableDateTime)) { var varDateTime = ((VariableDateTime)Var); try { if (!varDateTime.IsValidDateTimeFormat(calculatedValue)) { Error = $"The Value [{calculatedValue}] is not in correct format, expected format is [{varDateTime.DateTimeFormat}], {GingerDicser.GetTermResValue(eTermResKey.Variable)}."; return; } if (varDateTime.CheckDateTimeWithInRange(calculatedValue)) { varDateTime.Value = calculatedValue; } else { Error = $"The value {calculatedValue} is not in the date range {Var.Name}:-[Min value:{varDateTime.MinDateTime}, Max value:{varDateTime.MaxDateTime}] {GingerDicser.GetTermResValue(eTermResKey.Variable)}."; return; } } catch (Exception ex) { Error = $"Invalid DateTimeFormat,{Var.Name}:-[DateTimeFormat:{varDateTime.DateTimeFormat}] :- {ex.Message}"; return; } } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.ResetValue) { (Var).ResetValue(); } else if (SetVariableValueOption == VariableBase.eSetValueOptions.ClearSpecialChar) { string specChar = ValueExpression.Calculate(this.Value); if (string.IsNullOrEmpty(specChar)) { specChar = @"{}(),\"""; } if (!string.IsNullOrEmpty(((VariableString)Var).Value)) { foreach (char c in specChar) { ((VariableString)Var).Value = ((VariableString)Var).Value.Replace(c.ToString(), ""); } } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.AutoGenerateValue) { ((VariableBase)Var).GenerateAutoValue(); } else if (SetVariableValueOption == VariableBase.eSetValueOptions.StartTimer) { if (Var.GetType() == typeof(VariableTimer)) { ((VariableTimer)Var).StartTimer(); } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Operation type " + SetVariableValueOption + " is not supported for " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " of type " + Var.GetType(); return; } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.StopTimer) { if (Var.GetType() == typeof(VariableTimer)) { ((VariableTimer)Var).StopTimer(); } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Operation type " + SetVariableValueOption + " is not supported for " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " of type " + Var.GetType(); return; } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.ContinueTimer) { if (Var.GetType() == typeof(VariableTimer)) { ((VariableTimer)Var).ContinueTimer(); } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Operation type " + SetVariableValueOption + " is not supported for variable of type " + Var.GetType(); return; } } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Unknown set " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " value operation."; return; } ExInfo = GingerDicser.GetTermResValue(eTermResKey.Variable) + " '" + Var.Name + "' value was set to: '" + Var.Value + "'"; }
public override void Execute() { VariableBase Var = RunOnBusinessFlow.GetHierarchyVariableByName(VariableName); if (Var == null) { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = GingerDicser.GetTermResValue(eTermResKey.Variable) + " was not found."; return; } string calculatedValue = ValueExpression.Calculate(this.Value); if (SetVariableValueOption == VariableBase.eSetValueOptions.SetValue) { if (Var.GetType() == typeof(VariableString)) { ((VariableString)Var).Value = calculatedValue; } else if (Var.GetType() == typeof(VariableSelectionList)) { if (((VariableSelectionList)Var).OptionalValuesList.Where(pv => pv.Value == calculatedValue).SingleOrDefault() != null) { ((VariableSelectionList)Var).Value = calculatedValue; } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "The value '" + calculatedValue + "' is not part of the possible values of the '" + Var.Name + "' " + GingerDicser.GetTermResValue(eTermResKey.Variable) + "."; return; } } else if (Var.GetType() == typeof(VariableList)) { string[] possibleVals = ((VariableList)Var).Formula.Split(','); if (possibleVals != null && possibleVals.Contains(calculatedValue)) { ((VariableList)Var).Value = calculatedValue; } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "The value '" + calculatedValue + "' is not part of the possible values of the '" + Var.Name + "' " + GingerDicser.GetTermResValue(eTermResKey.Variable) + "."; return; } } else if (Var.GetType() == typeof(VariableDynamic)) { ((VariableDynamic)Var).ValueExpression = this.Value; } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.ResetValue) { (Var).ResetValue(); } else if (SetVariableValueOption == VariableBase.eSetValueOptions.ClearSpecialChar) { string specChar = ValueExpression.Calculate(this.Value); if (string.IsNullOrEmpty(specChar)) { specChar = @"{}(),\"""; } if (!string.IsNullOrEmpty(((VariableString)Var).Value)) { foreach (char c in specChar) { ((VariableString)Var).Value = ((VariableString)Var).Value.Replace(c.ToString(), ""); } } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.AutoGenerateValue) { ((VariableBase)Var).GenerateAutoValue(); } else if (SetVariableValueOption == VariableBase.eSetValueOptions.StartTimer) { if (Var.GetType() == typeof(VariableTimer)) { ((VariableTimer)Var).StartTimer(); } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Operation type " + SetVariableValueOption + " is not supported for " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " of type " + Var.GetType(); return; } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.StopTimer) { if (Var.GetType() == typeof(VariableTimer)) { ((VariableTimer)Var).StopTimer(); } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Operation type " + SetVariableValueOption + " is not supported for " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " of type " + Var.GetType(); return; } } else if (SetVariableValueOption == VariableBase.eSetValueOptions.ContinueTimer) { if (Var.GetType() == typeof(VariableTimer)) { ((VariableTimer)Var).ContinueTimer(); } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Operation type " + SetVariableValueOption + " is not supported for variable of type " + Var.GetType(); return; } } else { Status = Amdocs.Ginger.CoreNET.Execution.eRunStatus.Failed; Error = "Unknown set " + GingerDicser.GetTermResValue(eTermResKey.Variable) + " value operation."; return; } ExInfo = GingerDicser.GetTermResValue(eTermResKey.Variable) + " '" + Var.Name + "' value was set to: '" + Var.Value + "'"; }