Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
#pragma warning disable S1541 // Methods and properties should not be too complex
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            var            replaceOperation = Dev2OperationsFactory.CreateReplaceOperation();
            IErrorResultTO errors           = new ErrorResultTO();
            IErrorResultTO allErrors        = new ErrorResultTO();

            var replacementCount = 0;
            var replacementTotal = 0;

            InitializeDebug(dataObject);
            try
            {
                IList <string> toSearch = FieldsToSearch.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                AddTypeDebugItem(dataObject, update, toSearch);

                foreach (string s in toSearch)
                {
                    if (!DataListUtil.IsEvaluated(s))
                    {
                        allErrors.AddError(ErrorResource.RequiredVaraibleNameONLY);
                        return;
                    }
                }
                IWarewolfListIterator iteratorCollection = new WarewolfListIterator();

                var finRes = dataObject.Environment.Eval(Find, update);
                if (ExecutionEnvironment.IsNothing(finRes))
                {
                    if (!string.IsNullOrEmpty(Result))
                    {
                        dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture), update);
                    }
                }
                else
                {
                    var itrFind = new WarewolfIterator(dataObject.Environment.Eval(Find, update));
                    iteratorCollection.AddVariableToIterateOn(itrFind);

                    var itrReplace = new WarewolfIterator(dataObject.Environment.Eval(ReplaceWith, update));
                    iteratorCollection.AddVariableToIterateOn(itrReplace);
                    var rule   = new IsSingleValueRule(() => Result);
                    var single = rule.Check();
                    if (single != null)
                    {
                        allErrors.AddError(single.Message);
                    }
                    else
                    {
                        allErrors = TryExecute(dataObject, update, replaceOperation, ref errors, allErrors, ref replacementCount, ref replacementTotal, toSearch, iteratorCollection, itrFind, itrReplace);
                    }
                }
                if (dataObject.IsDebugMode() && !allErrors.HasErrors() && !string.IsNullOrEmpty(Result))
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                }

                // now push the result to the server
            }

            catch (Exception ex)
            {
                Dev2Logger.Error("DSFReplace", ex, GlobalConstants.WarewolfError);
                allErrors.AddError(ex.Message);
            }
            finally
            {
                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    dataObject.Environment.Assign(Result, null, update);
                    DisplayAndWriteError(dataObject, DisplayName, allErrors);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();

            IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation();
            ErrorResultTO         errors;
            ErrorResultTO         allErrors = new ErrorResultTO();

            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())
                    {
                        AddDebugInputItem(new DebugEvalResult(s, "In Field(s)", dataObject.Environment));
                        if (Find != null)
                        {
                            AddDebugInputItem(new DebugEvalResult(Find, "Find", dataObject.Environment));
                        }
                        if (ReplaceWith != null)
                        {
                            AddDebugInputItem(new DebugEvalResult(ReplaceWith, "Replace With", dataObject.Environment));
                        }
                    }
                }
                IWarewolfListIterator iteratorCollection = new WarewolfListIterator();

                var finRes = dataObject.Environment.Eval(Find);
                if (ExecutionEnvironment.IsNothing(finRes))
                {
                    if (!string.IsNullOrEmpty(Result))
                    {
                        dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture));
                    }
                }
                else
                {
                    var itrFind = new WarewolfIterator(dataObject.Environment.Eval(Find));
                    iteratorCollection.AddVariableToIterateOn(itrFind);

                    var itrReplace = new WarewolfIterator(dataObject.Environment.Eval(ReplaceWith));
                    iteratorCollection.AddVariableToIterateOn(itrReplace);
                    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.FetchNextValue(itrFind);
                            var replaceWithValue = iteratorCollection.FetchNextValue(itrReplace);
                            foreach (string s in toSearch)
                            {
                                if (!DataListUtil.IsEvaluated(s))
                                {
                                    allErrors.AddError("Please insert only variables into Fields To Search");
                                    return;
                                }
                                if (!string.IsNullOrEmpty(findValue))
                                {
                                    dataObject.Environment.ApplyUpdate(s, a => DataASTMutable.WarewolfAtom.NewDataString(replaceOperation.Replace(a.ToString(), findValue, replaceWithValue, CaseMatch, out errors, ref replacementCount)));
                                }

                                replacementTotal += replacementCount;
                                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                                {
                                    if (!string.IsNullOrEmpty(Result))
                                    {
                                        if (replacementCount > 0)
                                        {
                                            AddDebugOutputItem(new DebugEvalResult(s, "", dataObject.Environment));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(Result))
                    {
                        dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture));
                    }
                }
                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                {
                    if (!string.IsNullOrEmpty(Result))
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment));
                    }
                }
                // now push the result to the server
            }
            // 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);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    dataObject.Environment.Assign(Result, null);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before);
                    DispatchDebugState(dataObject, StateType.After);
                }
            }
        }
Пример #5
0
        /// <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);
                }
            }
        }
Пример #6
0
 public void Initialization()
 {
     _dev2ReplaceOperation = Dev2OperationsFactory.CreateReplaceOperation();
 }