public void Can_Create_XML_With_ColumnIODirection_Input() { Guid tmp = CreateDataList(enDev2ColumnArgumentDirection.Input); ErrorResultTO errors; var result = _compiler.ConvertFrom(tmp, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors); const string expected = @"<DataList><recset Description="""" IsEditable=""True"" ColumnIODirection=""Input"" ><f1 Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /><f2 Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /><f3 Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /><f4 Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /><f5 Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /></recset><myScalar Description="""" IsEditable=""True"" ColumnIODirection=""Input"" /></DataList>"; var res = _compiler.HasErrors(tmp); _compiler.ForceDeleteDataListByID(tmp); Assert.AreEqual(expected, result.ToString()); Assert.IsFalse(res); }
public void XML_Without_SystemTags_ConvertTo_WhenSingleRecordset_ExpectNoErrors() { //------------Setup for test-------------------------- IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; var data = new StringBuilder("<DataList><hero index=\"1\"><name>Chuck Norris</name><pushups>All of them</pushups></hero></DataList>"); var shape = new StringBuilder(@"<DataList> <hero Description="""" IsEditable=""True"" ColumnIODirection=""Output""> <name Description="""" IsEditable=""True"" ColumnIODirection=""Output"" /> <pushups Description="""" IsEditable=""True"" ColumnIODirection=""Output"" /> </hero> <rect Description="""" IsEditable=""True"" ColumnIODirection=""None""> <set Description="""" IsEditable=""True"" ColumnIODirection=""None"" /> </rect> </DataList>"); //------------Execute Test--------------------------- var dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), data, shape, out errors); var result = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out errors); //------------Assert Results------------------------- const string expected = "<DataList><hero><name>Chuck Norris</name><pushups>All of them</pushups></hero></DataList>"; StringAssert.Contains(result.ToString(), expected); }
public string GetXMLForInputs(IBinaryDataList binaryDataList) { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; return (compiler.ConvertFrom(binaryDataList.UID, DataListFormat.CreateFormat(GlobalConstants._XML_Inputs_Only), enTranslationDepth.Data, out errors).ToString()); }
static string ExtractKeyValuePairs(NameValueCollection pairs) { IBinaryDataList bdl = Dev2BinaryDataListFactory.CreateDataList(); // Extract request keys ;) foreach (var key in pairs.AllKeys) { if (key == "wid") //Don't add the Workspace ID to DataList { continue; } if (key.IsXml()) { return(key); //We have a workspace id and XML DataList } string error; bdl.TryCreateScalarTemplate(string.Empty, key, string.Empty, true, out error); if (!string.IsNullOrEmpty(error)) { Dev2Logger.Log.Error(error); } IBinaryDataListEntry entry; if (bdl.TryGetEntry(key, out entry, out error)) { var item = Dev2BinaryDataListFactory.CreateBinaryItem(pairs[key], key); entry.TryPutScalar(item, out error); if (!string.IsNullOrEmpty(error)) { Dev2Logger.Log.Error(error); } } else { Dev2Logger.Log.Error(error); } } IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid pushedId = compiler.PushBinaryDataList(bdl.UID, bdl, out errors); if (pushedId != Guid.Empty) { var result = compiler.ConvertFrom(pushedId, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); if (errors.HasErrors()) { Dev2Logger.Log.Error(errors.MakeDisplayReady()); } return(result.ToString()); } Dev2Logger.Log.Error(errors.MakeDisplayReady()); return(string.Empty); }
/// <summary> /// Creates the XML data from binary data list. /// </summary> /// <param name="binaryDataList">The binary data list.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private string CreateXmlDataFromBinaryDataList(IBinaryDataList binaryDataList, out ErrorResultTO errors) { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlGuid = compiler.PushBinaryDataList(binaryDataList.UID, binaryDataList, out errors); string result = compiler.ConvertFrom(dlGuid, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString(); return(result); }
/// <summary> /// Creates the XML data from binary data list. /// </summary> /// <param name="binaryDataList">The binary data list.</param> /// <param name="errors">The errors.</param> /// <returns></returns> private string CreateXmlDataFromBinaryDataList(IBinaryDataList binaryDataList, out ErrorResultTO errors) { string result = string.Empty; ErrorResultTO allErrors = new ErrorResultTO(); errors = new ErrorResultTO(); Guid dlGuid = _compiler.PushBinaryDataList(binaryDataList.UID, binaryDataList, out errors); result = _compiler.ConvertFrom(dlGuid, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors); return(result); }
public void CanConvertFromWithSingleScalarDataListXMLTranslatorWithOutSystemTags() { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), new StringBuilder("<root><scalar>s1</scalar></root>"), new StringBuilder("<root><scalar/></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out errors); const string Expected = "<DataList><scalar>s1</scalar></DataList>"; Assert.AreEqual(Expected, data.ToString(), "Expected [ " + Expected + " ] but got [ " + data + " ]"); }
public void CanConvertFromDataListToJsonSingleScalarSingleRecordsetColumn() { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), new StringBuilder("<root><scalar>s1</scalar><rs><val>1</val></rs><rs><val>2</val></rs></root>"), new StringBuilder("<root><scalar/><rs><val/></rs></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._JSON), enTranslationDepth.Data, out errors); var result = JsonConvert.DeserializeObject <TestClassRsWithScalar>(data.ToString()); Assert.AreEqual("s1", result.scalar); Assert.AreEqual("1", result.rs[0].val); Assert.AreEqual("2", result.rs[1].val); }
void ExecuteRequestAsync(IDSFDataObject dataObject, IDataListCompiler compiler, IEsbServiceInvoker invoker, bool isLocal, Guid oldID, out ErrorResultTO invokeErrors) { var clonedDataObject = dataObject.Clone(); StringBuilder dl1 = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), enTranslationDepth.Data, out invokeErrors); var shapeOfData = FindServiceShape(dataObject.WorkspaceID, dataObject.ResourceID); var executionContainer = invoker.GenerateInvokeContainer(clonedDataObject, clonedDataObject.ServiceName, isLocal, oldID); if (executionContainer != null) { if (!isLocal) { var remoteContainer = executionContainer as RemoteWorkflowExecutionContainer; if (remoteContainer != null) { if (!remoteContainer.ServerIsUp()) { invokeErrors.AddError("Asynchronous execution failed: Remote server unreachable"); } SetRemoteExecutionDataList(dataObject, executionContainer); shapeOfData = dataObject.RemoteInvokeResultShape; } } if (!invokeErrors.HasErrors()) { var task = Task.Factory.StartNew(() => { Dev2Logger.Log.Info("ASYNC EXECUTION USER CONTEXT IS [ " + Thread.CurrentPrincipal.Identity.Name + " ]"); ErrorResultTO error; clonedDataObject.DataListID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), dl1, shapeOfData, out error); executionContainer.Execute(out error); }); // ReSharper disable ImplicitlyCapturedClosure task.ContinueWith(o => // ReSharper restore ImplicitlyCapturedClosure { DataListRegistar.DisposeScope(o.Id, clonedDataObject.DataListID); o.Dispose(); }); } } else { invokeErrors.AddError("Asynchronous execution failed: Resource not found"); } }
static void ValidateVariable(string fieldName, IDataListCompiler compiler, IDSFDataObject dataObject, out ErrorResultTO errors) { 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).ToString(); if (!string.IsNullOrEmpty(datalist)) { var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { errors.AddError(errorInfo.Message); } } }
public void CanConvertDataTableToDataListWithScalar() { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); // build up DataTable DataTable dbData = new DataTable("rs"); dbData.Columns.Add("scalar", typeof(string)); dbData.Rows.Add("aaa"); // Execute Translator ErrorResultTO errors; Guid dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._DATATABLE), dbData, new StringBuilder("<root><scalar/></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); Assert.AreEqual("<DataList><scalar>aaa</scalar></DataList>", data.ToString()); }
public void CanConvertDataTableToDataList() { IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); // build up DataTable DataTable dbData = new DataTable("rs"); dbData.Columns.Add("val", typeof(string)); dbData.Columns.Add("otherVal", typeof(int)); dbData.Rows.Add("aaa", 1); dbData.Rows.Add("zzz", 2); // Execute Translator ErrorResultTO errors; Guid dlID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._DATATABLE), dbData, new StringBuilder("<root><rs><val/><otherVal/></rs></root>"), out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); Assert.AreEqual("<DataList><rs><val>aaa</val><otherVal>1</otherVal></rs><rs><val>zzz</val><otherVal>2</otherVal></rs></DataList>", data.ToString()); }
public void Populate_TwiceWithNumericIndex_PutsDataAtIndex() { //-------------------Setup ---------------------------------- const string outputDefs = "<Outputs><Output Name=\"[[rs(2).num]]\" MapsTo=\"[[rec(*).num]]\" Value=\"[[rs(2).num]]\" Recordset=\"rs\"/></Outputs>"; IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; Guid dataListID = compiler.ConvertTo(DataListFormat.CreateFormat(GlobalConstants._XML_Without_SystemTags), new StringBuilder("<root></root>"), new StringBuilder("<root><rs><num></num></rs></root>"), out errors); // build up DataTable DataTable dbData = new DataTable("rec"); dbData.Columns.Add("num", typeof(string)); dbData.Rows.Add("One"); dbData.Rows.Add("Two"); dbData.Rows.Add("Three"); // Execute Translator Guid dlID = compiler.PopulateDataList(DataListFormat.CreateFormat(GlobalConstants._DATATABLE), dbData, outputDefs, dataListID, out errors); var data = compiler.ConvertFrom(dlID, DataListFormat.CreateFormat(GlobalConstants._XML), enTranslationDepth.Data, out errors); Assert.AreEqual("<DataList><rs><num>One</num></rs><rs><num>Two</num></rs><rs><num>Three</num></rs></DataList>", data.ToString()); }
// 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); } } }
// 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 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); } } }
// 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 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); } } }
protected override void OnExecute(NativeActivityContext context) { // ???? Why is this here.... context.Properties.ToObservableCollection(); IEsbChannel esbChannel = context.GetExtension <IEsbChannel>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO errors; ErrorResultTO allErrors = new ErrorResultTO(); Guid datalistId = DataListExecutionID.Get(context); ParentServiceName = dataObject.ServiceName; ParentWorkflowInstanceId = context.WorkflowInstanceId.ToString(); 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(); dataObject.EnvironmentID = context.GetValue(EnvironmentID); 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.RemoteServiceType = context.GetValue(Type); dataObject.RunWorkflowAsync = RunWorkflowAsync; if (dataObject.IsDebugMode() || (dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer)) { DispatchDebugState(context, StateType.Before); } var resourceId = context.GetValue(ResourceID); if (resourceId != Guid.Empty) { dataObject.ResourceID = resourceId; } // scrub it clean ;) ScrubDataList(compiler, datalistId, context.WorkflowInstanceId.ToString(), out errors); allErrors.MergeErrors(errors); // 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; } // ** THIS IS A HACK OF NOTE, WE NEED TO ADDRESS THIS! if (dataObject.IsDebugMode()) { //Dont remove this it is here to fix the data not being returned correctly string testData = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), enTranslationDepth.Data, out errors).ToString(); if (string.IsNullOrEmpty(testData)) { } } } bool whereErrors = compiler.HasErrors(datalistId); Result.Set(context, whereErrors); HasError.Set(context, whereErrors); IsValid.Set(context, whereErrors); } } finally { if (!dataObject.WorkflowResumeable || !dataObject.IsDataListScoped) { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); // add to datalist in variable specified if (!String.IsNullOrEmpty(OnErrorVariable)) { var upsertVariable = DataListUtil.AddBracketsToValueIfNotExist(OnErrorVariable); compiler.Upsert(dataObject.DataListID, upsertVariable, allErrors.MakeDataListReady(), out errors); } } } if (dataObject.IsDebugMode() || (dataObject.RunWorkflowAsync && !dataObject.IsFromWebServer)) { DispatchDebugState(context, 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; } }