コード例 #1
0
#pragma warning disable S1541 // Methods and properties should not be too complex
#pragma warning disable S3776 // Cognitive Complexity of methods should not be too high
        private void ExecuteEachField(IDSFDataObject dataObject, int update, IDev2ReplaceOperation replaceOperation, ref IErrorResultTO errors, IErrorResultTO allErrors, ref int replacementCount, ref int replacementTotal, ref int counter, string findValue, string replaceWithValue, string s)
#pragma warning restore S3776 // Cognitive Complexity of methods should not be too high
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            if (!string.IsNullOrEmpty(findValue))
            {
                if (!string.IsNullOrEmpty(Result) && !DataListUtil.IsValueScalar(Result) && !dataObject.Environment.HasRecordSet(DataListUtil.ExtractRecordsetNameFromValue(Result)))
                {
                    dataObject.Environment.AssignDataShape(Result);
                }

                try
                {
                    var replacementTotalInner = replacementTotal;
                    var errorsInner           = errors;
                    var counterInner          = counter;
                    dataObject.Environment.ApplyUpdate(s, a =>
                    {
                        var replacementCountInner = 0;
                        var replace = replaceOperation.Replace(a.ToString(), findValue, replaceWithValue, CaseMatch, out errorsInner, ref replacementCountInner);
                        if (!string.IsNullOrEmpty(Result) && !DataListUtil.IsValueScalar(Result))
                        {
                            dataObject.Environment.Assign(Result, replacementCountInner.ToString(CultureInfo.InvariantCulture), update == 0 ? counterInner : update);
                        }
                        replacementTotalInner += replacementCountInner;
                        counterInner++;
                        return(DataStorage.WarewolfAtom.NewDataString(replace));
                    }, update);
                    replacementTotal = replacementTotalInner;
                    errors           = errorsInner;
                    counter          = counterInner;
                }
                catch (Exception)
                {
                    replacementCount = 0;
                    var toReplaceIn = dataObject.Environment.Eval(s, update);
                    var a           = ExecutionEnvironment.WarewolfEvalResultToString(toReplaceIn);
                    var replace     = replaceOperation.Replace(a, findValue, replaceWithValue, CaseMatch, out errors, ref replacementCount);
                    if (!string.IsNullOrEmpty(Result) && !DataListUtil.IsValueScalar(Result))
                    {
                        dataObject.Environment.AssignStrict(Result, replacementCount.ToString(CultureInfo.InvariantCulture), update == 0 ? counter : update);
                    }
                    replacementTotal += replacementCount;
                    counter++;
                    dataObject.Environment.AssignStrict(s, replace, update == 0 ? counter : update);
                }
            }
            if (DataListUtil.IsValueScalar(Result))
            {
                dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture), update == 0 ? counter : update);
            }

            if (dataObject.IsDebugMode() && !allErrors.HasErrors() && !string.IsNullOrEmpty(Result) && replacementTotal > 0)
            {
                AddDebugOutputItem(new DebugEvalResult(s, "", dataObject.Environment, update));
            }
        }
コード例 #2
0
        IErrorResultTO TryExecute(IDSFDataObject dataObject, int update, IDev2ReplaceOperation replaceOperation, ref IErrorResultTO errors, IErrorResultTO allErrors, ref int replacementCount, ref int replacementTotal, IList <string> toSearch, IWarewolfListIterator iteratorCollection, WarewolfIterator itrFind, WarewolfIterator itrReplace)
        {
            var counter = 1;

            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)
                {
                    ExecuteEachField(dataObject, update, replaceOperation, ref errors, allErrors, ref replacementCount, ref replacementTotal, ref counter, findValue, replaceWithValue, s);
                }
            }
            return(allErrors);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        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);
                }
            }
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
0
 public void Initialization()
 {
     _dev2ReplaceOperation = Dev2OperationsFactory.CreateReplaceOperation();
 }