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>(); _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); } } }
// 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); } } }
// ReSharper restore RedundantOverridenMember 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 = DataListExecutionID.Get(context); InitializeDebug(dataObject); try { string rawRecsetName = RetrieveItemForEvaluation(enIntellisensePartType.RecordsetsOnly, SortField); string sortField = RetrieveItemForEvaluation(enIntellisensePartType.RecordsetFields, SortField); bool descOrder = String.IsNullOrEmpty(SelectedSort) || SelectedSort.Equals("Backwards"); // Travis.Frisinger : New Stuff.... if (!string.IsNullOrEmpty(rawRecsetName)) { IBinaryDataList bdl = compiler.FetchBinaryDataList(executionId, out errors); IBinaryDataListEntry rsData; string error; bdl.TryGetEntry(rawRecsetName, out rsData, out error); if (dataObject.IsDebugMode()) { AddDebugInputItem(SortField, "Sort Field", rsData, executionId); } allErrors.AddError(error); IsSingleRecordSetRule rule = new IsSingleRecordSetRule(() => SortField); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } // Check for fields if (rsData != null && rsData.HasField(sortField)) { rsData.Sort(sortField, descOrder, out error); errors.AddError(error); // Push back against the datalist compiler.PushBinaryDataList(executionId, bdl, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode()) { bdl.TryGetEntry(rawRecsetName, out rsData, out error); //Added for Bug 9479 string tmpExpression = SortField; if (tmpExpression.Contains("().")) { tmpExpression = tmpExpression.Replace("().", "(*)."); } AddDebugOutputItem(new DebugItemVariableParams(tmpExpression, "", rsData, executionId)); } } } else { allErrors.AddError("No recordset given"); } } finally { if (allErrors.HasErrors()) { DisplayAndWriteError("DsfSortRecordsActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } // End Travis.Frisinger New Stuff }
/// <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(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); // Process if no errors try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = (dataObject.IsDebugMode()); toUpsert.ResourceID = dataObject.ResourceID; IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2DataListEvaluateIterator dtItr = CreateDataListEvaluateIterator(string.IsNullOrEmpty(DateTime) ? GlobalConstants.CalcExpressionNow : DateTime, executionId, compiler, colItr, allErrors); colItr.AddIterator(dtItr); IDev2DataListEvaluateIterator ifItr = CreateDataListEvaluateIterator(InputFormat, executionId, compiler, colItr, allErrors); colItr.AddIterator(ifItr); IDev2DataListEvaluateIterator ofItr = CreateDataListEvaluateIterator(OutputFormat, executionId, compiler, colItr, allErrors); colItr.AddIterator(ofItr); IDev2DataListEvaluateIterator tmaItr = CreateDataListEvaluateIterator(TimeModifierAmountDisplay, executionId, compiler, colItr, allErrors); colItr.AddIterator(tmaItr); if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(DateTime)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time", "Input"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(System.DateTime.Now.ToString(CultureInfo.CurrentCulture), "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugItemVariableParams(DateTime, "Input", dtItr.FetchEntry(), executionId)); } var dateTimePattern = string.Format("{0} {1}", CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern, CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern); if (string.IsNullOrEmpty(InputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Input Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugItemVariableParams(InputFormat, "Input Format", ifItr.FetchEntry(), executionId)); } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(TimeModifierType, "Add Time"), debugItem); AddDebugItem(new DebugItemVariableParams(TimeModifierAmountDisplay, "", tmaItr.FetchEntry(), executionId, true), debugItem); _debugInputs.Add(debugItem); if (string.IsNullOrEmpty(OutputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Output Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugItemVariableParams(OutputFormat, "Output Format", ofItr.FetchEntry(), executionId)); } } if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { IDateTimeOperationTO transObj = ConvertToDateTimeTo(colItr.FetchNextRow(dtItr).TheValue, colItr.FetchNextRow(ifItr).TheValue, colItr.FetchNextRow(ofItr).TheValue, TimeModifierType, colItr.FetchNextRow(tmaItr).TheValue ); //Create a DateTimeFomatter using the DateTimeConverterFactory.DONE IDateTimeFormatter format = DateTimeConverterFactory.CreateFormatter(); string result; string error; if (format.TryFormat(transObj, out result, out error)) { string expression = Result; //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result toUpsert.Add(expression, result); toUpsert.FlushIterationFrame(); } else { allErrors.AddError(error); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } allErrors.MergeErrors(errors); } } catch (Exception e) { Dev2Logger.Log.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDateTimeActivity", 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); } } }
/// <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); } } }
/// <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; var allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); IDev2DataListUpsertPayloadBuilder <IBinaryDataListEntry> toUpsert = Dev2DataListBuilderFactory.CreateBinaryDataListUpsertBuilder(true); try { toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.AttachDebugFromExpression = false; toUpsert.RecordSetDataAsCSVToScalar = true; toUpsert.ReplaceStarWithFixedIndex = true; IBinaryDataListEntry rsEntry; // We need to break up by , for InFields ;) List <string> cols = BreakAndValidate(dlId, compiler, InFields, dataObject, true, out errors, out rsEntry); allErrors.MergeErrors(errors); // Use row data?!, nope use row indexes ;) List <string> resultFields = BreakAndValidate(dlId, compiler, ResultFields, dataObject, false, out errors, out rsEntry); allErrors.MergeErrors(errors); compiler.Evaluate(dlId, enActionType.User, ResultFields, false, out errors); allErrors.MergeErrors(errors); compiler.Evaluate(dlId, enActionType.User, InFields, false, out errors); allErrors.MergeErrors(errors); // Fetch the unique data ;) if (!allErrors.HasErrors()) { List <int> uniqueRowIndexes = rsEntry.GetDistinctRows(cols); var shadowList = new List <IBinaryDataListEntry>(); // And break and validate the target expressions ;) List <string> targetExpressions = DataListCleaningUtils.SplitIntoRegions(Result); if (!allErrors.HasErrors()) { // process each row ;) foreach (var uidx in uniqueRowIndexes) { int idx = 0; // something in here is off ;) foreach (var targetExp in targetExpressions) { string error; // clone, prep and shove into the upsert payload builder ;) var clone = rsEntry.Clone(enTranslationDepth.Data, dlId, out error); allErrors.AddError(error); clone.MakeRecordsetEvaluateReady(uidx, resultFields[idx], out error); allErrors.AddError(error); // We need to replace * with fixed index? else we will over write all data all the time ;) toUpsert.Add(targetExp, clone); shadowList.Add(clone); idx++; } toUpsert.FlushIterationFrame(); } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); // If in debug mode, we have data and there is the correct debug info balance ;) if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { int innerCount = 1; foreach (var debugOutputTo in toUpsert.DebugOutputs) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugItemVariableParams(debugOutputTo, targetExpressions.ToList()), itemToAdd); UpdateStarNotationColumns(itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } } } } } catch (Exception e) { Dev2Logger.Log.Error("DSFUnique", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfUniqueActivity", allErrors); compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { if (hasErrors && !String.IsNullOrEmpty(Result)) { IBinaryDataListEntry entry = compiler.Evaluate(dlId, enActionType.User, Result, false, out errors); AddDebugOutputItem(new DebugItemVariableParams(Result, "", entry, dlId)); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
// ReSharper restore RedundantOverridenMember protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2MergeOperations mergeOperations = new Dev2MergeOperations(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errorResultTo = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { CleanArguments(MergeCollection); if (MergeCollection.Count <= 0) { return; } IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); allErrors.MergeErrors(errorResultTo); Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >(); #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data int dictionaryKey = 0; foreach (DataMergeDTO row in MergeCollection) { IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); var fieldName = row.InputVariable; var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName); var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString(); if (!string.IsNullOrEmpty(datalist)) { foreach (var region in splitIntoRegions) { var r = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region; var isValidExpr = new IsValidExpressionRule(() => r, datalist) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { row.InputVariable = ""; errorResultTo.AddError(errorInfo.Message); } allErrors.MergeErrors(errorResultTo); } } allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem); AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem); //Old workflows don't have this set. if (row.Alignment == null) { row.Alignment = string.Empty; } AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem); _debugInputs.Add(debugItem); } IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry); IDev2DataListEvaluateIterator atItr = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry); IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry); iteratorCollection.AddIterator(itr); iteratorCollection.AddIterator(atItr); iteratorCollection.AddIterator(padItr); listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> { itr, atItr, padItr }); dictionaryKey++; } #endregion #region Iterate and Merge Data if (!allErrors.HasErrors()) { while (iteratorCollection.HasMoreData()) { int pos = 0; foreach (var iterator in listOfIterators) { var val = iteratorCollection.FetchNextRow(iterator.Value[0]); var at = iteratorCollection.FetchNextRow(iterator.Value[1]); var pad = iteratorCollection.FetchNextRow(iterator.Value[2]); if (val != null) { if (at != null) { if (pad != null) { if (MergeCollection[pos].MergeType == "Index") { if (string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } int atValue; if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0) { allErrors.AddError("The 'Using' value must be a real number."); } if (pad.TheValue.Length > 1) { allErrors.AddError("'Padding' must be a single character"); } } else { if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } } mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment); pos++; } } } } } if (!allErrors.HasErrors()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "")); } else { var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(Result, mergeOperations.MergeData.ToString()); toUpsert.FlushIterationFrame(); compiler.Upsert(executionId, toUpsert, out errorResultTo); allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } } } } } #endregion Iterate and Merge Data } catch (Exception e) { Dev2Logger.Log.Error("DSFDataMerge", e); allErrors.AddError(e.Message); } finally { #region Handle Errors if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfDataMergeActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } #endregion } }
/// <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 /// <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); } } }
[ExcludeFromCodeCoverage] //This execution is no longer used protected override void OnExecute(NativeActivityContext context) { // ???? Why is this here.... context.Properties.ToObservableCollection(); IEsbChannel esbChannel = DataObject.EsbChannel; IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); dataObject.EnvironmentID = context.GetValue(EnvironmentID); Guid datalistId = DataListExecutionID.Get(context); ParentWorkflowInstanceId = context.WorkflowInstanceId.ToString(); dataObject.RemoteServiceType = context.GetValue(Type); var resourceId = context.GetValue(ResourceID); ErrorResultTO allErrors = new ErrorResultTO(); ParentServiceName = dataObject.ServiceName; string parentServiceName = string.Empty; string serviceName = string.Empty; var isRemote = dataObject.IsRemoteWorkflow(); if ((isRemote || dataObject.IsRemoteInvokeOverridden) && dataObject.EnvironmentID == Guid.Empty) { dataObject.IsRemoteInvokeOverridden = true; } var oldResourceId = dataObject.ResourceID; InitializeDebug(dataObject); try { if (ServiceServer != Guid.Empty) { dataObject.RemoteInvokerID = ServiceServer.ToString(); } dataObject.RunWorkflowAsync = RunWorkflowAsync; if (resourceId != Guid.Empty) { dataObject.ResourceID = resourceId; } if (dataObject.IsDebugMode() || dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer) { DispatchDebugState(dataObject, StateType.Before, 0); } // scrub it clean ;) // set the parent service parentServiceName = dataObject.ParentServiceName; serviceName = dataObject.ServiceName; dataObject.ParentServiceName = serviceName; _previousInstanceId = dataObject.ParentInstanceID; dataObject.ParentID = oldResourceId; dataObject.ParentInstanceID = UniqueID; dataObject.ParentWorkflowInstanceId = ParentWorkflowInstanceId; if (!DeferExecution) { // In all cases the ShapeOutput will have merged the execution data up into the current ErrorResultTO tmpErrors = new ErrorResultTO(); if (esbChannel == null) { throw new Exception(ErrorResource.NullESBChannel); } else { // NEW EXECUTION MODEL ;) // PBI 7913 if (datalistId != GlobalConstants.NullDataListID) { BeforeExecutionStart(dataObject, allErrors); allErrors.MergeErrors(tmpErrors); dataObject.ServiceName = ServiceName; // set up for sub-exection ;) dataObject.ResourceID = ResourceID.Expression == null ? Guid.Empty : Guid.Parse(ResourceID.Expression.ToString()); // Execute Request ExecutionImpl(esbChannel, dataObject, InputMapping, OutputMapping, out tmpErrors, 0); // careful of zero if wf comes back allErrors.MergeErrors(tmpErrors); AfterExecutionCompleted(tmpErrors); allErrors.MergeErrors(tmpErrors); dataObject.DataListID = datalistId; // re-set DL ID dataObject.ServiceName = ServiceName; } } } } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfActivity", allErrors); dataObject.Environment.AddError(allErrors.MakeDataListReady()); // add to datalist in variable specified if (!String.IsNullOrEmpty(OnErrorVariable)) { var upsertVariable = DataListUtil.AddBracketsToValueIfNotExist(OnErrorVariable); dataObject.Environment.Assign(upsertVariable, allErrors.MakeDataListReady(), 0); } } if (dataObject.IsDebugMode() || dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer) { DispatchDebugState(dataObject, StateType.After, 0); } dataObject.ParentInstanceID = _previousInstanceId; dataObject.ParentServiceName = parentServiceName; dataObject.ServiceName = serviceName; dataObject.RemoteInvokeResultShape = new StringBuilder(); // reset targnet shape ;) dataObject.RunWorkflowAsync = false; dataObject.RemoteInvokerID = Guid.Empty.ToString(); dataObject.EnvironmentID = Guid.Empty; dataObject.ResourceID = oldResourceId; } }
protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); var dataObject = context.GetExtension <IDSFDataObject>(); var compiler = DataListFactory.CreateDataListCompiler(); var allErrors = new ErrorResultTO(); ErrorResultTO errors; var executionId = DataListExecutionID.Get(context); var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); InitializeDebug(dataObject); try { var expression = Expression ?? string.Empty; var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty; var decimalPlacesToShow = DecimalPlacesToShow ?? string.Empty; var colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); var expressionIterator = CreateDataListEvaluateIterator(expression, executionId, compiler, colItr, allErrors); var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, executionId, compiler, colItr, allErrors); var decimalPlacesToShowIterator = CreateDataListEvaluateIterator(decimalPlacesToShow, executionId, compiler, colItr, allErrors); if (dataObject.IsDebugMode()) { AddDebugInputItem(expression, "Number", expressionIterator.FetchEntry(), executionId); if (!String.IsNullOrEmpty(RoundingType)) { AddDebugInputItem(new DebugItemStaticDataParams(RoundingType, "Rounding")); } AddDebugInputItem(roundingDecimalPlaces, "Rounding Value", roundingDecimalPlacesIterator.FetchEntry(), executionId); AddDebugInputItem(decimalPlacesToShow, "Decimals to show", decimalPlacesToShowIterator.FetchEntry(), executionId); } // Loop data ;) var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); while (colItr.HasMoreData()) { int decimalPlacesToShowValue; var tmpDecimalPlacesToShow = colItr.FetchNextRow(decimalPlacesToShowIterator).TheValue; var adjustDecimalPlaces = tmpDecimalPlacesToShow.IsRealNumber(out decimalPlacesToShowValue); if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces) { throw new Exception("Decimals to show is not valid"); } var tmpDecimalPlaces = colItr.FetchNextRow(roundingDecimalPlacesIterator).TheValue; var roundingDecimalPlacesValue = 0; if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue)) { throw new Exception("Rounding decimal places is not valid"); } var binaryDataListItem = colItr.FetchNextRow(expressionIterator); var val = binaryDataListItem.TheValue; FormatNumberTO formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue); var result = _numberFormatter.Format(formatNumberTo); if (single != null) { allErrors.AddError(single.Message); } else { UpdateResultRegions(toUpsert, result); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFNumberFormatActivity", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfNumberFormatActivity", 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); } } }
protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); dataObject.ForEachNestingLevel++; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); try { ForEachBootstrapTO exePayload = FetchExecutionType(dataObject, executionId, compiler, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); return; } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); } dataObject.ParentInstanceID = UniqueID; allErrors.MergeErrors(errors); string error; ForEachInnerActivityTO innerA = GetInnerActivity(out error); allErrors.AddError(error); exePayload.InnerActivity = innerA; operationalData = exePayload; // flag it as scoped so we can use a single DataList dataObject.IsDataListScoped = true; dataObject.IsDebugNested = true; if (exePayload.InnerActivity != null && exePayload.IndexIterator.HasMore()) { int idx = exePayload.IndexIterator.FetchNextIndex(); if (exePayload.ForEachType != enForEachType.NumOfExecution) { IterateIOMapping(idx, context); } else { dataObject.IsDataListScoped = false; } // schedule the func to execute ;) dataObject.ParentInstanceID = UniqueID; context.ScheduleFunc(DataFunc, string.Empty, ActivityCompleted); } } catch (Exception e) { Dev2Logger.Log.Error("DSFForEach", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfForEachActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); dataObject.ParentInstanceID = _previousParentId; } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.After); } } }
protected override void OnExecute(NativeActivityContext context) { // ???? Why is this here.... context.Properties.ToObservableCollection(); IEsbChannel esbChannel = DataObject.EsbChannel; IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); dataObject.EnvironmentID = context.GetValue(EnvironmentID); Guid datalistId = DataListExecutionID.Get(context); ParentWorkflowInstanceId = context.WorkflowInstanceId.ToString(); dataObject.RemoteServiceType = context.GetValue(Type); var resourceId = context.GetValue(ResourceID); ErrorResultTO allErrors = new ErrorResultTO(); ParentServiceName = dataObject.ServiceName; string parentServiceName = string.Empty; string serviceName = string.Empty; // BUG 9634 - 2013.07.17 - TWR - changed isRemoteExecution to check EnvironmentID instead // This is now the wrong behavior - We need to keep the original EnvironmentID when not a remote workflow // This is because we put and empty GUID in when designing against a remote server that uses it's resources // The first time through this value is set correctly when executing those designed resource from our localhost // If we change it as per what was here, we always get a localhost tag instead of the remote host we are design against var isRemote = dataObject.IsRemoteWorkflow(); if ((isRemote || dataObject.IsRemoteInvokeOverridden) && dataObject.EnvironmentID == Guid.Empty) { dataObject.IsRemoteInvokeOverridden = true; } var oldResourceId = dataObject.ResourceID; InitializeDebug(dataObject); try { //compiler.ClearErrors(dataObject.DataListID); if (ServiceServer != Guid.Empty) { // we need to adjust the originating server id so debug reflect remote server instead of localhost ;) dataObject.RemoteInvokerID = ServiceServer.ToString(); } dataObject.RunWorkflowAsync = RunWorkflowAsync; if (dataObject.IsDebugMode() || (dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer)) { DispatchDebugState(dataObject, StateType.Before); } if (resourceId != Guid.Empty) { dataObject.ResourceID = resourceId; } // scrub it clean ;) // set the parent service parentServiceName = dataObject.ParentServiceName; serviceName = dataObject.ServiceName; dataObject.ParentServiceName = serviceName; _previousInstanceId = dataObject.ParentInstanceID; dataObject.ParentID = oldResourceId; dataObject.ParentInstanceID = UniqueID; dataObject.ParentWorkflowInstanceId = ParentWorkflowInstanceId; if (!DeferExecution) { // In all cases the ShapeOutput will have merged the execution data up into the current ErrorResultTO tmpErrors = new ErrorResultTO(); if (esbChannel == null) { throw new Exception("FATAL ERROR : Null ESB channel!!"); } else { // NEW EXECUTION MODEL ;) // PBI 7913 if (datalistId != GlobalConstants.NullDataListID) { BeforeExecutionStart(dataObject, allErrors); allErrors.MergeErrors(tmpErrors); dataObject.ServiceName = ServiceName; // set up for sub-exection ;) dataObject.ResourceID = ResourceID.Expression == null ? Guid.Empty : Guid.Parse(ResourceID.Expression.ToString()); // Execute Request ExecutionImpl(esbChannel, dataObject, InputMapping, OutputMapping, out tmpErrors); allErrors.MergeErrors(tmpErrors); AfterExecutionCompleted(tmpErrors); allErrors.MergeErrors(tmpErrors); dataObject.DataListID = datalistId; // re-set DL ID dataObject.ServiceName = ServiceName; } } bool whereErrors = dataObject.Environment.HasErrors(); SetValues(context, whereErrors); } } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfActivity", allErrors); dataObject.Environment.AddError(allErrors.MakeDataListReady()); // add to datalist in variable specified if (!String.IsNullOrEmpty(OnErrorVariable)) { var upsertVariable = DataListUtil.AddBracketsToValueIfNotExist(OnErrorVariable); dataObject.Environment.Assign(upsertVariable, allErrors.MakeDataListReady()); } } if (dataObject.IsDebugMode() || (dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer)) { DispatchDebugState(dataObject, StateType.After); } dataObject.ParentInstanceID = _previousInstanceId; dataObject.ParentServiceName = parentServiceName; dataObject.ServiceName = serviceName; dataObject.RemoteInvokeResultShape = new StringBuilder(); // reset targnet shape ;) dataObject.RunWorkflowAsync = false; dataObject.RemoteInvokerID = Guid.Empty.ToString(); dataObject.EnvironmentID = Guid.Empty; dataObject.ResourceID = oldResourceId; } }
/// <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); } } }
// ReSharper restore RedundantOverridenMember protected override void OnExecute(NativeActivityContext context) { _debugOutputs.Clear(); _debugInputs.Clear(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false); toUpsert.IsDebug = (dataObject.IsDebugMode()); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); ErrorResultTO errors = new ErrorResultTO(); ErrorResultTO allErrors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); try { if (!errors.HasErrors()) { foreach (ActivityDTO t in FieldsCollection) { if (!string.IsNullOrEmpty(t.FieldName)) { var fieldName = t.FieldName; fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName; var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString(); if (!string.IsNullOrEmpty(datalist)) { var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { t.FieldName = ""; errors.AddError(errorInfo.Message); } allErrors.MergeErrors(errors); } string eval = t.FieldValue; if (eval.StartsWith("@")) { eval = GetEnviromentVariable(dataObject, context, eval); } toUpsert.Add(t.FieldName, eval); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugTos(toUpsert, executionId); } allErrors.MergeErrors(errors); } } catch (Exception e) { Dev2Logger.Log.Error(e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfAssignActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugTos(toUpsert, executionId); } 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) { _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); } } }
/// <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(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); if (dataObject.IsDebugMode()) { AddDebugInputItem(executionId); } IFunctionEvaluator functionEvaluator = MathOpsFactory.CreateFunctionEvaluator(); string input = string.IsNullOrEmpty(Expression) ? Expression : Expression.Replace("\\r", string.Empty).Replace("\\n", string.Empty).Replace(Environment.NewLine, ""); IEvaluationFunction evaluationFunctionTo = MathOpsFactory.CreateEvaluationExpressionTO(input); string result = functionEvaluator.EvaluateFunction(evaluationFunctionTo, executionId, out errors); allErrors.MergeErrors(errors); compiler.Upsert(executionId, Result, result, out errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugOutputItem(Result, executionId); } allErrors.MergeErrors(errors); } catch (Exception ex) { Dev2Logger.Log.Error("Calculate Exception", ex); allErrors.AddError(ex.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfCalculateActivity", 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(Result, executionId); } 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(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString(); if (!string.IsNullOrEmpty(datalist)) { ValidateInput(datalist, allErrors, Input1); ValidateInput(datalist, allErrors, Input2); } IBinaryDataListEntry input1Entry = compiler.Evaluate(executionId, enActionType.User, string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator input1Itr = Dev2ValueObjectFactory.CreateEvaluateIterator(input1Entry); colItr.AddIterator(input1Itr); IBinaryDataListEntry input2Entry = compiler.Evaluate(executionId, enActionType.User, string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator input2Itr = Dev2ValueObjectFactory.CreateEvaluateIterator(input2Entry); colItr.AddIterator(input2Itr); IBinaryDataListEntry inputFormatEntry = compiler.Evaluate(executionId, enActionType.User, InputFormat ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator ifItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputFormatEntry); colItr.AddIterator(ifItr); if (dataObject.IsDebugMode()) { AddDebugInputItem(string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, "Input 1", input1Entry, executionId); AddDebugInputItem(string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, "Input 2", input2Entry, executionId); AddDebugInputItem(InputFormat, "Input Format", inputFormatEntry, executionId); AddDebugInputItem(new DebugItemStaticDataParams(OutputType, "Output In")); } int indexToUpsertTo = 1; while (colItr.HasMoreData()) { IDateTimeDiffTO transObj = ConvertToDateTimeDiffTo(colItr.FetchNextRow(input1Itr).TheValue, colItr.FetchNextRow(input2Itr).TheValue, colItr.FetchNextRow(ifItr).TheValue, OutputType); //Create a DateTimeComparer using the DateTimeConverterFactory IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); //Call the TryComparer method on the DateTimeComparer and pass it the IDateTimeDiffTO created from the ConvertToDateTimeDiffTO Method string result; string error; if (comparer.TryCompare(transObj, out result, out error)) { string expression; if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { expression = Result.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); } else { expression = Result; } //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(expression, result); } } else { DoDebugOutput(dataObject, Result, result, executionId, indexToUpsertTo); allErrors.AddError(error); } indexToUpsertTo++; } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfDateTimeDifferenceActivity", 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); } } }