public void UpsertBuilder_AssignStyleAppend_Expect_10RecordSetEntries_And_Scalar() { IDev2DataListUpsertPayloadBuilder <string> tmp = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); string error; tmp.Add("[[scalar]]", "myScalar"); tmp.FlushIterationFrame(); tmp.Add("[[recset().f1]]", "field1_value1a"); tmp.Add("[[recset().f2]]", "field2_value1a"); tmp.FlushIterationFrame(); tmp.Add("[[recset(10).f1]]", "field1_value2a"); tmp.Add("[[recset(10).f2]]", "field2_value2a"); ErrorResultTO errors; Guid id = _compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), _adlData.ToStringBuilder(), new StringBuilder(_dlShape), out errors); _compiler.Upsert(id, tmp, out errors); IBinaryDataList bdl = _compiler.FetchBinaryDataList(id, out errors); // Else we good to go, normal asserts ;) IBinaryDataListEntry recset; bdl.TryGetEntry("recset", out recset, out error); IBinaryDataListEntry scalar; bdl.TryGetEntry("scalar", out scalar, out error); var res1 = scalar.FetchScalar().TheValue; var res2 = recset.FetchLastRecordsetIndex(); // we have a single scalar Assert.AreEqual("myScalar", res1); Assert.AreEqual(10, res2); }
public void UpsertBuilder_AssignStyleAppend_Expect_Scalar_WithLastRecord() { IDev2DataListUpsertPayloadBuilder <string> tmp = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); tmp.Add("[[recset().f1]]", "field1_value1a"); tmp.Add("[[recset().f2]]", "field2_value1a"); tmp.FlushIterationFrame(); tmp.Add("[[scalar]]", "[[recset(*).f1]]"); tmp.FlushIterationFrame(); ErrorResultTO errors; Guid id = _compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), _adlData.ToStringBuilder(), new StringBuilder(_dlShape), out errors); _compiler.Upsert(id, tmp, out errors); IBinaryDataList bdl = _compiler.FetchBinaryDataList(id, out errors); IBinaryDataListEntry scalar; string error; bdl.TryGetEntry("scalar", out scalar, out error); var res = scalar.FetchScalar().TheValue; // we have a single scalar Assert.AreEqual("field1_value1a", res); }
public void UpsertPayloadBuilder_Without_Flush_Valid_Entries() { IDev2DataListUpsertPayloadBuilder <string> tmp = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); tmp.Add("[[scalar]]", "zzz"); tmp.Add("[[scalar2]]", "aaa"); Assert.AreEqual(1, tmp.FetchFrames().Count); }
public void UpsertPayloadBuilder_MultFrames_Expect_Valid_Entries() { IDev2DataListUpsertPayloadBuilder <string> tmp = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); tmp.Add("[[scalar]]", "zzz"); tmp.FlushIterationFrame(); tmp.Add("[[scalar2]]", "aaa"); Assert.AreEqual(2, tmp.FetchFrames().Count); }
public void UpsertBuilder_AssignStyleAppend_Expect_2RecordSetEntries_And_Scalar_AsDebug() { IDev2DataListUpsertPayloadBuilder <string> tmp = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); tmp.IsDebug = true; tmp.Add("[[scalar]]", "myScalar"); tmp.FlushIterationFrame(); tmp.Add("[[recset().f1]]", "field1_value1"); tmp.Add("[[recset().f2]]", "field2_value1"); tmp.FlushIterationFrame(); tmp.Add("[[recset().f1]]", "field1_value2"); tmp.Add("[[recset().f2]]", "field2_value2"); ErrorResultTO errors; Guid id = _compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), string.Empty.ToStringBuilder(), new StringBuilder(_dlShape), out errors); _compiler.Upsert(id, tmp, out errors); IBinaryDataList bdl = _compiler.FetchBinaryDataList(id, out errors); // Else we good to go, normal asserts ;) IBinaryDataListEntry recset; string error; bdl.TryGetEntry("recset", out recset, out error); IBinaryDataListEntry scalar; bdl.TryGetEntry("scalar", out scalar, out error); var res1 = scalar.FetchScalar().TheValue; var res2 = recset.FetchLastRecordsetIndex(); // we have a single scalar Assert.AreEqual("myScalar", res1); Assert.AreEqual(2, res2); Assert.IsNotNull(tmp.DebugOutputs); Assert.IsNotNull(tmp.DebugOutputs[0].LeftEntry); Assert.IsNotNull(tmp.DebugOutputs[0].RightEntry); Assert.IsNotNull(tmp.DebugOutputs[0].TargetEntry); Assert.IsNotNull(tmp.DebugOutputs[0].RightEntry.ComplexExpressionAuditor); Assert.IsNotNull(tmp.DebugOutputs[0].LeftEntry.ComplexExpressionAuditor); Assert.IsNotNull(tmp.DebugOutputs[0].TargetEntry.ComplexExpressionAuditor); Assert.AreEqual(1, tmp.DebugOutputs[0].RightEntry.ComplexExpressionAuditor.FetchAuditItems().Count); Assert.AreEqual(1, tmp.DebugOutputs[0].LeftEntry.ComplexExpressionAuditor.FetchAuditItems().Count); Assert.AreEqual(5, tmp.DebugOutputs[0].TargetEntry.ComplexExpressionAuditor.FetchAuditItems().Count); }
public void Replace_CaseMatch_Recorset_Expected_No_Replaces() { ErrorResultTO errors; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid exidx = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), TestStrings.ReplaceDataListWithData, TestStrings.ReplaceDataListShape.ToStringBuilder(), out errors); IDev2DataListUpsertPayloadBuilder <string> payloadBuilder = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); IBinaryDataListEntry entry; IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); const string Expression = "[[results(*).resfield]]"; int replaceCount; // ReSharper disable RedundantAssignment payloadBuilder = replaceOperation.Replace(exidx, Expression, "hello", "World", true, payloadBuilder, out errors, out replaceCount, out entry); // ReSharper restore RedundantAssignment Assert.AreEqual(0, replaceCount); }
public void Dev2DataListUpsertPayloadBuilder_UnitTest_KeepsStarIndexingWhenNotReplacing() { IDev2DataListUpsertPayloadBuilder <string> builder = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); builder.Add("[[rs(*).val]]", "aaa"); builder.FlushIterationFrame(); builder.Add("[[rs(*).val]]", "aaa"); var items = builder.FetchFrames(true); foreach (var itm in items) { var exp = itm.FetchNextFrameItem().Expression; const string Expected = "rs(*).val"; StringAssert.Contains(exp, Expected, "Index substitution occurred when not active"); } }
public void Replace_NoCaseMatch_Recorset_Expected_Correct_Data_Returned_ReplaceCount_Twenty() { ErrorResultTO errors; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid exidx = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML), TestStrings.ReplaceDataListWithData.ToStringBuilder(), TestStrings.ReplaceDataListShape.ToStringBuilder(), out errors); IDev2DataListUpsertPayloadBuilder <string> payloadBuilder = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); IBinaryDataListEntry entry; const string Expected = "World0"; const string Expression = "[[results(*).resfield]]"; int replaceCount; payloadBuilder = replaceOperation.Replace(exidx, Expression, "hello", "World", false, payloadBuilder, out errors, out replaceCount, out entry); var frames = payloadBuilder.FetchFrames(); var frame = frames[0].FetchNextFrameItem(); Assert.AreEqual(20, replaceCount); Assert.AreEqual("[[results(1).resfield]]", frame.Expression); Assert.AreEqual(Expected, frame.Value); }
public void Dev2DataListUpsertPayloadBuilder_UnitTest_CanReplaceStarWithFixedIndexOnFlush() { IDev2DataListUpsertPayloadBuilder <string> builder = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); builder.ReplaceStarWithFixedIndex = true; builder.Add("[[rs(*).val]]", "aaa"); builder.FlushIterationFrame(); builder.Add("[[rs(*).val]]", "aaa"); var items = builder.FetchFrames(true); int idx = 1; foreach (var itm in items) { var exp = itm.FetchNextFrameItem().Expression; var expected = "rs(" + idx + ").val"; StringAssert.Contains(exp, expected, "Index substitution did not occur correctly"); idx++; } }
public void UpsertPayloadBuilder_FetchFrames_Expect_Ordered_Valid_Entries() { IDev2DataListUpsertPayloadBuilder <string> tmp = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); tmp.Add("[[scalar]]", "zzz"); tmp.FlushIterationFrame(); tmp.Add("[[scalar2]]", "aaa"); IList <string> expressions = new List <string>(); IList <string> values = new List <string>(); IList <IDataListPayloadIterationFrame <string> > frames = tmp.FetchFrames(); int frameID = 1; foreach (IDataListPayloadIterationFrame <string> f in frames) { while (f.HasData()) { DataListPayloadFrameTO <string> t2 = f.FetchNextFrameItem(); expressions.Add(t2.Expression + "." + frameID); values.Add(t2.Value + "." + frameID); } frameID++; } IList <string> expectedExpressions = new List <string> { "[[scalar]].1", "[[scalar2]].2" }; CollectionAssert.AreEqual(expectedExpressions.ToArray(), expressions.ToArray()); CollectionAssert.AreEqual(expectedExpressions.ToArray(), expressions.ToArray()); }
// 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); } } }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; var errorResultTo = new ErrorResultTO(); var allErrors = new ErrorResultTO(); bool addExceptionToErrorList = true; InitializeDebug(dataObject); try { IWarewolfIterator batchItr; IWarewolfIterator timeoutItr; var parametersIteratorCollection = BuildParametersIteratorCollection(dataObject.Environment, out batchItr, out timeoutItr); var currentOptions = BuildSqlBulkCopyOptions(); var runtimeDatabase = ResourceCatalog.Instance.GetResource <DbSource>(dataObject.WorkspaceID, Database.ResourceID); if (runtimeDatabase.ServerType == enSourceType.MySqlDatabase) { DoInsertForMySql(runtimeDatabase, currentOptions, parametersIteratorCollection, batchItr, timeoutItr, dataObject, errorResultTo, allErrors, ref addExceptionToErrorList); } else { DoInsertForSqlServer(runtimeDatabase, currentOptions, dataObject, allErrors, batchItr, parametersIteratorCollection, timeoutItr, ref errorResultTo, ref addExceptionToErrorList); } allErrors.MergeErrors(errorResultTo); } 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()) { DisplayAndWriteError("DsfSqlBulkInsertActivity", allErrors); dataObject.Environment.Assign(Result, null); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("Failure", Result, "", "=")); } } if (toUpsert.IsDebug) { DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, 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); } } }
/// <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); } } }
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(); Guid dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); IDev2DataListUpsertPayloadBuilder <IBinaryDataListEntry> toUpsertDeferred = Dev2DataListBuilderFactory.CreateBinaryDataListUpsertBuilder(true); toUpsertDeferred.IsDebug = true; IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = true; // Process if no errors if (dataObject.IsDebugMode()) { InitializeDebug(dataObject); } if (!errors.HasErrors()) { try { //Execute the concrete action for the specified activity IList <OutputTO> outputs = ExecuteConcreteAction(context, out errors); allErrors.MergeErrors(errors); if (outputs.Count > 0) { foreach (OutputTO output in outputs) { if (output.OutputStrings.Count > 0) { foreach (string value in output.OutputStrings) { if (output.OutPutDescription == GlobalConstants.ErrorPayload) { errors.AddError(value); } else { //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result foreach (var region in DataListCleaningUtils.SplitIntoRegions(output.OutPutDescription)) { toUpsert.Add(region, value); } } } toUpsert.FlushIterationFrame(); } } compiler.Upsert(dlId, toUpsert, out errors); if (dataObject.IsDebugMode()) { if (!String.IsNullOrEmpty(Result)) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } allErrors.MergeErrors(errors); } } catch (Exception ex) { allErrors.AddError(ex.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfFileActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, 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) { _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> /// 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 /// <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); } } }
/// <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 executionId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors; IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false); toUpsert.IsDebug = (dataObject.IsDebugMode()); toUpsert.ResourceID = dataObject.ResourceID; if (dataObject.ExecutingUser != null) { _currentIdentity = dataObject.ExecutingUser.Identity; } var indexCounter = 0; InitializeDebug(dataObject); try { CleanArgs(); foreach (GatherSystemInformationTO item in SystemInformationCollection) { try { indexCounter++; if (dataObject.IsDebugMode()) { var inputToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", indexCounter.ToString(CultureInfo.InvariantCulture)), inputToAdd); AddDebugItem(new DebugItemStaticDataParams("", item.Result, "", "="), inputToAdd); AddDebugItem(new DebugItemStaticDataParams(item.EnTypeOfSystemInformation.GetDescription(), ""), inputToAdd); _debugInputs.Add(inputToAdd); } var hasErrors = allErrors.HasErrors(); if (!hasErrors) { string val = GetCorrectSystemInformation(item.EnTypeOfSystemInformation); string expression = item.Result; foreach (var region in DataListCleaningUtils.SplitIntoRegions(expression)) { toUpsert.Add(region, val); } } } catch (Exception) { toUpsert.Add(item.Result, null); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { int innerCount = 1; foreach (DebugTO 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++; } } } catch (Exception e) { Dev2Logger.Log.Error("DSFGatherSystemInformationTool", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors); compiler.UpsertSystemTag(executionId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { int innerCount = 1; foreach (DebugTO 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++; } } 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(); } } }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); ErrorResultTO allErrors = new ErrorResultTO(); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false); toUpsert.IsDebug = (dataObject.IsDebugMode()); toUpsert.ResourceID = dataObject.ResourceID; if (dataObject.ExecutingUser != null) { _currentIdentity = dataObject.ExecutingUser.Identity; } var indexCounter = 0; InitializeDebug(dataObject); try { CleanArgs(); foreach (GatherSystemInformationTO item in SystemInformationCollection) { try { indexCounter++; if (dataObject.IsDebugMode()) { var inputToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", indexCounter.ToString(CultureInfo.InvariantCulture)), inputToAdd); AddDebugItem(new DebugItemStaticDataParams("", item.Result, "", "="), inputToAdd); AddDebugItem(new DebugItemStaticDataParams(item.EnTypeOfSystemInformation.GetDescription(), ""), inputToAdd); _debugInputs.Add(inputToAdd); } var hasErrors = allErrors.HasErrors(); if (!hasErrors) { string val = GetCorrectSystemInformation(item.EnTypeOfSystemInformation); string expression = item.Result; var regions = DataListCleaningUtils.SplitIntoRegions(expression); if (regions.Count > 1) { allErrors.AddError("Multiple variables in result field."); } else { foreach (var region in regions) { dataObject.Environment.AssignWithFrame(new AssignValue(region, val)); } } } } catch (Exception err) { dataObject.Environment.Assign(item.Result, null); allErrors.AddError(err.Message); } } dataObject.Environment.CommitAssign(); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { int innerCount = 1; foreach (GatherSystemInformationTO item in SystemInformationCollection) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", "", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugEvalResult(item.Result, "", dataObject.Environment), itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } } } catch (Exception e) { Dev2Logger.Log.Error("DSFGatherSystemInformationTool", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors); foreach (var error in allErrors.FetchErrors()) { dataObject.Environment.AddError(error); } } if (dataObject.IsDebugMode()) { if (hasErrors) { int innerCount = 1; foreach (GatherSystemInformationTO item in SystemInformationCollection) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugEvalResult(item.Result, "", dataObject.Environment), itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } } DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, 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) { 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(); toUpsert.IsDebug = (dataObject.IsDebugMode()); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { if (!errors.HasErrors()) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2DataListEvaluateIterator scriptItr = CreateDataListEvaluateIterator(Script, executionId, compiler, colItr, allErrors); IBinaryDataListEntry scriptEntry = compiler.Evaluate(executionId, enActionType.User, Script, false, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode()) { var language = ScriptType.GetDescription(); AddDebugInputItem(new DebugItemStaticDataParams(language, "Language")); AddDebugInputItem(new DebugItemVariableParams(Script, "Script", scriptEntry, executionId)); } if (allErrors.HasErrors()) { return; } while (colItr.HasMoreData()) { string scriptValue = colItr.FetchNextRow(scriptItr).TheValue; var engine = new ScriptingEngineRepo().CreateEngine(ScriptType); var value = engine.Execute(scriptValue); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result foreach (var region in DataListCleaningUtils.SplitIntoRegions(Result)) { toUpsert.Add(region, value); toUpsert.FlushIterationFrame(); } } 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) { if (e.GetType() == typeof(NullReferenceException) || e.GetType() == typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException)) { allErrors.AddError("There was an error when returning a value from your script, remember to use the 'Return' keyword when returning the result"); } else { allErrors.AddError(e.Message.Replace(" for main:Object", string.Empty)); } } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfScriptingJavaScriptActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { if (allErrors.HasErrors()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
// 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); } } }
/// <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); } } }
/// <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; 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); } } }
// ReSharper restore RedundantOverridenMember protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2MergeOperations mergeOperations = new Dev2MergeOperations(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errorResultTo = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { CleanArguments(MergeCollection); if (MergeCollection.Count <= 0) { return; } IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); allErrors.MergeErrors(errorResultTo); Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >(); #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data int dictionaryKey = 0; foreach (DataMergeDTO row in MergeCollection) { IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); var fieldName = row.InputVariable; var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName); var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString(); if (!string.IsNullOrEmpty(datalist)) { foreach (var region in splitIntoRegions) { var r = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region; var isValidExpr = new IsValidExpressionRule(() => r, datalist) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { row.InputVariable = ""; errorResultTo.AddError(errorInfo.Message); } allErrors.MergeErrors(errorResultTo); } } allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem); AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem); //Old workflows don't have this set. if (row.Alignment == null) { row.Alignment = string.Empty; } AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem); _debugInputs.Add(debugItem); } IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry); IDev2DataListEvaluateIterator atItr = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry); IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry); iteratorCollection.AddIterator(itr); iteratorCollection.AddIterator(atItr); iteratorCollection.AddIterator(padItr); listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> { itr, atItr, padItr }); dictionaryKey++; } #endregion #region Iterate and Merge Data if (!allErrors.HasErrors()) { while (iteratorCollection.HasMoreData()) { int pos = 0; foreach (var iterator in listOfIterators) { var val = iteratorCollection.FetchNextRow(iterator.Value[0]); var at = iteratorCollection.FetchNextRow(iterator.Value[1]); var pad = iteratorCollection.FetchNextRow(iterator.Value[2]); if (val != null) { if (at != null) { if (pad != null) { if (MergeCollection[pos].MergeType == "Index") { if (string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } int atValue; if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0) { allErrors.AddError("The 'Using' value must be a real number."); } if (pad.TheValue.Length > 1) { allErrors.AddError("'Padding' must be a single character"); } } else { if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } } mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment); pos++; } } } } } if (!allErrors.HasErrors()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "")); } else { var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(Result, mergeOperations.MergeData.ToString()); toUpsert.FlushIterationFrame(); compiler.Upsert(executionId, toUpsert, out errorResultTo); allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } } } } } #endregion Iterate and Merge Data } catch (Exception e) { Dev2Logger.Log.Error("DSFDataMerge", e); allErrors.AddError(e.Message); } finally { #region Handle Errors if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfDataMergeActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } #endregion } }
// ReSharper restore RedundantOverridenMember /// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); 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); } } }