public void TryFetchLastIndexedRecordsetUpsertPayload_ColumnName_FetchesForColumn()
        {
            //------------Setup for test--------------------------
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();

            toUpsert.Add("[[rec().f1]]", new List <string> {
                "test11", "test12"
            });
            toUpsert.Add("[[rec().f2]]", new List <string> {
                "test21", "test22"
            });
            IBinaryDataList dataList = Dev2BinaryDataListFactory.CreateDataList();
            string          creationError;

            dataList.TryCreateRecordsetTemplate("rec", "recset", new List <Dev2Column> {
                DataListFactory.CreateDev2Column("f1", "f1"), DataListFactory.CreateDev2Column("f2", "f2")
            }, true, out creationError);
            ErrorResultTO localErrors;

            compiler.PushBinaryDataList(dataList.UID, dataList, out localErrors);
            compiler.Upsert(dataList.UID, toUpsert, out _errors);
            IBinaryDataListEntry recEntry;
            string error;

            dataList.TryGetEntry("rec", out recEntry, out error);
            //------------Assert Preconditions-------------------
            Assert.IsNotNull(recEntry);
            //------------Execute Test---------------------------
            var listItem = recEntry.TryFetchLastIndexedRecordsetUpsertPayload(out error, "f2");

            //------------Assert Results-------------------------
            Assert.AreEqual("test22", listItem.TheValue);
        }
        public void UpsertWhereListStringExpectUpsertCorrectlyMultipleRecordset()
        {
            //------------Setup for test--------------------------
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();

            toUpsert.Add("[[rec().f1]]", new List <string> {
                "test11", "test12"
            });
            toUpsert.Add("[[rec().f2]]", new List <string> {
                "test21", "test22"
            });
            IBinaryDataList dataList = Dev2BinaryDataListFactory.CreateDataList();
            string          creationError;

            dataList.TryCreateRecordsetTemplate("rec", "recset", new List <Dev2Column> {
                DataListFactory.CreateDev2Column("f1", "f1"), DataListFactory.CreateDev2Column("f2", "f2")
            }, true, out creationError);
            ErrorResultTO localErrors;

            compiler.PushBinaryDataList(dataList.UID, dataList, out localErrors);
            //------------Execute Test---------------------------
            compiler.Upsert(dataList.UID, toUpsert, out _errors);
            //------------Assert Results-------------------------
            IList <IBinaryDataListEntry> binaryDataListEntries = dataList.FetchRecordsetEntries();
            IBinaryDataListEntry         binaryDataListEntry   = binaryDataListEntries[0];
            string errString;
            IList <IBinaryDataListItem> binaryDataListItems = binaryDataListEntry.FetchRecordAt(1, out errString);
            IBinaryDataListItem         binaryDataListItem  = binaryDataListItems[0];
            IBinaryDataListItem         binaryDataListItem2 = binaryDataListItems[1];
            string theValue = binaryDataListItem.TheValue;

            Assert.AreEqual("test11", theValue);
            theValue = binaryDataListItem2.TheValue;
            Assert.AreEqual("test21", theValue);
            binaryDataListItems = binaryDataListEntry.FetchRecordAt(2, out errString);
            binaryDataListItem  = binaryDataListItems[0];
            binaryDataListItem2 = binaryDataListItems[1];
            theValue            = binaryDataListItem.TheValue;
            Assert.AreEqual("test12", theValue);
            theValue = binaryDataListItem2.TheValue;

            Assert.AreEqual("test22", theValue);
        }
Beispiel #3
0
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugOutputs.Clear();

            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();

            _isDebugMode        = dataObject.IsDebugMode();
            toUpsert.IsDebug    = _isDebugMode;
            toUpsert.ResourceID = dataObject.ResourceID;
            ErrorResultTO errors      = new ErrorResultTO();
            ErrorResultTO allErrors   = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);
            XPathParser   parser      = new XPathParser();
            int           i           = 0;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, SourceString, false, out errors);

                    if (_isDebugMode)
                    {
                        AddSourceStringDebugInputItem(SourceString, expressionsEntry, executionId);
                        AddResultDebugInputs(ResultsCollection, executionId, compiler, out errors);
                        allErrors.MergeErrors(errors);
                    }
                    if (!allErrors.HasErrors())
                    {
                        IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                        while (itr.HasMoreRecords())
                        {
                            IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                            foreach (IBinaryDataListItem c in cols)
                            {
                                for (i = 0; i < ResultsCollection.Count; i++)
                                {
                                    if (!string.IsNullOrEmpty(ResultsCollection[i].OutputVariable))
                                    {
                                        IBinaryDataListEntry          xpathEntry = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].XPath, false, out errors);
                                        IDev2DataListEvaluateIterator xpathItr   = Dev2ValueObjectFactory.CreateEvaluateIterator(xpathEntry);
                                        while (xpathItr.HasMoreRecords())
                                        {
                                            IList <IBinaryDataListItem> xpathCols = xpathItr.FetchNextRowData();
                                            foreach (IBinaryDataListItem xPathCol in xpathCols)
                                            {
                                                try
                                                {
                                                    List <string> eval = parser.ExecuteXPath(c.TheValue, xPathCol.TheValue).ToList();

                                                    //2013.06.03: Ashley Lewis for bug 9498 - handle line breaks in multi assign
                                                    string[] openParts  = Regex.Split(ResultsCollection[i].OutputVariable, @"\[\[");
                                                    string[] closeParts = Regex.Split(ResultsCollection[i].OutputVariable, @"\]\]");
                                                    if (openParts.Count() == closeParts.Count() && openParts.Count() > 2 && closeParts.Count() > 2)
                                                    {
                                                        foreach (var newFieldName in openParts)
                                                        {
                                                            if (!string.IsNullOrEmpty(newFieldName))
                                                            {
                                                                string cleanFieldName;
                                                                if (newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2 < newFieldName.Length)
                                                                {
                                                                    cleanFieldName = "[[" + newFieldName.Remove(newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2);
                                                                }
                                                                else
                                                                {
                                                                    cleanFieldName = "[[" + newFieldName;
                                                                }
                                                                toUpsert.Add(cleanFieldName, eval);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        toUpsert.Add(ResultsCollection[i].OutputVariable, eval);
                                                    }
                                                }
                                                catch (Exception)
                                                {
                                                    toUpsert.Add(ResultsCollection[i].OutputVariable, null);
                                                }
                                            }
                                        }
                                    }
                                }
                                compiler.Upsert(executionId, toUpsert, out errors);
                            }

                            allErrors.MergeErrors(errors);
                        }
                    }
                    if (_isDebugMode && !allErrors.HasErrors())
                    {
                        var innerCount = 1;
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugItemVariableParams(debugOutputTo), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                            innerCount++;
                        }
                        toUpsert.DebugOutputs.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                allErrors.AddError(ex.Message);
            }
            finally
            {
                // Handle Errors

                var actualIndex = i - 1;
                var hasErrors   = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfXPathActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, ResultsCollection[actualIndex].OutputVariable, (string)null, out errors);
                }
                if (_isDebugMode)
                {
                    if (hasErrors)
                    {
                        if (_isDebugMode)
                        {
                            ResultsCollection[actualIndex].XPath = "";
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", (actualIndex + 1).ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugOutputParams(ResultsCollection[actualIndex].OutputVariable, "", executionId, actualIndex + 1), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Beispiel #4
0
        // 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);
                }
            }
        }