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); }
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); }
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); }
public ForEachBootstrapTOOld(enForEachExecutionType typeOf, int maxExe, IBinaryDataListEntry data) { ExeType = typeOf; MaxExecutions = maxExe; if (data != null) { DataIterator = Dev2ValueObjectFactory.CreateEvaluateIterator(data); } else { DataIterator = null; } }
public void PerformLogExecution(string logUri) { var connection = GetConnection(DataObject.EnvironmentID); var dataListCompiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var expressionsEntry = dataListCompiler.Evaluate(DataObject.DataListID, enActionType.User, logUri, false, out errors); var itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); while (itr.HasMoreRecords()) { var cols = itr.FetchNextRowData(); foreach (var c in cols) { var buildGetWebRequest = BuildGetWebRequest(c.TheValue, connection.AuthenticationType, connection.UserName, connection.Password); if (buildGetWebRequest == null) { throw new Exception("Invalid Url to execute for logging"); } ExecuteWebRequestAsync(buildGetWebRequest); } } }
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); }
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); }
// 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); } } }
protected void ExecuteImpl(IDataListCompiler compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); #region Create OutputFormatter // ReSharper disable RedundantAssignment IOutputFormatter outputFormatter = null; // ReSharper restore RedundantAssignment try { outputFormatter = GetOutputFormatter(Service); } catch (Exception) { if (HandlesOutputFormatting) { errors.AddError(string.Format("Output format in service action {0} is invalid. Please edit and remap.", Service.ResourceName)); return; } } if (HandlesOutputFormatting && outputFormatter == null) { errors.AddError(string.Format("Output format in service action {0} is invalid.", Service.ResourceName)); return; } #endregion try { ErrorResultTO invokeErrors; var itrs = new List <IDev2DataListEvaluateIterator>(5); var itrCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); ServiceMethod method = Service.Method; List <MethodParameter> inputs = method.Parameters; if (inputs.Count == 0) { ExecuteServiceAndMergeResultIntoDataList(outputFormatter, compiler, itrCollection, itrs, out invokeErrors); errors.MergeErrors(invokeErrors); } else { #region Build iterators for each ServiceActionInput foreach (var sai in inputs) { var val = sai.Name; var toInject = "NULL"; if (val != null) { toInject = DataListUtil.AddBracketsToValueIfNotExist(sai.Name); } else if (!sai.EmptyToNull) { toInject = sai.DefaultValue; } var expressionEntry = compiler.Evaluate(DataObj.DataListID, enActionType.User, toInject, false, out invokeErrors); errors.MergeErrors(invokeErrors); var expressionIterator = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionEntry); itrCollection.AddIterator(expressionIterator); itrs.Add(expressionIterator); } #endregion while (itrCollection.HasMoreData()) { ExecuteServiceAndMergeResultIntoDataList(outputFormatter, compiler, itrCollection, itrs, out invokeErrors); errors.MergeErrors(invokeErrors); } } } finally { var disposable = Service as IDisposable; if (disposable != null) { disposable.Dispose(); } // ensure errors bubble up ;) errors.MergeErrors(ErrorResult); } }
// 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); } } }
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(); IDev2IndexFinder indexFinder = new Dev2IndexFinder(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder(); IDev2DataListUpsertPayloadBuilder <string> toUpsertScalar = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsertScalar.IsDebug = dataObject.IsDebugMode(); try { IDev2IteratorCollection outerIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2IteratorCollection innerIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); allErrors.MergeErrors(errors); IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, Characters, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itrChar = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); outerIteratorCollection.AddIterator(itrChar); #region Iterate and Find Index expressionsEntry = compiler.Evaluate(executionId, enActionType.User, InField, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(InField, "In Field", expressionsEntry, executionId)); AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index")); AddDebugInputItem(new DebugItemVariableParams(Characters, "Characters", itrChar.FetchEntry(), executionId)); AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction")); } var completeResultList = new List <string>(); while (outerIteratorCollection.HasMoreData()) { allErrors.MergeErrors(errors); errors.ClearErrors(); IDev2DataListEvaluateIterator itrInField = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); innerIteratorCollection.AddIterator(itrInField); string chars = outerIteratorCollection.FetchNextRow(itrChar).TheValue; while (innerIteratorCollection.HasMoreData()) { if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters)) { var val = innerIteratorCollection.FetchNextRow(itrInField); if (val != null) { IEnumerable <int> returedData = indexFinder.FindIndex(val.TheValue, Index, chars, Direction, MatchCase, StartIndex); completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList()); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result } } } } var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { var rsType = DataListUtil.GetRecordsetIndexType(Result); if (rsType == enRecordsetIndexType.Numeric) { toUpsertScalar.Add(Result, string.Join(",", completeResultList)); compiler.Upsert(executionId, toUpsertScalar, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { foreach (var debugOutputTo in toUpsertScalar.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } toUpsert.DebugOutputs.Clear(); } } else { toUpsert.Add(Result, completeResultList); compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } toUpsert.DebugOutputs.Clear(); } } } #endregion } catch (Exception e) { Dev2Logger.Log.Error("DSFFindActivity", e); allErrors.AddError(e.Message); } finally { #region Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfIndexActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } #endregion if (dataObject.IsDebugMode()) { if (hasErrors) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } 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>(); _indexCounter = 1; IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; _datalistString = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors).ToString(); InitializeDebug(dataObject); try { var sourceString = SourceString ?? ""; IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dlId, enActionType.User, sourceString, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(sourceString, "String to Split", expressionsEntry, dlId)); AddDebugInputItem(new DebugItemStaticDataParams(ReverseOrder ? "Backward" : "Forward", "Process Direction")); AddDebugInputItem(new DebugItemStaticDataParams(SkipBlankRows ? "Yes" : "No", "Skip blank rows")); } CleanArguments(ResultsCollection); ResultsCollection.ToList().ForEach(a => IsSingleValueRule.ApplyIsSingleValueRule(a.OutputVariable, allErrors)); if (ResultsCollection.Count > 0) { if (dataObject.IsDebugMode()) { AddDebug(ResultsCollection, compiler, dlId); } CheckIndex(sourceString); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); bool singleInnerIteration = ArePureScalarTargets(ResultsCollection); bool exit = false; while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> cols = itr.FetchNextRowData(); foreach (IBinaryDataListItem c in cols) { // set up live flushing iterator details toUpsert.HasLiveFlushing = true; toUpsert.LiveFlushingLocation = dlId; #pragma warning disable 219 int opCnt = 0; #pragma warning restore 219 if (!string.IsNullOrEmpty(c.TheValue)) { string val = c.TheValue; var blankRows = new List <int>(); if (SkipBlankRows) { var strings = val.Split(new[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); var newSourceString = string.Join(Environment.NewLine, strings); val = newSourceString; } else { var strings = val.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int blankRow = 0; blankRow < strings.Length; blankRow++) { if (String.IsNullOrEmpty(strings[blankRow])) { blankRows.Add(blankRow); } } } IDev2Tokenizer tokenizer = CreateSplitPattern(ref val, ResultsCollection, compiler, dlId, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { if (tokenizer != null) { int pos = 0; int end = (ResultsCollection.Count - 1); // track used tokens so we can adjust flushing ;) HashSet <string> usedTokens = new HashSet <string>(); while (tokenizer.HasMoreOps() && !exit) { string tmp = tokenizer.NextToken(); if (blankRows.Contains(opCnt) && blankRows.Count != 0) { tmp = tmp.Replace(Environment.NewLine, ""); while (pos != end + 1) { UpdateOutputVariableWithValue(pos, usedTokens, toUpsert, ""); pos++; } pos = CompletedRow(usedTokens, toUpsert, singleInnerIteration, ref opCnt, ref exit); } UpdateOutputVariableWithValue(pos, usedTokens, toUpsert, tmp); // Per pass if (pos == end) { //row has been processed pos = CompletedRow(usedTokens, toUpsert, singleInnerIteration, ref opCnt, ref exit); } else { pos++; } } // flush the final frame ;) toUpsert.FlushIterationFrame(); toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); } } } } } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddResultToDebug(compiler, dlId); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFDataSplit", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDataSplitActivity", allErrors); compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddResultToDebug(compiler, dlId); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
//MO - Changed : new ctor that accepts the new arguments public ForEachBootstrapTO(enForEachType forEachType, string from, string to, string csvNumbers, string numberOfExecutes, string recordsetName, IExecutionEnvironment compiler, out ErrorResultTO errors) { errors = new ErrorResultTO(); ForEachType = forEachType; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IIndexIterator localIndexIterator; IndexList indexList; switch (forEachType) { case enForEachType.InRecordset: var records = compiler.EvalRecordSetIndexes(recordsetName); if (!compiler.HasRecordSet(recordsetName)) { errors.AddError("When selecting a recordset only valid recordsets can be used"); break; } var isEmpty = !records.Any(); if (isEmpty) { localIndexIterator = new IndexListIndexIterator(records); } else { localIndexIterator = new IndexListIndexIterator(records); } 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 evalledFrom = Warewolf.Storage.ExecutionEnvironment.WarewolfEvalResultToString(compiler.Eval(@from)); int intFrom; if (!int.TryParse(evalledFrom, 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 evalledTo = Warewolf.Storage.ExecutionEnvironment.WarewolfEvalResultToString(compiler.Eval(@to)); int intTo; if (!int.TryParse(evalledTo, 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 = Warewolf.Storage.ExecutionEnvironment.WarewolfEvalResultToString(compiler.Eval(csvNumbers)); ErrorResultTO allErrors; List <int> listOfIndexes = SplitOutCsvIndexes(csvIndexedsItr, 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 = Warewolf.Storage.ExecutionEnvironment.WarewolfEvalResultToString(compiler.Eval(numberOfExecutes)); if (!int.TryParse(numOfExItr, out intExNum)) { errors.AddError("Number of executes must be a whole number from 1 onwards."); } IndexIterator = new IndexIterator(new HashSet <int>(), intExNum); break; } }
/// <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>(); _nativeActivityContext = context; var dataObject = _nativeActivityContext.GetExtension <IDSFDataObject>(); var compiler = DataListFactory.CreateDataListCompiler(); var dlId = dataObject.DataListID; var allErrors = new ErrorResultTO(); ErrorResultTO errors; var exeToken = _nativeActivityContext.GetExtension <IExecutionToken>(); InitializeDebug(dataObject); try { IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dlId, enActionType.User, CommandFileName, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(CommandFileName, "Command", expressionsEntry, dlId)); } allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); if (!allErrors.HasErrors()) { while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> cols = itr.FetchNextRowData(); foreach (IBinaryDataListItem c in cols) { if (c.IsDeferredRead) { if (toUpsert != null) { toUpsert.HasLiveFlushing = true; toUpsert.LiveFlushingLocation = dlId; } } if (string.IsNullOrEmpty(c.TheValue)) { throw new Exception("Empty script to execute"); } string val = c.TheValue; StreamReader errorReader; StringBuilder outputReader; if (!ExecuteProcess(val, exeToken, out errorReader, out outputReader)) { return; } allErrors.AddError(errorReader.ReadToEnd()); var bytes = Encoding.Default.GetBytes(outputReader.ToString().Trim()); string readValue = Encoding.ASCII.GetString(bytes).Replace("?", " "); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result foreach (var region in DataListCleaningUtils.SplitIntoRegions(CommandResult)) { if (toUpsert != null) { toUpsert.Add(region, readValue); } } errorReader.Close(); if (toUpsert != null && toUpsert.HasLiveFlushing) { try { toUpsert.FlushIterationFrame(); toUpsert = null; } catch (Exception e) { Dev2Logger.Log.Error("DSFExecuteCommandLine", e); allErrors.AddError(e.Message); } } else { compiler.Upsert(dlId, toUpsert, out errors); allErrors.MergeErrors(errors); } } } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { if (toUpsert == null) { return; } foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } } catch (Exception e) { Dev2Logger.Log.Error("DSFCommandLine", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors); compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(dlId, CommandResult, (string)null, out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", CommandResult, "")); } DispatchDebugState(_nativeActivityContext, StateType.Before); DispatchDebugState(_nativeActivityContext, StateType.After); } if (!string.IsNullOrEmpty(_fullPath)) { File.Delete(_fullPath); } } }
/// <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 errors = new ErrorResultTO(); Guid executionId = dlId; allErrors.MergeErrors(errors); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { if (!errors.HasErrors()) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2DataListEvaluateIterator lengthItr = CreateDataListEvaluateIterator(Length, executionId, compiler, colItr, allErrors); IBinaryDataListEntry lengthEntry = compiler.Evaluate(executionId, enActionType.User, Length, false, out errors); IDev2DataListEvaluateIterator fromItr = CreateDataListEvaluateIterator(From, executionId, compiler, colItr, allErrors); IBinaryDataListEntry fromEntry = compiler.Evaluate(executionId, enActionType.User, From, false, out errors); IDev2DataListEvaluateIterator toItr = CreateDataListEvaluateIterator(To, executionId, compiler, colItr, allErrors); IBinaryDataListEntry toEntry = compiler.Evaluate(executionId, enActionType.User, To, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(Length, From, To, fromEntry, toEntry, lengthEntry, executionId, RandomType); } Dev2Random dev2Random = new Dev2Random(); while (colItr.HasMoreData()) { int lengthNum = -1; int fromNum = -1; int toNum = -1; string fromValue = colItr.FetchNextRow(fromItr).TheValue; string toValue = colItr.FetchNextRow(toItr).TheValue; string lengthValue = colItr.FetchNextRow(lengthItr).TheValue; if (RandomType != enRandomType.Guid) { if (RandomType == enRandomType.Numbers) { #region Getting the From fromNum = GetFromValue(fromValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion #region Getting the To toNum = GetToValue(toValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } else { #region Getting the Length lengthNum = GetLengthValue(lengthValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } } string value = dev2Random.GetRandom(RandomType, lengthNum, fromNum, toNum); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(Result, value); toUpsert.FlushIterationFrame(); } } compiler.Upsert(executionId, toUpsert, out errors); if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "Result")); } else { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } allErrors.MergeErrors(errors); } } catch (Exception e) { Dev2Logger.Log.Error("DSFRandomActivity", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfRandomActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } 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; 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 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); IBinaryDataListEntry destinationUsernameEntry = compiler.Evaluate(executionId, enActionType.User, DestinationUsername, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator desunameItr = Dev2ValueObjectFactory.CreateEvaluateIterator(destinationUsernameEntry); ColItr.AddIterator(desunameItr); IBinaryDataListEntry destinationPasswordEntry = compiler.Evaluate(executionId, enActionType.User, DestinationPassword, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator despassItr = Dev2ValueObjectFactory.CreateEvaluateIterator(destinationPasswordEntry); ColItr.AddIterator(despassItr); var iteratorsErrors = new List <ErrorResultTO>(); AddItemsToIterator(executionId, compiler, iteratorsErrors); ErrorResultTO to = allErrors; iteratorsErrors.ForEach(to.MergeErrors); outputs.Add(DataListFactory.CreateOutputTO(Result)); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(InputPath, "Source Path", inputPathEntry, executionId)); AddDebugInputItemUserNamePassword(executionId, usernameEntry); AddDebugInputItem(new DebugItemVariableParams(OutputPath, "Destination Path", outputPathEntry, executionId)); AddDebugInputItemDestinationUsernamePassword(executionId, destinationUsernameEntry, DestinationPassword, DestinationUsername); AddDebugInputItem(new DebugItemStaticDataParams(Overwrite.ToString(), "Overwrite")); AddDebugInputItems(executionId); } while (ColItr.HasMoreData()) { var hasError = false; IActivityIOPath src = null; IActivityIOPath dst = null; try { src = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextRow(inputItr).TheValue, ColItr.FetchNextRow(unameItr).TheValue, ColItr.FetchNextRow(passItr).TheValue, true); } catch (IOException ioException) { allErrors.AddError("Source: " + ioException.Message); hasError = true; } try { dst = ActivityIOFactory.CreatePathFromString(ColItr.FetchNextRow(outputItr).TheValue, ColItr.FetchNextRow(desunameItr).TheValue, ColItr.FetchNextRow(despassItr).TheValue, true); } catch (IOException ioException) { allErrors.AddError("Destination:" + ioException.Message); hasError = true; } if (hasError) { outputs[0].OutputStrings.Add(null); MoveRemainingIterators(); continue; } IActivityIOOperationsEndPoint scrEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(src); IActivityIOOperationsEndPoint dstEndPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(dst); try { IActivityOperationsBroker broker = GetOperationBroker(); var result = ExecuteBroker(broker, scrEndPoint, dstEndPoint); outputs[0].OutputStrings.Add(result); } catch (Exception e) { allErrors.AddError(e.Message); outputs[0].OutputStrings.Add(null); } } 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); }
/// <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 inputPathEntry = compiler.Evaluate(executionId, enActionType.User, OutputPath, 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); IBinaryDataListEntry contentsEntry = compiler.Evaluate(executionId, enActionType.User, FileContents, false, out errors); if (contentsEntry == null) { errors.AddError("Contents could not be evaluated"); } allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator contentItr = Dev2ValueObjectFactory.CreateEvaluateIterator(contentsEntry); colItr.AddIterator(contentItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if (dataObject.IsDebugMode()) { AddDebugInputItem(OutputPath, "Output Path", inputPathEntry, executionId); AddDebugInputItem(new DebugItemStaticDataParams(GetMethod(), "Method")); AddDebugInputItemUserNamePassword(executionId, usernameEntry); AddDebugInputItem(FileContents, "File Contents", contentsEntry, executionId); } while (colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); var writeType = GetCorrectWriteType(); Dev2PutRawOperationTO putTo = ActivityIOFactory.CreatePutRawOperationTO(writeType, TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(colItr.FetchNextRow(contentItr).TheValue)); IActivityIOPath opath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextRow(inputItr).TheValue, colItr.FetchNextRow(unameItr).TheValue, colItr.FetchNextRow(passItr).TheValue, true); 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); }
Dev2DecisionStack ResolveAllRecords(Guid id, Dev2DecisionStack stack, Dev2Decision decision, bool[] effectedCols, out ErrorResultTO errors) { if (effectedCols == null) { throw new ArgumentNullException("effectedCols"); } int stackIndex = stack.TheStack.IndexOf(decision); stack.TheStack.Remove(decision); errors = new ErrorResultTO(); if (effectedCols[0]) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry col1Entry = Compiler.Evaluate(id, enActionType.User, decision.Col1, false, out errors); IDev2DataListEvaluateIterator col1Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col1Entry); colItr.AddIterator(col1Iterator); int reStackIndex = stackIndex; while (colItr.HasMoreData()) { var newDecision = new Dev2Decision { Col1 = colItr.FetchNextRow(col1Iterator).TheValue, Col2 = decision.Col2, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn }; stack.TheStack.Insert(reStackIndex++, newDecision); } } if (effectedCols[1]) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry col2Entry = Compiler.Evaluate(id, enActionType.User, decision.Col2, false, out errors); IDev2DataListEvaluateIterator col2Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col2Entry); colItr.AddIterator(col2Iterator); int reStackIndex = stackIndex; while (colItr.HasMoreData()) { var newDecision = new Dev2Decision { Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = colItr.FetchNextRow(col2Iterator).TheValue, Col3 = decision.Col3, EvaluationFn = decision.EvaluationFn }; if (effectedCols[0]) { // ensure we have the correct indexing ;) if (reStackIndex < stack.TheStack.Count) { stack.TheStack[reStackIndex++] = newDecision; } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } } if (effectedCols[2]) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry col3Entry = Compiler.Evaluate(id, enActionType.User, decision.Col3, false, out errors); IDev2DataListEvaluateIterator col3Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(col3Entry); colItr.AddIterator(col3Iterator); int reStackIndex = stackIndex; while (colItr.HasMoreData()) { var newDecision = new Dev2Decision { Col1 = FetchStackValue(stack, reStackIndex, 1), Col2 = FetchStackValue(stack, reStackIndex, 2), Col3 = colItr.FetchNextRow(col3Iterator).TheValue, EvaluationFn = decision.EvaluationFn }; if (effectedCols[0] || effectedCols[1]) { // ensure we have the correct indexing ;) if (reStackIndex < stack.TheStack.Count) { stack.TheStack[reStackIndex++] = newDecision; } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } else { stack.TheStack.Insert(reStackIndex++, newDecision); } } } return(stack); }
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); }
/// <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>(); _dataObject = dataObject; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); int indexToUpsertTo = 0; IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); InitializeDebug(dataObject); try { var colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry fromAccountEntry = compiler.Evaluate(dlId, enActionType.User, FromAccount ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator fromAccountItr = Dev2ValueObjectFactory.CreateEvaluateIterator(fromAccountEntry); colItr.AddIterator(fromAccountItr); IBinaryDataListEntry passwordEntry = compiler.Evaluate(dlId, enActionType.User, Password, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator passwordItr = Dev2ValueObjectFactory.CreateEvaluateIterator(passwordEntry); colItr.AddIterator(passwordItr); IBinaryDataListEntry toEntry = compiler.Evaluate(dlId, enActionType.User, To, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator toItr = Dev2ValueObjectFactory.CreateEvaluateIterator(toEntry); colItr.AddIterator(toItr); IBinaryDataListEntry ccEntry = compiler.Evaluate(dlId, enActionType.User, Cc ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator ccItr = Dev2ValueObjectFactory.CreateEvaluateIterator(ccEntry); colItr.AddIterator(ccItr); IBinaryDataListEntry bccEntry = compiler.Evaluate(dlId, enActionType.User, Bcc ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator bccItr = Dev2ValueObjectFactory.CreateEvaluateIterator(bccEntry); colItr.AddIterator(bccItr); IBinaryDataListEntry subjectEntry = compiler.Evaluate(dlId, enActionType.User, Subject ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator subjectItr = Dev2ValueObjectFactory.CreateEvaluateIterator(subjectEntry); colItr.AddIterator(subjectItr); IBinaryDataListEntry bodyEntry = compiler.Evaluate(dlId, enActionType.User, Body ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator bodyItr = Dev2ValueObjectFactory.CreateEvaluateIterator(bodyEntry); colItr.AddIterator(bodyItr); IBinaryDataListEntry attachmentsEntry = compiler.Evaluate(dlId, enActionType.User, Attachments ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator attachmentsItr = Dev2ValueObjectFactory.CreateEvaluateIterator(attachmentsEntry); colItr.AddIterator(attachmentsItr); var runtimeSource = ResourceCatalog.Instance.GetResource <EmailSource>(dataObject.WorkspaceID, SelectedEmailSource.ResourceID); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { if (IsDebug) { var fromAccount = FromAccount; if (String.IsNullOrEmpty(fromAccount)) { fromAccount = runtimeSource.UserName; AddDebugInputItem(fromAccount, "From Account"); } else { AddDebugInputItem(new DebugItemVariableParams(FromAccount, "From Account", fromAccountEntry, executionId)); } AddDebugInputItem(new DebugItemVariableParams(To, "To", toEntry, executionId)); AddDebugInputItem(new DebugItemVariableParams(Subject, "Subject", subjectEntry, executionId)); AddDebugInputItem(new DebugItemVariableParams(Body, "Body", bodyEntry, executionId)); } var result = SendEmail(runtimeSource, colItr, fromAccountItr, passwordItr, toItr, ccItr, bccItr, subjectItr, bodyItr, attachmentsItr, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { indexToUpsertTo = UpsertResult(indexToUpsertTo, toUpsert, result); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (IsDebug && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } else { if (IsDebug) { AddDebugInputItem(FromAccount, "From Account"); AddDebugInputItem(To, "To"); AddDebugInputItem(Subject, "Subject"); AddDebugInputItem(Body, "Body"); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFEmail", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { UpsertResult(indexToUpsertTo, toUpsert, null); compiler.Upsert(executionId, toUpsert, out errors); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfSendEmailActivity", allErrors); compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { 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>(); var dataObject = context.GetExtension <IDSFDataObject>(); var compiler = DataListFactory.CreateDataListCompiler(); var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; var errorResultTo = new ErrorResultTO(); var allErrors = new ErrorResultTO(); var executionId = DataListExecutionID.Get(context); DataTable dataTableToInsert = null; bool addExceptionToErrorList = true; InitializeDebug(dataObject); try { IDev2DataListEvaluateIterator batchItr; IDev2DataListEvaluateIterator timeoutItr; var parametersIteratorCollection = BuildParametersIteratorCollection(compiler, executionId, out batchItr, out timeoutItr); SqlBulkCopy sqlBulkCopy = null; var currentOptions = BuildSqlBulkCopyOptions(); var runtimeDatabase = ResourceCatalog.Instance.GetResource <DbSource>(dataObject.WorkspaceID, Database.ResourceID); if (String.IsNullOrEmpty(BatchSize) && String.IsNullOrEmpty(Timeout)) { sqlBulkCopy = new SqlBulkCopy(runtimeDatabase.ConnectionString, currentOptions) { DestinationTableName = TableName }; } else { while (parametersIteratorCollection.HasMoreData()) { sqlBulkCopy = SetupSqlBulkCopy(batchItr, parametersIteratorCollection, timeoutItr, runtimeDatabase, currentOptions); } } if (sqlBulkCopy != null) { // BuiltUsingSingleRecset was very poorly put together it assumes a 1-1 mapping between target and destination columns ?! ;( // And it forced a need for duplicate logic?! dataTableToInsert = BuildDataTableToInsert(); if (InputMappings != null && InputMappings.Count > 0) { var iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); var listOfIterators = GetIteratorsFromInputMappings(compiler, executionId, dataObject, iteratorCollection, out errorResultTo); allErrors.MergeErrors(errorResultTo); // oh no, we have an issue, bubble it out ;) if (allErrors.HasErrors()) { addExceptionToErrorList = false; throw new Exception("Problems with Iterators for SQLBulkInsert"); } // emit options to debug as per acceptance test ;) if (dataObject.IsDebugMode()) { AddBatchSizeAndTimeOutToDebug(compiler, executionId); AddOptionsDebugItems(); } FillDataTableWithDataFromDataList(iteratorCollection, dataTableToInsert, listOfIterators); foreach (var dataColumnMapping in InputMappings) { if (!String.IsNullOrEmpty(dataColumnMapping.InputColumn)) { sqlBulkCopy.ColumnMappings.Add(new SqlBulkCopyColumnMapping(dataColumnMapping.OutputColumn.ColumnName, dataColumnMapping.OutputColumn.ColumnName)); } } } // Pass in wrapper now ;) var wrapper = new SqlBulkCopyWrapper(sqlBulkCopy); SqlBulkInserter.Insert(wrapper, dataTableToInsert); toUpsert.Add(Result, "Success"); compiler.Upsert(executionId, toUpsert, out errorsTo); allErrors.MergeErrors(errorResultTo); if (toUpsert.IsDebug) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } } catch (Exception e) { if (addExceptionToErrorList) { allErrors.AddError(e.Message); } // ReSharper disable InvokeAsExtensionMethod Dev2Logger.Log.Error(this, e); // ReSharper restore InvokeAsExtensionMethod } finally { // Handle Errors if (allErrors.HasErrors()) { if (toUpsert.IsDebug) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } DisplayAndWriteError("DsfSqlBulkInsertActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorsTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (toUpsert.IsDebug) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } if (dataTableToInsert != null) { dataTableToInsert.Dispose(); } } }
// 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 } }
/// <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) { _debugOutputs.Clear(); _debugInputs.Clear(); if (WebRequestInvoker == null) { return; } var dataObject = context.GetExtension <IDSFDataObject>(); var compiler = DataListFactory.CreateDataListCompiler(); var dlId = dataObject.DataListID; var allErrors = new ErrorResultTO(); var executionId = DataListExecutionID.Get(context); var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); InitializeDebug(dataObject); try { var expressionsEntry = compiler.Evaluate(executionId, enActionType.User, Url, false, out errorsTo); allErrors.MergeErrors(errorsTo); var headersEntry = compiler.Evaluate(executionId, enActionType.User, Headers, false, out errorsTo); allErrors.MergeErrors(errorsTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); if (expressionsEntry == null) { AddDebugItem(new DebugItemStaticDataParams("", Url, "URL"), debugItem); } else { AddDebugItem(new DebugItemVariableParams(Url, "URL", expressionsEntry, executionId), debugItem); } _debugInputs.Add(debugItem); } var colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); var urlitr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); var headerItr = Dev2ValueObjectFactory.CreateEvaluateIterator(headersEntry); colItr.AddIterator(urlitr); colItr.AddIterator(headerItr); const int IndexToUpsertTo = 1; while (colItr.HasMoreData()) { var c = colItr.FetchNextRow(urlitr); var headerValue = colItr.FetchNextRow(headerItr).TheValue; var headers = string.IsNullOrEmpty(headerValue) ? new string[0] : headerValue.Split(new[] { '\n', '\r', ';' }, StringSplitOptions.RemoveEmptyEntries); var headersEntries = new List <Tuple <string, string> >(); foreach (var header in headers) { var headerSegments = header.Split(':'); headersEntries.Add(new Tuple <string, string>(headerSegments[0], headerSegments[1])); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemVariableParams(Headers, "Header", headersEntry, executionId), debugItem); _debugInputs.Add(debugItem); } } var result = WebRequestInvoker.ExecuteRequest(Method, c.TheValue, headersEntries); allErrors.MergeErrors(errorsTo); var expression = GetExpression(IndexToUpsertTo); PushResultsToDataList(expression, toUpsert, result, dataObject, executionId, compiler, allErrors); } } catch (Exception e) { Dev2Logger.Log.Error("DSFWebGetRequest", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { DisplayAndWriteError("DsfWebGetRequestActivity", allErrors); compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorsTo); var expression = GetExpression(1); PushResultsToDataList(expression, toUpsert, null, dataObject, executionId, compiler, allErrors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
private string EvaluateExpressiomToStringValue(string expression, Dev2DecisionMode mode, IBinaryDataList dataList) { string result = string.Empty; IDataListCompiler c = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var dlEntry = c.Evaluate(dataList.UID, enActionType.User, expression, false, out errors); if (dlEntry != null && dlEntry.IsRecordset) { if (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Numeric) { int index; if (int.TryParse(DataListUtil.ExtractIndexRegionFromRecordset(expression), out index)) { string error; IList <IBinaryDataListItem> listOfCols = dlEntry.FetchRecordAt(index, out error); if (listOfCols != null) { foreach (IBinaryDataListItem binaryDataListItem in listOfCols) { result = binaryDataListItem.TheValue; } } } } else { if (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry entry = c.Evaluate(dataList.UID, enActionType.User, expression, false, out errors); IDev2DataListEvaluateIterator col1Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(entry); colItr.AddIterator(col1Iterator); bool firstTime = true; while (colItr.HasMoreData()) { if (firstTime) { result = colItr.FetchNextRow(col1Iterator).TheValue; firstTime = false; } else { result += " " + mode + " " + colItr.FetchNextRow(col1Iterator).TheValue; } } } else { result = string.Empty; } } } else { if (dlEntry != null) { var scalarItem = dlEntry.FetchScalar(); result = scalarItem.TheValue; } } return(result); }
/// <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); } } }
//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; } }
// ReSharper restore RedundantOverridenMember /// <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>(); ErrorResultTO errors; ErrorResultTO allErrors = new ErrorResultTO(); Guid executionId = dataObject.DataListID; InitializeDebug(dataObject); try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); // Fetch all fields to search.... IList <string> toSearch = FieldsToSearch.Split(','); // now process each field for entire evaluated Where expression.... IBinaryDataListEntry bdle = compiler.Evaluate(executionId, enActionType.User, SearchCriteria, false, out errors); if (dataObject.IsDebugMode()) { var itemToAdd = new DebugItem(); itemToAdd.Add(new DebugItemResult { Type = DebugItemResultType.Label, Value = "Fields To Search" }); _debugInputs.Add(itemToAdd); } allErrors.MergeErrors(errors); if (bdle != null) { IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(bdle); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); int idx; if (!Int32.TryParse(StartIndex, out idx)) { idx = 1; } IBinaryDataList toSearchList = compiler.FetchBinaryDataList(executionId, out errors); allErrors.MergeErrors(errors); int iterationIndex = 0; foreach (string s in toSearch) { if (dataObject.IsDebugMode()) { IBinaryDataListEntry tmpEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors); AddDebugInputItem(s, string.Empty, tmpEntry, executionId); } // each entry in the recordset while (itr.HasMoreRecords()) { IList <IBinaryDataListItem> cols = itr.FetchNextRowData(); foreach (IBinaryDataListItem c in cols) { IRecsetSearch searchTo = ConvertToSearchTo(c.TheValue, idx.ToString(CultureInfo.InvariantCulture)); IList <string> results = RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errors); allErrors.MergeErrors(errors); string concatRes = string.Empty; // ReSharper disable LoopCanBeConvertedToQuery foreach (string r in results) // ReSharper restore LoopCanBeConvertedToQuery { concatRes = string.Concat(concatRes, r, ","); } if (concatRes.EndsWith(",")) { concatRes = concatRes.Remove(concatRes.Length - 1); } //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result DataListCleaningUtils.SplitIntoRegions(Result); //2013.06.07: Massimo Guerrera for BUG 9497 - To handle putting out to a scalar as a CSV if (!DataListUtil.IsValueRecordset(Result)) { toUpsert.Add(Result, concatRes); toUpsert.FlushIterationFrame(); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugOutputParams(Result, concatRes, executionId, iterationIndex)); } } else { iterationIndex = 0; foreach (string r in results) { toUpsert.Add(Result, r); toUpsert.FlushIterationFrame(); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugOutputParams(Result, r, executionId, iterationIndex)); } iterationIndex++; } } } } } if (dataObject.IsDebugMode()) { AddDebugInputItem(SearchCriteria, "Where", bdle, executionId); } // now push the result to the server compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); } } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfFindRecordsActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }