protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var outputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath, update)); colItr.AddVariableToIterateOn(outputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); if(dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(OutputPath, "File or Folder", dataObject.Environment, update)); AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite")); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Destination Private Key File", dataObject.Environment, update); } } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); Dev2CRUDOperationTO opTo = new Dev2CRUDOperationTO(Overwrite); try { IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(outputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst); string result = broker.Create(dstEndPoint, opTo, true); outputs.Add(DataListFactory.CreateOutputTO(Result, result)); } catch(Exception e) { outputs.Add(DataListFactory.CreateOutputTO(Result, "Failure")); allErrors.AddError(e.Message); break; } } return outputs; }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", dataObject.Environment, update); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if(!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update); } } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); IActivityIOPath ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint endpoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(ioPath); try { string result = broker.Get(endpoint); outputs[0].OutputStrings.Add(result); } catch(Exception e) { outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return outputs; }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(Password)); colItr.AddVariableToIterateOn(passItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", dataObject.Environment); AddDebugInputItemUserNamePassword(dataObject.Environment); } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); try { IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true); IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst); string result = broker.Delete(dstEndPoint); outputs[0].OutputStrings.Add(result); } catch(Exception e) { outputs.Add(DataListFactory.CreateOutputTO(Result, "Failure")); //outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return outputs; }
static bool RunBetween(IEnumerable<DataASTMutable.WarewolfAtom> warewolfAtoms, IEnumerable<DataASTMutable.WarewolfAtom> tovals, DataASTMutable.WarewolfAtom a) { WarewolfListIterator iterator = new WarewolfListIterator(); var from = new WarewolfAtomIterator(warewolfAtoms); var to = new WarewolfAtomIterator(tovals); iterator.AddVariableToIterateOn(@from); iterator.AddVariableToIterateOn(to); while(iterator.HasMoreData()) { var fromval = iterator.FetchNextValue(@from); var toVal = iterator.FetchNextValue(to); DateTime fromDt; if(DateTime.TryParse(fromval, out fromDt)) { DateTime toDt; if(!DateTime.TryParse(toVal, out toDt)) { throw new InvalidDataException("IsBetween Numeric and DateTime mis-match"); } DateTime recDateTime; if(DateTime.TryParse(a.ToString(), out recDateTime)) { if(recDateTime > fromDt && recDateTime < toDt) { return true; } } } double fromNum; if(double.TryParse(fromval, out fromNum)) { double toNum; if(!double.TryParse(toVal, out toNum)) { return false; } double recNum; if(!double.TryParse(a.ToString(), out recNum)) { continue; } if(recNum > fromNum && recNum < toNum) { return true; } } } return false; }
public void WarewolfListIterator_FetchNextValue_NoValuesToIterateOn_ReturnsException() { //------------Setup for test-------------------------- var env = new ExecutionEnvironment(); var warewolfListIterator = new WarewolfListIterator(); var warewolfIterator = new WarewolfIterator(env.Eval("[[rec().a]]", 0)); //------------Execute Test--------------------------- var value = warewolfListIterator.FetchNextValue(warewolfIterator); //------------Assert Results------------------------- Assert.IsNull(value); }
public void WarewolfListIterator_FetchNextValue_WithStar_HasValues_ShouldReturnValues() { //------------Setup for test-------------------------- var env = new ExecutionEnvironment(); env.Assign("[[rec().a]]", "Test", 0); env.Assign("[[rec().a]]", "Test2", 0); env.Assign("[[rec().a]]", "Test4", 0); env.Assign("[[rec().a]]", "Test5", 0); env.CommitAssign(); var warewolfListIterator = new WarewolfListIterator(); var warewolfIterator = new WarewolfIterator(env.Eval("[[rec(*).a]]", 0)); warewolfListIterator.AddVariableToIterateOn(warewolfIterator); //------------Execute Test--------------------------- var value = warewolfListIterator.FetchNextValue(warewolfIterator); //------------Assert Results------------------------- Assert.AreEqual("Test", value); //------------Execute Test--------------------------- value = warewolfListIterator.FetchNextValue(warewolfIterator); //------------Assert Results------------------------- Assert.AreEqual("Test2", value); }
public static string GetJsonOutputFromEnvironment(IDSFDataObject dataObject,string dataList,int update) { var environment = dataObject.Environment; var dataListTO = new DataListTO(dataList); StringBuilder result = new StringBuilder("{"); var keyCnt = 0; var scalarOutputs = dataListTO.Outputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Outputs.Where(DataListUtil.IsValueRecordset); var groupedRecSets = recSetOutputs.GroupBy(DataListUtil.ExtractRecordsetNameFromValue); var recSets = groupedRecSets as IGrouping<string, string>[] ?? groupedRecSets.ToArray(); foreach (var groupedRecSet in recSets) { var i = 0; var warewolfListIterators = new WarewolfListIterator(); Dictionary<string, IWarewolfIterator> iterators = new Dictionary<string, IWarewolfIterator>(); foreach (var name in groupedRecSet) { var warewolfIterator = new WarewolfIterator(environment.Eval(name, update,false)); iterators.Add(DataListUtil.ExtractFieldNameFromValue(name), warewolfIterator); warewolfListIterators.AddVariableToIterateOn(warewolfIterator); } result.Append("\""); result.Append(groupedRecSet.Key); result.Append("\" : ["); while (warewolfListIterators.HasMoreData()) { int colIdx = 0; result.Append("{"); foreach (var namedIterator in iterators) { try { var value = warewolfListIterators.FetchNextValue(namedIterator.Value); result.Append("\""); result.Append(namedIterator.Key); result.Append("\":\""); result.Append(value); result.Append("\""); colIdx++; if (colIdx < iterators.Count) { result.Append(","); } } catch(Exception e) { Dev2Logger.Log.Debug(e.Message,e); colIdx++; } } if (warewolfListIterators.HasMoreData()) { result = new StringBuilder(result.ToString().TrimEnd(',')); result.Append("}"); result.Append(","); } } result.Append("}"); result.Append("]"); i++; if (i <= recSets.Length) { result.Append(","); } } var scalars = scalarOutputs as string[] ?? scalarOutputs.ToArray(); foreach (var output in scalars) { var evalResult = environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(output), update,false); if (evalResult.IsWarewolfAtomResult) { var scalarResult = evalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (scalarResult != null && !scalarResult.Item.IsNothing) { result.Append("\""); result.Append(output); result.Append("\":\""); result.Append(scalarResult.Item); result.Append("\""); } } keyCnt++; if (keyCnt < scalars.Length) { result.Append(","); } } var jsonOutputFromEnvironment = result.ToString(); jsonOutputFromEnvironment = jsonOutputFromEnvironment.TrimEnd(','); jsonOutputFromEnvironment += "}"; return jsonOutputFromEnvironment; }
public static string GetXmlOutputFromEnvironment(IDSFDataObject dataObject,string dataList,int update) { var environment = dataObject.Environment; var dataListTO = new DataListTO(dataList); StringBuilder result = new StringBuilder("<DataList>"); var scalarOutputs = dataListTO.Outputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Outputs.Where(DataListUtil.IsValueRecordset); var groupedRecSets = recSetOutputs.GroupBy(DataListUtil.ExtractRecordsetNameFromValue); foreach (var groupedRecSet in groupedRecSets) { var i = 1; var warewolfListIterators = new WarewolfListIterator(); Dictionary<string, IWarewolfIterator> iterators = new Dictionary<string, IWarewolfIterator>(); foreach (var name in groupedRecSet) { var warewolfEvalResult = WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing); try { warewolfEvalResult = environment.Eval(name, update,false); } // ReSharper disable once RESP510236 // ReSharper disable once RESP510241 catch(Exception e) { Dev2Logger.Log.Debug("Null Variable",e); } var warewolfIterator = new WarewolfIterator(warewolfEvalResult); iterators.Add(DataListUtil.ExtractFieldNameFromValue(name), warewolfIterator); warewolfListIterators.AddVariableToIterateOn(warewolfIterator); } while (warewolfListIterators.HasMoreData()) { result.Append("<"); result.Append(groupedRecSet.Key); result.Append(string.Format(" Index=\"{0}\">", i)); foreach (var namedIterator in iterators) { try { var value = warewolfListIterators.FetchNextValue(namedIterator.Value); result.Append("<"); result.Append(namedIterator.Key); result.Append(">"); result.Append(value); result.Append("</"); result.Append(namedIterator.Key); result.Append(">"); } catch(Exception e) { Dev2Logger.Log.Debug(e.Message,e); } } result.Append("</"); result.Append(groupedRecSet.Key); result.Append(">"); i++; } } foreach (var output in scalarOutputs) { var evalResult = environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(output), update,false); if (evalResult.IsWarewolfAtomResult) { var scalarResult = evalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (scalarResult != null && !scalarResult.Item.IsNothing) { result.Append("<"); result.Append(output); result.Append(">"); result.Append(scalarResult.Item); result.Append("</"); result.Append(output); result.Append(">"); } } } result.Append("</DataList>"); return result.ToString(); }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IList<OutputTO> outputs = new List<OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath, update)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); var contentItr =new WarewolfIterator(dataObject.Environment.Eval(FileContents, update)); colItr.AddVariableToIterateOn(contentItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if(dataObject.IsDebugMode()) { AddDebugInputItem(OutputPath, "Output Path", dataObject.Environment, update); AddDebugInputItem(new DebugItemStaticDataParams(GetMethod(), "Method")); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update); } AddDebugInputItem(FileContents, "File Contents", dataObject.Environment, update); } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); var writeType = GetCorrectWriteType(); Dev2PutRawOperationTO putTo = ActivityIOFactory.CreatePutRawOperationTO(writeType, TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(colItr.FetchNextValue(contentItr))); IActivityIOPath opath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(opath); try { if(allErrors.HasErrors()) { outputs[0].OutputStrings.Add(null); } else { string result = broker.PutRaw(endPoint, putTo); outputs[0].OutputStrings.Add(result); } } catch(Exception e) { outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return outputs; }
public static string GetXmlInputFromEnvironment(IDSFDataObject dataObject, Guid workspaceGuid, string dataList) { var environment = dataObject.Environment; var dataListTO = new DataListTO(dataList); StringBuilder result = new StringBuilder("<" + "DataList" + ">"); var scalarOutputs = dataListTO.Inputs.Where(s => !DataListUtil.IsValueRecordset(s)); var recSetOutputs = dataListTO.Inputs.Where(DataListUtil.IsValueRecordset); var groupedRecSets = recSetOutputs.GroupBy(DataListUtil.ExtractRecordsetNameFromValue); foreach (var groupedRecSet in groupedRecSets) { var i = 1; var warewolfListIterators = new WarewolfListIterator(); Dictionary<string, IWarewolfIterator> iterators = new Dictionary<string, IWarewolfIterator>(); foreach (var name in groupedRecSet) { var warewolfIterator = new WarewolfIterator(environment.Eval(name)); iterators.Add(DataListUtil.ExtractFieldNameFromValue(name), warewolfIterator); warewolfListIterators.AddVariableToIterateOn(warewolfIterator); } while (warewolfListIterators.HasMoreData()) { result.Append("<"); result.Append(groupedRecSet.Key); result.Append(string.Format(" Index=\"{0}\">", i)); foreach (var namedIterator in iterators) { var value = warewolfListIterators.FetchNextValue(namedIterator.Value); result.Append("<"); result.Append(namedIterator.Key); result.Append(">"); result.Append(value); result.Append("</"); result.Append(namedIterator.Key); result.Append(">"); } result.Append("</"); result.Append(groupedRecSet.Key); result.Append(">"); i++; } } foreach (var output in scalarOutputs) { var evalResult = environment.Eval(DataListUtil.AddBracketsToValueIfNotExist(output)); if (evalResult.IsWarewolfAtomResult) { var scalarResult = evalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (scalarResult != null && !scalarResult.Item.IsNothing) { result.Append("<"); result.Append(output); result.Append(">"); result.Append(scalarResult.Item); result.Append("</"); result.Append(output); result.Append(">"); } } } result.Append("</" + "DataList" + ">"); return result.ToString(); }
protected override IList<OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors, int update) { IsNotCertVerifiable = true; allErrors = new ErrorResultTO(); IList<OutputTO> outputs = new List<OutputTO>(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(InputPath, update)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username, update)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword,update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(dataObject.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); if(dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", dataObject.Environment, update); AddDebugInputItem(new DebugItemStaticDataParams(GetReadType().GetDescription(), "Read")); AddDebugInputItemUserNamePassword(dataObject.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", dataObject.Environment, update); } } while(colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); IActivityIOPath ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(ioPath); try { IList<IActivityIOPath> listOfDir = broker.ListDirectory(endPoint, GetReadType()); if(DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) != enRecordsetIndexType.Numeric) { if(DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { string recsetName = DataListUtil.ExtractRecordsetNameFromValue(Result); string fieldName = DataListUtil.ExtractFieldNameFromValue(Result); int indexToUpsertTo = 1; if(listOfDir != null) { foreach(IActivityIOPath pa in listOfDir) { string fullRecsetName = DataListUtil.CreateRecordsetDisplayValue(recsetName, fieldName, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); outputs.Add(DataListFactory.CreateOutputTO(DataListUtil.AddBracketsToValueIfNotExist(fullRecsetName), pa.Path)); indexToUpsertTo++; } } } else if(DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Blank) { if(listOfDir != null) { foreach(IActivityIOPath pa in listOfDir) { outputs.Add(DataListFactory.CreateOutputTO(Result, pa.Path)); } } } } else { if(listOfDir != null) { string xmlList = string.Join(",", listOfDir.Select(c => c.Path)); outputs.Add(DataListFactory.CreateOutputTO(Result)); outputs.Last().OutputStrings.Add(xmlList); } } } catch(Exception e) { outputs.Add(DataListFactory.CreateOutputTO(null)); allErrors.AddError(e.Message); break; } } return outputs; }