void AddResultDebugInputs(IEnumerable <FindRecordsTO> resultsCollection, Guid executionId, IDataListCompiler compiler) { var indexCount = 1; foreach (var findRecordsTo in resultsCollection) { DebugItem debugItem = new DebugItem(); if (!String.IsNullOrEmpty(findRecordsTo.SearchType)) { AddDebugItem(new DebugItemStaticDataParams("", indexCount.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemStaticDataParams(findRecordsTo.SearchType, ""), debugItem); if (!string.IsNullOrEmpty(findRecordsTo.SearchCriteria)) { var expressionsEntry = compiler.Evaluate(executionId, enActionType.User, findRecordsTo.SearchCriteria, false, out errorsTo); AddDebugItem(new DebugItemVariableParams(findRecordsTo.SearchCriteria, "", expressionsEntry, executionId), debugItem); } if (findRecordsTo.SearchType == "Is Between" || findRecordsTo.SearchType == "Not Between") { var expressionsEntryFrom = compiler.Evaluate(executionId, enActionType.User, findRecordsTo.From, false, out errorsTo); AddDebugItem(new DebugItemVariableParams(findRecordsTo.From, "", expressionsEntryFrom, executionId), debugItem); var expressionsEntryTo = compiler.Evaluate(executionId, enActionType.User, findRecordsTo.To, false, out errorsTo); AddDebugItem(new DebugItemVariableParams(findRecordsTo.To, " And", expressionsEntryTo, executionId), debugItem); } _debugInputs.Add(debugItem); indexCount++; } } }
public static IBinaryDataListEntry EvaluateBinaryDataListEntry(string expression, Guid executionID) { ErrorResultTO errors; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); var dataList = compiler.FetchBinaryDataList(executionID, out errors); if (DataListUtil.IsValueRecordset(expression)) { IBinaryDataListEntry expressionsEntry; string error; dataList.TryGetEntry(DataListUtil.ExtractRecordsetNameFromValue(expression), out expressionsEntry, out error); return(compiler.Evaluate(executionID, enActionType.User, expression, false, out errors)); } return(compiler.Evaluate(executionID, enActionType.User, expression, false, out errors)); }
public List <IDebugItem> GetDebugInputs(IBinaryDataList dataList, IDataListCompiler compiler, IDev2LanguageParser parser) { IList <IDev2Definition> inputs = parser.Parse(InputMapping); var results = new List <IDebugItem>(); foreach (IDev2Definition dev2Definition in inputs) { ErrorResultTO errors; IBinaryDataListEntry tmpEntry = compiler.Evaluate(dataList.UID, enActionType.User, dev2Definition.RawValue, false, out errors); DebugItem itemToAdd = new DebugItem(); AddDebugItem(new DebugItemVariableParams(dev2Definition.RawValue, "", tmpEntry, dataList.UID), itemToAdd); if (errors.HasErrors()) { itemToAdd.FlushStringBuilder(); throw new DebugCopyException(errors.MakeDisplayReady(), itemToAdd); } results.Add(itemToAdd); } foreach (IDebugItem debugInput in results) { debugInput.FlushStringBuilder(); } return(results); }
void AddDebugInputItemFromEntry(string expression, string parameterName, IDataListCompiler compiler, Guid executionId, DebugItem debugItem) { ErrorResultTO errorsResultTo; var expressionsEntry = compiler.Evaluate(executionId, enActionType.User, expression, false, out errorsResultTo); AddDebugItem(new DebugItemVariableParams(expression, parameterName, expressionsEntry, executionId), debugItem); }
List <IDev2DataListEvaluateIterator> GetIteratorsFromInputMappings(IDataListCompiler compiler, Guid executionId, IDSFDataObject dataObject, IDev2IteratorCollection iteratorCollection, out ErrorResultTO errorsResultTo) { errorsResultTo = new ErrorResultTO(); var listOfIterators = new List <IDev2DataListEvaluateIterator>(); var indexCounter = 1; foreach (var row in InputMappings) { if (String.IsNullOrEmpty(row.InputColumn)) { continue; } ErrorResultTO invokeErrors; var expressionsEntry = compiler.Evaluate(executionId, enActionType.User, row.InputColumn, false, out invokeErrors); errorsResultTo.MergeErrors(invokeErrors); if (dataObject.IsDebugMode()) { AddDebugInputItem(row.InputColumn, row.OutputColumn.ColumnName, expressionsEntry, row.OutputColumn.DataTypeName, executionId, indexCounter); indexCounter++; } var itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); iteratorCollection.AddIterator(itr); listOfIterators.Add(itr); } return(listOfIterators); }
public List <DebugItem> GetDebugInputs(IList <IDev2Definition> inputs, IBinaryDataList dataList, ErrorResultTO errors) { if (errors == null) { throw new ArgumentNullException("errors"); } IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); var results = new List <DebugItem>(); foreach (IDev2Definition dev2Definition in inputs) { IBinaryDataListEntry tmpEntry = compiler.Evaluate(dataList.UID, enActionType.User, GetVariableName(dev2Definition), false, out errors); var val = tmpEntry.FetchScalar(); val.TheValue += ""; DebugItem itemToAdd = new DebugItem(); AddDebugItem(new DebugItemVariableParams(GetVariableName(dev2Definition), "", tmpEntry, dataList.UID), itemToAdd); results.Add(itemToAdd); } foreach (IDebugItem debugInput in results) { debugInput.FlushStringBuilder(); } return(results); }
public List <DebugItem> GetDebugValues(IList <IDev2Definition> values, IBinaryDataList dataList, out ErrorResultTO errors) { errors = new ErrorResultTO(); IDataListCompiler compiler = _getDataListCompiler(); var results = new List <DebugItem>(); var added = new List <string>(); foreach (IDev2Definition dev2Definition in values) { IBinaryDataListEntry tmpEntry = compiler.Evaluate(dataList.UID, enActionType.User, GetVariableName(dev2Definition), false, out errors); GetValue(tmpEntry, dev2Definition); var defn = GetVariableName(dev2Definition); if (added.Any(a => a == defn)) { continue; } added.Add(defn); DebugItem itemToAdd = new DebugItem(); _add(new DebugItemVariableParams(GetVariableName(dev2Definition), "", tmpEntry, dataList.UID), itemToAdd); results.Add(itemToAdd); } foreach (IDebugItem debugInput in results) { debugInput.FlushStringBuilder(); } return(results); }
public override List <DebugItem> GetDebugOutputs(IBinaryDataList dataList) { IDev2LanguageParser parser = DataListFactory.CreateOutputParser(); IList <IDev2Definition> inputs = parser.Parse(OutputMapping); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); var results = new List <DebugItem>(); foreach (IDev2Definition dev2Definition in inputs) { ErrorResultTO errors; IBinaryDataListEntry tmpEntry = compiler.Evaluate(dataList.UID, enActionType.User, dev2Definition.RawValue, false, out errors); if (tmpEntry != null) { DebugItem itemToAdd = new DebugItem(); AddDebugItem(new DebugItemVariableParams(dev2Definition.RawValue, "", tmpEntry, dataList.UID), itemToAdd); results.Add(itemToAdd); } else { if (errors.HasErrors()) { throw new Exception(errors.MakeDisplayReady()); } } } foreach (IDebugItem debugOutput in results) { debugOutput.FlushStringBuilder(); } return(results); }
private void AddDebug(IEnumerable <DataSplitDTO> resultCollection, IDataListCompiler compiler, Guid dlId) { foreach (DataSplitDTO t in resultCollection) { IBinaryDataListEntry entry; ErrorResultTO errors; DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", _indexCounter.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(DebugUtil.EvaluateEmptyRecordsetBeforeAddingToDebugOutput(t.OutputVariable, "", dlId), debugItem); AddDebugItem(new DebugItemStaticDataParams(t.SplitType, "With"), debugItem); switch (t.SplitType) { case "Index": entry = compiler.Evaluate(dlId, enActionType.User, t.At, false, out errors); AddDebugItem(new DebugItemVariableParams(t.At, "Using", entry, dlId), debugItem); AddDebugItem(new DebugItemStaticDataParams(t.Include ? "Yes" : "No", "Include"), debugItem); break; case "End": AddDebugItem(new DebugItemStaticDataParams(t.Include ? "Yes" : "No", "Include"), debugItem); break; case "Space": AddDebugItem(new DebugItemStaticDataParams(t.Include ? "Yes" : "No", "Include"), debugItem); break; case "Tab": AddDebugItem(new DebugItemStaticDataParams(t.Include ? "Yes" : "No", "Include"), debugItem); break; case "New Line": AddDebugItem(new DebugItemStaticDataParams(t.Include ? "Yes" : "No", "Include"), debugItem); break; case "Chars": entry = compiler.Evaluate(dlId, enActionType.User, t.At, false, out errors); AddDebugItem(new DebugItemVariableParams(t.At, "Using", entry, dlId), debugItem); AddDebugItem(new DebugItemStaticDataParams(t.Include ? "Yes" : "No", "Include"), debugItem); AddDebugItem(new DebugItemStaticDataParams(t.EscapeChar, "Escape"), debugItem); break; } _indexCounter++; _debugInputs.Add(debugItem); } }
protected override void AddItemsToIterator(Guid executionId, IDataListCompiler compiler, List <ErrorResultTO> errors) { ErrorResultTO error; IBinaryDataListEntry archPassEntry = compiler.Evaluate(executionId, enActionType.User, ArchivePassword, false, out error); errors.Add(error); _archPassItr = Dev2ValueObjectFactory.CreateEvaluateIterator(archPassEntry); ColItr.AddIterator(_archPassItr); }
public static DebugOutputBase EvaluateEmptyRecordsetBeforeAddingToDebugOutput(string expression, string labelText, Guid executionID) { ErrorResultTO errors; string error; IBinaryDataListEntry expressionsEntry; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); var dataList = compiler.FetchBinaryDataList(executionID, out errors); if (DataListUtil.IsValueRecordset(expression)) { var found = dataList.TryGetEntry(DataListUtil.ExtractRecordsetNameFromValue(expression), out expressionsEntry, out error); if ((found && expressionsEntry.IsEmpty()) || !found) { return(new DebugItemStaticDataParams("", expression, labelText)); } expressionsEntry = compiler.Evaluate(executionID, enActionType.User, expression, false, out errors); return(new DebugItemVariableParams(expression, labelText, expressionsEntry, executionID)); } expressionsEntry = compiler.Evaluate(executionID, enActionType.User, expression, false, out errors); return(new DebugItemVariableParams(expression, labelText, expressionsEntry, executionID)); }
IDev2DataListEvaluateIterator CreateDataListEvaluateIterator(string expression, Guid executionId, IDataListCompiler compiler, IDev2IteratorCollection iteratorCollection, ErrorResultTO allErrors) { ErrorResultTO errors; IBinaryDataListEntry expressionEntry = compiler.Evaluate(executionId, enActionType.User, expression, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator expressionIterator = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionEntry); iteratorCollection.AddIterator(expressionIterator); return(expressionIterator); }
/// <summary> /// Fetches the type of the execution. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="dlId">The dl ID.</param> /// <param name="compiler">The compiler.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private ForEachBootstrapTO FetchExecutionType(IDSFDataObject dataObject, Guid dlId, IDataListCompiler compiler, out ErrorResultTO errors) { if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(ForEachType.GetDescription(), ""), debugItem); if (ForEachType == enForEachType.NumOfExecution && !string.IsNullOrEmpty(NumOfExections)) { IBinaryDataListEntry numOfExectionsEntry = compiler.Evaluate(dlId, enActionType.User, NumOfExections, false, out errors); AddDebugItem(new DebugItemVariableParams(NumOfExections, "Number", numOfExectionsEntry, dlId), debugItem); } if (ForEachType == enForEachType.InCSV && !string.IsNullOrEmpty(CsvIndexes)) { IBinaryDataListEntry csvIndexesEntry = compiler.Evaluate(dlId, enActionType.User, CsvIndexes, false, out errors); AddDebugItem(new DebugItemVariableParams(CsvIndexes, "Csv Indexes", csvIndexesEntry, dlId), debugItem); } if (ForEachType == enForEachType.InRange && !string.IsNullOrEmpty(From)) { IBinaryDataListEntry fromEntry = compiler.Evaluate(dlId, enActionType.User, From, false, out errors); AddDebugItem(new DebugItemVariableParams(From, "From", fromEntry, dlId), debugItem); } if (ForEachType == enForEachType.InRange && !string.IsNullOrEmpty(To)) { IBinaryDataListEntry toEntry = compiler.Evaluate(dlId, enActionType.User, To, false, out errors); AddDebugItem(new DebugItemVariableParams(To, "To", toEntry, dlId), debugItem); } if (ForEachType == enForEachType.InRecordset && !string.IsNullOrEmpty(Recordset)) { var toEmit = Recordset.Replace("()", "(*)"); IBinaryDataListEntry toEntry = compiler.Evaluate(dlId, enActionType.User, toEmit, false, out errors); AddDebugItem(new DebugItemVariableParams(toEmit, "Recordset", toEntry, dlId), debugItem); } _debugInputs.Add(debugItem); } var result = new ForEachBootstrapTO(ForEachType, From, To, CsvIndexes, NumOfExections, Recordset, dlId, compiler, out errors); return(result); }
IDev2IteratorCollection BuildParametersIteratorCollection(IDataListCompiler compiler, Guid executionId, out IDev2DataListEvaluateIterator batchIterator, out IDev2DataListEvaluateIterator timeOutIterator) { ErrorResultTO errorResultTo; var parametersIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); batchIterator = null; timeOutIterator = null; if (!String.IsNullOrEmpty(BatchSize)) { var batchSizeEntry = compiler.Evaluate(executionId, enActionType.User, BatchSize, false, out errorResultTo); var batchItr = Dev2ValueObjectFactory.CreateEvaluateIterator(batchSizeEntry); parametersIteratorCollection.AddIterator(batchItr); batchIterator = batchItr; } if (!String.IsNullOrEmpty(Timeout)) { var timeoutEntry = compiler.Evaluate(executionId, enActionType.User, Timeout, false, out errorResultTo); var timeoutItr = Dev2ValueObjectFactory.CreateEvaluateIterator(timeoutEntry); parametersIteratorCollection.AddIterator(timeoutItr); timeOutIterator = timeoutItr; } return(parametersIteratorCollection); }
void AddResultDebugInputs(IEnumerable <XPathDTO> resultsCollection, Guid executionId, IDataListCompiler compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); var i = 1; foreach (var xPathDto in resultsCollection) { if (!String.IsNullOrEmpty(xPathDto.OutputVariable)) { var expressionsEntry = compiler.Evaluate(executionId, enActionType.User, xPathDto.XPath, false, out errorsTo); errors.MergeErrors(errorsTo); compiler.Evaluate(executionId, enActionType.User, xPathDto.OutputVariable, false, out errorsTo); errors.MergeErrors(errorsTo); if (_isDebugMode) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", i.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugItemVariableParams(xPathDto.OutputVariable, "", expressionsEntry, executionId), itemToAdd); _debugInputs.Add(itemToAdd); i++; } } } }
/// <summary> /// Gets a value from data list for a expression. /// </summary> /// <param name="expression">The expression to find the value for.</param> /// <param name="datalistID">The datalist unique identifier.</param> /// <param name="compiler">The compiler.</param> /// <returns></returns> /// <exception cref="System.Exception"></exception> private static string GetValueFromDataList(string expression, Guid datalistID, IDataListCompiler compiler) { expression = DataListUtil.AddBracketsToValueIfNotExist(expression); ErrorResultTO errors; IBinaryDataListEntry returnedEntry = compiler.Evaluate(datalistID, enActionType.User, expression, false, out errors); if (returnedEntry == null) { throw new Exception(errors.MakeUserReady()); } IBinaryDataListItem item = returnedEntry.FetchScalar(); string result = item.TheValue; return(result); }
void AddInputDebugItemResultsAfterEvaluate(List <IDebugItem> result, ref string userModel, IBinaryDataList dataList, Dev2DecisionMode decisionMode, string expression, out ErrorResultTO error, DebugItem parent = null) { error = new ErrorResultTO(); if (expression != null && DataListUtil.IsEvaluated(expression)) { DebugOutputBase debugResult; if (error.HasErrors()) { debugResult = new DebugItemStaticDataParams("", expression, ""); } else { var expressiomToStringValue = EvaluateExpressiomToStringValue(expression, decisionMode, dataList); userModel = userModel.Replace(expression, expressiomToStringValue); ErrorResultTO errors; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dataList.UID, enActionType.User, expression, false, out errors); debugResult = new DebugItemVariableParams(expression, "", expressionsEntry, dataList.UID); } var itemResults = debugResult.GetDebugItemResult(); var allReadyAdded = new List <IDebugItemResult>(); itemResults.ForEach(a => { var found = result.SelectMany(r => r.FetchResultsList()) .SingleOrDefault(r => r.Variable.Equals(a.Variable)); if (found != null) { allReadyAdded.Add(a); } }); allReadyAdded.ForEach(i => itemResults.Remove(i)); if (parent == null) { result.Add(new DebugItem(itemResults)); } else { parent.AddRange(itemResults); } } }
void AddDebugInputValues(IDSFDataObject dataObject, IEnumerable <string> toSearch, IDataListCompiler compiler, Guid executionId, ref ErrorResultTO errorTos) { if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "In Field(s)"), debugItem); foreach (var s in toSearch) { var searchFields = s; if (DataListUtil.IsValueRecordset(s)) { searchFields = searchFields.Replace("()", "(*)"); } IBinaryDataListEntry tmpEntry = compiler.Evaluate(executionId, enActionType.User, searchFields, false, out errorTos); AddDebugItem(new DebugItemVariableParams(searchFields, "", tmpEntry, executionId), debugItem); } _debugInputs.Add(debugItem); AddResultDebugInputs(ResultsCollection, executionId, compiler); AddDebugInputItem(new DebugItemStaticDataParams(RequireAllFieldsToMatch ? "YES" : "NO", "Require All Fields To Match")); AddDebugInputItem(new DebugItemStaticDataParams(RequireAllTrue ? "YES" : "NO", "Require All Matches To Be True")); } }
void AddResultToDebug(IDataListCompiler compiler, Guid dlId) { int innerCount = 1; foreach (DataSplitDTO dataSplitDto in ResultsCollection) { var outputVariable = ResultsCollection[innerCount - 1].OutputVariable; if (outputVariable.Contains("().")) { outputVariable = outputVariable.Remove(outputVariable.IndexOf(".", StringComparison.Ordinal)); outputVariable = outputVariable.Replace("()", "(*)") + "]]"; } ErrorResultTO errors; IBinaryDataListEntry binaryDataListEntry = compiler.Evaluate(dlId, enActionType.User, outputVariable, false, out errors); string expression = dataSplitDto.OutputVariable; if (expression.Contains("().")) { expression = expression.Replace("().", "(*)."); } AddDebugOutputItemFromEntry(expression, binaryDataListEntry, innerCount, dlId); innerCount++; } }
//MO - Changed : new ctor that accepts the new arguments public ForEachBootstrapTOOld(enForEachType forEachType, string from, string to, string csvNumbers, string numberOfExecutes, string recordsetName, Guid dlID, IDataListCompiler compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); ForEachType = forEachType; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IndexIterator localIndexIterator; IndexList indexList; switch (forEachType) { case enForEachType.InRecordset: IBinaryDataListEntry recordset = compiler.Evaluate(dlID, enActionType.User, recordsetName, false, out errors); if (recordset == null || !recordset.IsRecordset) { errors.AddError("When selecting a recordset only valid recordsets can be used"); break; } var isEmpty = recordset.IsEmpty(); if (isEmpty) { indexList = new IndexList(new HashSet <int> { 1 }, 0); localIndexIterator = new IndexIterator(new HashSet <int> { 1 }, 0); } else { indexList = new IndexList(new HashSet <int>(), 0) { MinValue = 1, MaxValue = recordset.FetchLastRecordsetIndex() }; localIndexIterator = new IndexIterator(new HashSet <int>(), 0); } localIndexIterator.IndexList = indexList; IndexIterator = localIndexIterator; break; case enForEachType.InRange: if (string.IsNullOrWhiteSpace(from)) { errors.AddError("The from field can not be left empty."); break; } if (string.IsNullOrWhiteSpace(to)) { errors.AddError("The to field can not be left empty."); break; } if (from.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the From field."); break; } var fromItr = CreateDataListEvaluateIterator(from, dlID, compiler, colItr, errors); colItr.AddIterator(fromItr); int intFrom; if (!int.TryParse(colItr.FetchNextRow(fromItr).TheValue, out intFrom) || intFrom < 1) { errors.AddError("From range must be a whole number from 1 onwards."); break; } if (to.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the To field."); break; } var toItr = CreateDataListEvaluateIterator(to, dlID, compiler, colItr, errors); colItr.AddIterator(toItr); int intTo; if (!int.TryParse(colItr.FetchNextRow(toItr).TheValue, out intTo) || intTo < 1) { errors.AddError("To range must be a whole number from 1 onwards."); break; } if (intFrom > intTo) { indexList = new IndexList(new HashSet <int>(), 0) { MinValue = intFrom, MaxValue = intTo }; ReverseIndexIterator revIdxItr = new ReverseIndexIterator(new HashSet <int>(), 0) { IndexList = indexList }; IndexIterator = revIdxItr; } else { indexList = new IndexList(new HashSet <int>(), 0) { MinValue = intFrom, MaxValue = intTo }; localIndexIterator = new IndexIterator(new HashSet <int>(), 0) { IndexList = indexList }; IndexIterator = localIndexIterator; } break; case enForEachType.InCSV: var csvIndexedsItr = CreateDataListEvaluateIterator(csvNumbers, dlID, compiler, colItr, errors); colItr.AddIterator(csvIndexedsItr); ErrorResultTO allErrors; List <int> listOfIndexes = SplitOutCsvIndexes(colItr.FetchNextRow(csvIndexedsItr).TheValue, out allErrors); if (allErrors.HasErrors()) { errors.MergeErrors(allErrors); break; } ListIndexIterator listLocalIndexIterator = new ListIndexIterator(listOfIndexes); ListOfIndex listOfIndex = new ListOfIndex(listOfIndexes); listLocalIndexIterator.IndexList = listOfIndex; IndexIterator = listLocalIndexIterator; break; default: if (numberOfExecutes != null && numberOfExecutes.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the Numbers field."); break; } int intExNum; var numOfExItr = CreateDataListEvaluateIterator(numberOfExecutes, dlID, compiler, colItr, errors); colItr.AddIterator(numOfExItr); if (!int.TryParse(colItr.FetchNextRow(numOfExItr).TheValue, out intExNum)) { errors.AddError("Number of executes must be a whole number from 1 onwards."); } IndexIterator = new IndexIterator(new HashSet <int>(), intExNum); break; } }
//MO - Changed : new ctor that accepts the new arguments public ForEachBootstrapTOOld(enForEachType forEachType, string from, string to, string csvNumbers, string numberOfExecutes, string recordsetName, Guid dlID, IDataListCompiler compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); ForEachType = forEachType; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IndexIterator localIndexIterator; IndexList indexList; switch(forEachType) { case enForEachType.InRecordset: IBinaryDataListEntry recordset = compiler.Evaluate(dlID, enActionType.User, recordsetName, false, out errors); if(recordset == null || !recordset.IsRecordset) { errors.AddError("When selecting a recordset only valid recordsets can be used"); break; } var isEmpty = recordset.IsEmpty(); if(isEmpty) { indexList = new IndexList(new HashSet<int> { 1 }, 0); localIndexIterator = new IndexIterator(new HashSet<int> { 1 }, 0); } else { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = 1, MaxValue = recordset.FetchLastRecordsetIndex() }; localIndexIterator = new IndexIterator(new HashSet<int>(), 0); } localIndexIterator.IndexList = indexList; IndexIterator = localIndexIterator; break; case enForEachType.InRange: if(string.IsNullOrWhiteSpace(from)) { errors.AddError("The from field can not be left empty."); break; } if(string.IsNullOrWhiteSpace(to)) { errors.AddError("The to field can not be left empty."); break; } if(from.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the From field."); break; } var fromItr = CreateDataListEvaluateIterator(from, dlID, compiler, colItr, errors); colItr.AddIterator(fromItr); int intFrom; if(!int.TryParse(colItr.FetchNextRow(fromItr).TheValue, out intFrom) || intFrom < 1) { errors.AddError("From range must be a whole number from 1 onwards."); break; } if(to.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the To field."); break; } var toItr = CreateDataListEvaluateIterator(to, dlID, compiler, colItr, errors); colItr.AddIterator(toItr); int intTo; if(!int.TryParse(colItr.FetchNextRow(toItr).TheValue, out intTo) || intTo < 1) { errors.AddError("To range must be a whole number from 1 onwards."); break; } if(intFrom > intTo) { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = intFrom, MaxValue = intTo }; ReverseIndexIterator revIdxItr = new ReverseIndexIterator(new HashSet<int>(), 0) { IndexList = indexList }; IndexIterator = revIdxItr; } else { indexList = new IndexList(new HashSet<int>(), 0) { MinValue = intFrom, MaxValue = intTo }; localIndexIterator = new IndexIterator(new HashSet<int>(), 0) { IndexList = indexList }; IndexIterator = localIndexIterator; } break; case enForEachType.InCSV: var csvIndexedsItr = CreateDataListEvaluateIterator(csvNumbers, dlID, compiler, colItr, errors); colItr.AddIterator(csvIndexedsItr); ErrorResultTO allErrors; List<int> listOfIndexes = SplitOutCsvIndexes(colItr.FetchNextRow(csvIndexedsItr).TheValue, out allErrors); if(allErrors.HasErrors()) { errors.MergeErrors(allErrors); break; } ListIndexIterator listLocalIndexIterator = new ListIndexIterator(listOfIndexes); ListOfIndex listOfIndex = new ListOfIndex(listOfIndexes); listLocalIndexIterator.IndexList = listOfIndex; IndexIterator = listLocalIndexIterator; break; default: if(numberOfExecutes != null && numberOfExecutes.Contains("(*)")) { errors.AddError("The Star notation is not accepted in the Numbers field."); break; } int intExNum; var numOfExItr = CreateDataListEvaluateIterator(numberOfExecutes, dlID, compiler, colItr, errors); colItr.AddIterator(numOfExItr); if(!int.TryParse(colItr.FetchNextRow(numOfExItr).TheValue, out intExNum)) { errors.AddError("Number of executes must be a whole number from 1 onwards."); } IndexIterator = new IndexIterator(new HashSet<int>(), intExNum); break; } }
protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context, out ErrorResultTO allErrors) { IsNotCertVerifiable = true; allErrors = new ErrorResultTO(); IList <OutputTO> outputs = new List <OutputTO>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid executionId = dataObject.DataListID; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); //get all the possible paths for all the string variables IBinaryDataListEntry inputPathEntry = compiler.Evaluate(executionId, enActionType.User, InputPath, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator inputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputPathEntry); colItr.AddIterator(inputItr); IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry); colItr.AddIterator(unameItr); IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry); colItr.AddIterator(passItr); if (dataObject.IsDebugMode()) { AddDebugInputItem(InputPath, "Input Path", inputPathEntry, executionId); AddDebugInputItem(new DebugItemStaticDataParams(GetReadType().GetDescription(), "Read")); AddDebugInputItemUserNamePassword(executionId, usernameEntry); } while (colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); IActivityIOPath ioPath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(inputItr).TheValue, colItr.FetchNextRow(unameItr).TheValue, colItr.FetchNextRow(passItr).TheValue, true); 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); }
IDev2DataListEvaluateIterator CreateDataListEvaluateIterator(string expression, Guid executionId, IDataListCompiler compiler, IDev2IteratorCollection iteratorCollection, ErrorResultTO allErrors) { ErrorResultTO errors; IBinaryDataListEntry expressionEntry = compiler.Evaluate(executionId, enActionType.User, expression, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator expressionIterator = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionEntry); iteratorCollection.AddIterator(expressionIterator); return expressionIterator; }
/// <summary> /// Executes the logic of the activity and calls the backend code to do the work /// Also responsible for adding the results to the data list /// </summary> /// <param name="context"></param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false); toUpsert.IsDebug = dataObject.IsDebugMode(); ErrorResultTO errors; ErrorResultTO allErrors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry expressionsEntryFind = compiler.Evaluate(executionId, enActionType.User, Find, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itrFind = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntryFind); iteratorCollection.AddIterator(itrFind); IBinaryDataListEntry expressionsEntryReplaceWith = compiler.Evaluate(executionId, enActionType.User, ReplaceWith, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itrReplace = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntryReplaceWith); iteratorCollection.AddIterator(itrReplace); int replacementCount = 0; int replacementTotal = 0; InitializeDebug(dataObject); try { IList <string> toSearch = FieldsToSearch.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in toSearch) { if (dataObject.IsDebugMode()) { IBinaryDataListEntry inFieldsEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors); AddDebugInputItem(new DebugItemVariableParams(s, "In Field(s)", inFieldsEntry, executionId)); } } var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { while (iteratorCollection.HasMoreData()) { // now process each field for entire evaluated Where expression.... var findValue = iteratorCollection.FetchNextRow(itrFind).TheValue; var replaceWithValue = iteratorCollection.FetchNextRow(itrReplace).TheValue; foreach (string s in toSearch) { if (!DataListUtil.IsEvaluated(s)) { allErrors.AddError("Please insert only variables into Fields To Search"); return; } if (!string.IsNullOrEmpty(findValue)) { IBinaryDataListEntry entryToReplaceIn; toUpsert = replaceOperation.Replace(executionId, s.Trim(), findValue, replaceWithValue, CaseMatch, toUpsert, out errors, out replacementCount, out entryToReplaceIn); } replacementTotal += replacementCount; allErrors.MergeErrors(errors); } } } if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(Find, "Find", expressionsEntryFind, executionId)); AddDebugInputItem(new DebugItemVariableParams(ReplaceWith, "Replace With", expressionsEntryReplaceWith, executionId)); } toUpsert.Add(Result, replacementTotal.ToString(CultureInfo.InvariantCulture)); // now push the result to the server compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } // ReSharper disable EmptyGeneralCatchClause catch (Exception ex) { Dev2Logger.Log.Error("DSFReplace", ex); allErrors.AddError(ex.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfReplaceActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
// ReSharper restore RedundantOverridenMember protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2MergeOperations mergeOperations = new Dev2MergeOperations(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errorResultTo = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { CleanArguments(MergeCollection); if (MergeCollection.Count <= 0) { return; } IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); allErrors.MergeErrors(errorResultTo); Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >(); #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data int dictionaryKey = 0; foreach (DataMergeDTO row in MergeCollection) { IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); var fieldName = row.InputVariable; var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName); var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString(); if (!string.IsNullOrEmpty(datalist)) { foreach (var region in splitIntoRegions) { var r = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region; var isValidExpr = new IsValidExpressionRule(() => r, datalist) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { row.InputVariable = ""; errorResultTo.AddError(errorInfo.Message); } allErrors.MergeErrors(errorResultTo); } } allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem); AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem); //Old workflows don't have this set. if (row.Alignment == null) { row.Alignment = string.Empty; } AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem); _debugInputs.Add(debugItem); } IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry); IDev2DataListEvaluateIterator atItr = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry); IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry); iteratorCollection.AddIterator(itr); iteratorCollection.AddIterator(atItr); iteratorCollection.AddIterator(padItr); listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> { itr, atItr, padItr }); dictionaryKey++; } #endregion #region Iterate and Merge Data if (!allErrors.HasErrors()) { while (iteratorCollection.HasMoreData()) { int pos = 0; foreach (var iterator in listOfIterators) { var val = iteratorCollection.FetchNextRow(iterator.Value[0]); var at = iteratorCollection.FetchNextRow(iterator.Value[1]); var pad = iteratorCollection.FetchNextRow(iterator.Value[2]); if (val != null) { if (at != null) { if (pad != null) { if (MergeCollection[pos].MergeType == "Index") { if (string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } int atValue; if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0) { allErrors.AddError("The 'Using' value must be a real number."); } if (pad.TheValue.Length > 1) { allErrors.AddError("'Padding' must be a single character"); } } else { if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } } mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment); pos++; } } } } } if (!allErrors.HasErrors()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "")); } else { var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(Result, mergeOperations.MergeData.ToString()); toUpsert.FlushIterationFrame(); compiler.Upsert(executionId, toUpsert, out errorResultTo); allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } } } } } #endregion Iterate and Merge Data } catch (Exception e) { Dev2Logger.Log.Error("DSFDataMerge", e); allErrors.AddError(e.Message); } finally { #region Handle Errors if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfDataMergeActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } #endregion } }
// ReSharper restore RedundantOverridenMember /// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); _indexCounter = 0; IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false); InitializeDebug(dataObject); try { CleanArgs(); toUpsert.IsDebug = dataObject.IsDebugMode(); foreach (var item in ConvertCollection) { try { _indexCounter++; // Travis.Frisinger - This needs to be in the ViewModel not here ;) if (item.ToExpression == string.Empty) { item.ToExpression = item.FromExpression; } IsSingleValueRule.ApplyIsSingleValueRule(item.FromExpression, allErrors); var fieldName = item.FromExpression; fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName; var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors); if (!datalist.IsNullOrEmpty()) { var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist.ToString()) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { item.FromExpression = ""; errors.AddError(errorInfo.Message); } allErrors.MergeErrors(errors); } IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.FromExpression, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(item.FromExpression, tmp, executionId, item.FromType, item.ToType); } allErrors.MergeErrors(errors); if (tmp != null) { IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp); IBaseConverter from = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType))); IBaseConverter to = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType))); IBaseConversionBroker broker = _fac.CreateBroker(from, to); // process result information while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> cols = itr.FetchNextRowData(); foreach (IBinaryDataListItem c in cols) { // set up live flushing iterator details if (c.IsDeferredRead) { if (toUpsert != null) { toUpsert.HasLiveFlushing = true; toUpsert.LiveFlushingLocation = executionId; } } int indexToUpsertTo = c.ItemCollectionIndex; string val = string.IsNullOrEmpty(c.TheValue) ? "" : broker.Convert(c.TheValue); string expression = item.ToExpression; if (DataListUtil.IsValueRecordset(item.ToExpression) && DataListUtil.GetRecordsetIndexType(item.ToExpression) == enRecordsetIndexType.Star) { expression = item.ToExpression.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); } toUpsert.Add(expression, val); if (toUpsert != null && toUpsert.HasLiveFlushing) { toUpsert.FlushIterationFrame(); toUpsert = null; } } } } } catch (Exception e) { Dev2Logger.Log.Error("DSFBaseConvert", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { toUpsert.Add(item.ToExpression, null); } } } if (toUpsert != null && toUpsert.HasLiveFlushing) { try { toUpsert.FlushIterationFrame(); } catch (Exception e) { Dev2Logger.Log.Error("DSFBaseConvert", e); allErrors.AddError(e.Message); } } else { compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); } if (!allErrors.HasErrors() && toUpsert != null) { var outIndex = 1; foreach (var debugOutputTo in toUpsert.DebugOutputs) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem); _debugOutputs.Add(debugItem); outIndex++; } } } catch (Exception e) { Dev2Logger.Log.Error("DSFBaseConvert", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfBaseConvertActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
private IBinaryDataListEntry EvaluateForSwitch(string payload, Guid dlId, out ErrorResultTO errors) { IBinaryDataListEntry tmp = Compiler.Evaluate(dlId, enActionType.User, payload, false, out errors); return(tmp); }
protected override void OnExecute(NativeActivityContext context) { _debugOutputs.Clear(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder(); _isDebugMode = dataObject.IsDebugMode(); toUpsert.IsDebug = _isDebugMode; toUpsert.ResourceID = dataObject.ResourceID; ErrorResultTO errors = new ErrorResultTO(); ErrorResultTO allErrors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); XPathParser parser = new XPathParser(); int i = 0; InitializeDebug(dataObject); try { if (!errors.HasErrors()) { IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, SourceString, false, out errors); if (_isDebugMode) { AddSourceStringDebugInputItem(SourceString, expressionsEntry, executionId); AddResultDebugInputs(ResultsCollection, executionId, compiler, out errors); allErrors.MergeErrors(errors); } if (!allErrors.HasErrors()) { IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> cols = itr.FetchNextRowData(); foreach (IBinaryDataListItem c in cols) { for (i = 0; i < ResultsCollection.Count; i++) { if (!string.IsNullOrEmpty(ResultsCollection[i].OutputVariable)) { IBinaryDataListEntry xpathEntry = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].XPath, false, out errors); IDev2DataListEvaluateIterator xpathItr = Dev2ValueObjectFactory.CreateEvaluateIterator(xpathEntry); while (xpathItr.HasMoreRecords()) { IList <IBinaryDataListItem> xpathCols = xpathItr.FetchNextRowData(); foreach (IBinaryDataListItem xPathCol in xpathCols) { try { List <string> eval = parser.ExecuteXPath(c.TheValue, xPathCol.TheValue).ToList(); //2013.06.03: Ashley Lewis for bug 9498 - handle line breaks in multi assign string[] openParts = Regex.Split(ResultsCollection[i].OutputVariable, @"\[\["); string[] closeParts = Regex.Split(ResultsCollection[i].OutputVariable, @"\]\]"); if (openParts.Count() == closeParts.Count() && openParts.Count() > 2 && closeParts.Count() > 2) { foreach (var newFieldName in openParts) { if (!string.IsNullOrEmpty(newFieldName)) { string cleanFieldName; if (newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2 < newFieldName.Length) { cleanFieldName = "[[" + newFieldName.Remove(newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2); } else { cleanFieldName = "[[" + newFieldName; } toUpsert.Add(cleanFieldName, eval); } } } else { toUpsert.Add(ResultsCollection[i].OutputVariable, eval); } } catch (Exception) { toUpsert.Add(ResultsCollection[i].OutputVariable, null); } } } } } compiler.Upsert(executionId, toUpsert, out errors); } allErrors.MergeErrors(errors); } } if (_isDebugMode && !allErrors.HasErrors()) { var innerCount = 1; foreach (var debugOutputTo in toUpsert.DebugOutputs) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugItemVariableParams(debugOutputTo), itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } toUpsert.DebugOutputs.Clear(); } } } catch (Exception ex) { allErrors.AddError(ex.Message); } finally { // Handle Errors var actualIndex = i - 1; var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfXPathActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, ResultsCollection[actualIndex].OutputVariable, (string)null, out errors); } if (_isDebugMode) { if (hasErrors) { if (_isDebugMode) { ResultsCollection[actualIndex].XPath = ""; var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (actualIndex + 1).ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugOutputParams(ResultsCollection[actualIndex].OutputVariable, "", executionId, actualIndex + 1), itemToAdd); _debugOutputs.Add(itemToAdd); } } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
// ReSharper restore RedundantOverridenMember /// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ReplaceStarWithFixedIndex = true; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); try { CleanArgs(); ICaseConverter converter = CaseConverterFactory.CreateCaseConverter(); allErrors.MergeErrors(errors); int index = 1; int outIndex = 0; foreach (ICaseConvertTO item in ConvertCollection) { outIndex++; IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors); allErrors.MergeErrors(errors); ValidateVariable(item.Result, compiler, dataObject, out errors); allErrors.MergeErrors(errors); IsSingleValueRule.ApplyIsSingleValueRule(item.ExpressionToConvert, allErrors); if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", index.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(item.StringToConvert, "Convert", tmp, executionId), debugItem); AddDebugItem(new DebugItemStaticDataParams(item.ConvertType, "To"), debugItem); _debugInputs.Add(debugItem); index++; } if (tmp != null) { IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp); while (itr.HasMoreRecords()) { foreach (IBinaryDataListItem itm in itr.FetchNextRowData()) { try { IBinaryDataListItem res = converter.TryConvert(item.ConvertType, itm); string expression = item.Result; // 27.08.2013 // NOTE : The result must remain [ as this is how the fliping studio generates the result when using (*) notation // There is a proper bug in to fix this issue, but since the studio is spaghetti I will leave this to the experts ;) // This is a tmp fix to the issue if (expression == "[" || DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star) { expression = DataListUtil.AddBracketsToValueIfNotExist(res.DisplayValue); } //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result IsSingleValueRule rule = new IsSingleValueRule(() => expression); var singleresError = rule.Check(); if (singleresError != null) { allErrors.AddError(singleresError.Message); } else { toUpsert.Add(expression, res.TheValue); // Upsert the entire payload } allErrors.MergeErrors(errors); } catch (Exception e) { allErrors.AddError(e.Message); toUpsert.Add(item.Result, null); } } } compiler.Upsert(executionId, toUpsert, out errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem); _debugOutputs.Add(debugItem); } toUpsert.DebugOutputs.Clear(); } } } } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfCaseConvertActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { int outIndex = 1; foreach (ICaseConvertTO item in ConvertCollection) { IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors); var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(item.Result, "", tmp, executionId), debugItem); _debugOutputs.Add(debugItem); outIndex++; } } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
/// <summary> /// When overridden runs the activity's execution logic /// </summary> /// <param name="context">The context to be used.</param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errorResultTo = new ErrorResultTO(); Guid executionId = dlId; allErrors.MergeErrors(errorResultTo); try { if (!errorResultTo.HasErrors()) { IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); if (allErrors.HasErrors()) { return; } IBinaryDataListEntry scriptEntry = compiler.Evaluate(executionId, enActionType.User, Script, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); if (allErrors.HasErrors()) { return; } if (dataObject.IsDebugMode()) { AddDebugInputItem(Script, scriptEntry, executionId); } int iterationCounter = 0; while (colItr.HasMoreData()) { dynamic value = null; //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result foreach (var region in DataListCleaningUtils.SplitIntoRegions(Result)) { toUpsert.Add(region, null); toUpsert.FlushIterationFrame(); if (dataObject.IsDebugMode()) { // ReSharper disable ExpressionIsAlwaysNull AddDebugOutputItem(new DebugOutputParams(region, value, executionId, iterationCounter)); // ReSharper restore ExpressionIsAlwaysNull } } iterationCounter++; } compiler.Upsert(executionId, toUpsert, out errorResultTo); allErrors.MergeErrors(errorResultTo); } } catch (Exception e) { allErrors.AddError(e.GetType() == typeof(NullReferenceException) ? "There was an error when returning a value from the javascript, remember to use the 'Return' keyword when returning the result" : e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfScriptingJavaScriptActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
protected override IList <OutputTO> ExecuteConcreteAction(NativeActivityContext context, out ErrorResultTO allErrors) { IList <OutputTO> outputs = new List <OutputTO>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = dataObject.DataListID; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); //get all the possible paths for all the string variables IBinaryDataListEntry outputPathEntry = compiler.Evaluate(executionId, enActionType.User, OutputPath, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator outputItr = Dev2ValueObjectFactory.CreateEvaluateIterator(outputPathEntry); colItr.AddIterator(outputItr); IBinaryDataListEntry usernameEntry = compiler.Evaluate(executionId, enActionType.User, Username, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator unameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(usernameEntry); colItr.AddIterator(unameItr); IBinaryDataListEntry passwordEntry = compiler.Evaluate(executionId, enActionType.User, Password, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator passItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry); colItr.AddIterator(passItr); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(OutputPath, "File or Folder", outputPathEntry, executionId)); AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite")); AddDebugInputItemUserNamePassword(executionId, usernameEntry); } while (colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); Dev2CRUDOperationTO opTo = new Dev2CRUDOperationTO(Overwrite); try { IActivityIOPath dst = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(outputItr).TheValue, colItr.FetchNextRow(unameItr).TheValue, colItr.FetchNextRow(passItr).TheValue, true); 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, (string)null)); allErrors.AddError(e.Message); break; } } return(outputs); }
public IDev2DataListUpsertPayloadBuilder <string> Replace(Guid exIdx, string expression, string oldString, string newString, bool caseMatch, IDev2DataListUpsertPayloadBuilder <string> payloadBuilder, out ErrorResultTO errors, out int ReplaceCount, out IBinaryDataListEntry entryToReplaceIn) { ReplaceCount = 0; oldString = oldString.Replace("\\", "\\\\"); // ReSharper disable RedundantAssignment ErrorResultTO allErrors = new ErrorResultTO(); errors = new ErrorResultTO(); // ReSharper restore RedundantAssignment IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); entryToReplaceIn = compiler.Evaluate(exIdx, enActionType.User, expression, false, out errors); allErrors.MergeErrors(errors); if (entryToReplaceIn != null) { RegexOptions regexOptions; if (caseMatch) { regexOptions = NoneCompiled; } else { regexOptions = IgnoreCaseCompiled; } //Massimo Guerrera - Added the Regex.Escape to escape certain characters - Bug 9937 Regex regex = new Regex(Regex.Escape(oldString), regexOptions); IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(entryToReplaceIn); while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> rowList = itr.FetchNextRowData(); if (rowList != null) { foreach (IBinaryDataListItem binaryDataListItem in rowList) { int tmpCount = ReplaceCount; string tmpVal = binaryDataListItem.TheValue; if (tmpVal.Contains("\\") && oldString.Contains("\\")) { tmpVal = tmpVal.Replace("\\", "\\\\"); } ReplaceCount += regex.Matches(tmpVal).Count; if (ReplaceCount > tmpCount) { if (entryToReplaceIn.IsRecordset) { string recsetDisplayValue = DataListUtil.CreateRecordsetDisplayValue(entryToReplaceIn.Namespace, binaryDataListItem.FieldName, binaryDataListItem.ItemCollectionIndex.ToString()); expression = string.Concat("[[", recsetDisplayValue, "]]"); } var replaceValue = regex.Replace(tmpVal, newString); payloadBuilder.Add(expression, replaceValue); } } } } payloadBuilder.FlushIterationFrame(); } else { allErrors.AddError("DataList entry is null."); } errors = allErrors; return(payloadBuilder); }