Ejemplo n.º 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (FieldsToSearch != null ? FieldsToSearch.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Find != null ? Find.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ReplaceWith != null ? ReplaceWith.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ CaseMatch.GetHashCode();
         hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0);
         return(hashCode);
     }
 }
Ejemplo n.º 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (FieldsToSearch != null ? FieldsToSearch.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (StartIndex != null ? StartIndex.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ MatchCase.GetHashCode();
         hashCode = (hashCode * 397) ^ RequireAllTrue.GetHashCode();
         hashCode = (hashCode * 397) ^ RequireAllFieldsToMatch.GetHashCode();
         hashCode = (hashCode * 397) ^ (ResultsCollection != null ? ResultsCollection.GetHashCode() : 0);
         return(hashCode);
     }
 }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var env = dataObject.Environment;

            InitializeDebug(dataObject);
            var allErrors = new ErrorResultTO();

            try
            {
                IList <string> toSearch     = FieldsToSearch.Split(',').Select(a => a.Trim()).ToList();
                var            scalarValues = toSearch.Where(DataListUtil.IsValueScalar).ToList();
                if (scalarValues.Any())
                {
                    throw new Exception("Scalars are not allowed. Please check the following:" + Environment.NewLine + string.Join(Environment.NewLine, scalarValues));
                }
                List <int> results = new List <int>();
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputValues(dataObject, toSearch, ref allErrors, update);
                }

                bool hasEvaled = false;
                foreach (var searchvar in toSearch)
                {
                    Func <DataASTMutable.WarewolfAtom, bool> func = null;
                    foreach (FindRecordsTO to in ResultsCollection.Where(a => !String.IsNullOrEmpty(a.SearchType)))
                    {
                        if (to.From.Length > 0 && String.IsNullOrEmpty(to.To) ||
                            to.To.Length > 0 && String.IsNullOrEmpty(to.From))
                        {
                            throw new Exception("From and to Must be populated");
                        }
                        ValidateRequiredFields(to, out errorsTo);
                        var right = env.EvalAsList(to.SearchCriteria, update);
                        IEnumerable <DataASTMutable.WarewolfAtom> from    = new List <DataASTMutable.WarewolfAtom>();
                        IEnumerable <DataASTMutable.WarewolfAtom> tovalue = new List <DataASTMutable.WarewolfAtom>();

                        if (!String.IsNullOrEmpty(to.From))
                        {
                            @from = env.EvalAsList(to.From, update);
                        }
                        if (!String.IsNullOrEmpty(to.To))
                        {
                            tovalue = env.EvalAsList(to.To, update);
                        }
                        if (func == null)
                        {
                            func = CreateFuncFromOperator(to.SearchType, right, @from, tovalue);
                        }
                        else
                        {
                            func = RequireAllTrue ? CombineFuncAnd(func, to.SearchType, right, @from, tovalue) : CombineFuncOr(func, to.SearchType, right, @from, tovalue);
                        }
                    }
                    var output = env.EnvalWhere(dataObject.Environment.ToStar(searchvar), func, update);

                    if (RequireAllFieldsToMatch && hasEvaled)
                    {
                        results = results.Intersect(output).ToList();
                    }
                    else
                    {
                        results = results.Union(output).ToList();
                    }
                    hasEvaled = true;
                }
                if (!results.Any())
                {
                    results.Add(-1);
                }
                var res = String.Join(",", results.Distinct());
                env.Assign(Result, res, update);
                if (dataObject.IsDebugMode())
                {
                    AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                }
            }
            catch (Exception exception)
            {
                Dev2Logger.Log.Error("DSFRecordsMultipleCriteria", exception);
                allErrors.AddError(exception.Message);
            }
            finally
            {
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfFindRecordsMultipleCriteriaActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                    dataObject.Environment.Assign(Result, "-1", update);
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                    }
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 7
0
        // ReSharper restore RedundantOverridenMember

        /// <summary>
        /// Executes the logic of the activity and calls the backend code to do the work
        /// Also responsible for adding the results to the data list
        /// </summary>
        /// <param name="context"></param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            ErrorResultTO     errors;
            ErrorResultTO     allErrors = new ErrorResultTO();
            Guid executionId            = dataObject.DataListID;

            InitializeDebug(dataObject);
            try
            {
                IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors);
                // Fetch all fields to search....
                IList <string> toSearch = FieldsToSearch.Split(',');
                // now process each field for entire evaluated Where expression....
                IBinaryDataListEntry bdle = compiler.Evaluate(executionId, enActionType.User, SearchCriteria, false, out errors);
                if (dataObject.IsDebugMode())
                {
                    var itemToAdd = new DebugItem();
                    itemToAdd.Add(new DebugItemResult {
                        Type = DebugItemResultType.Label, Value = "Fields To Search"
                    });
                    _debugInputs.Add(itemToAdd);
                }
                allErrors.MergeErrors(errors);

                if (bdle != null)
                {
                    IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(bdle);
                    IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                    int idx;
                    if (!Int32.TryParse(StartIndex, out idx))
                    {
                        idx = 1;
                    }
                    IBinaryDataList toSearchList = compiler.FetchBinaryDataList(executionId, out errors);
                    allErrors.MergeErrors(errors);
                    int iterationIndex = 0;
                    foreach (string s in toSearch)
                    {
                        if (dataObject.IsDebugMode())
                        {
                            IBinaryDataListEntry tmpEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors);
                            AddDebugInputItem(s, string.Empty, tmpEntry, executionId);
                        }
                        // each entry in the recordset
                        while (itr.HasMoreRecords())
                        {
                            IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                            foreach (IBinaryDataListItem c in cols)
                            {
                                IRecsetSearch  searchTo = ConvertToSearchTo(c.TheValue, idx.ToString(CultureInfo.InvariantCulture));
                                IList <string> results  = RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errors);
                                allErrors.MergeErrors(errors);
                                string concatRes = string.Empty;

                                // ReSharper disable LoopCanBeConvertedToQuery
                                foreach (string r in results)
                                // ReSharper restore LoopCanBeConvertedToQuery
                                {
                                    concatRes = string.Concat(concatRes, r, ",");
                                }

                                if (concatRes.EndsWith(","))
                                {
                                    concatRes = concatRes.Remove(concatRes.Length - 1);
                                }
                                //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                                DataListCleaningUtils.SplitIntoRegions(Result);
                                //2013.06.07: Massimo Guerrera for BUG 9497 - To handle putting out to a scalar as a CSV

                                if (!DataListUtil.IsValueRecordset(Result))
                                {
                                    toUpsert.Add(Result, concatRes);
                                    toUpsert.FlushIterationFrame();
                                    if (dataObject.IsDebugMode())
                                    {
                                        AddDebugOutputItem(new DebugOutputParams(Result, concatRes, executionId, iterationIndex));
                                    }
                                }
                                else
                                {
                                    iterationIndex = 0;

                                    foreach (string r in results)
                                    {
                                        toUpsert.Add(Result, r);
                                        toUpsert.FlushIterationFrame();
                                        if (dataObject.IsDebugMode())
                                        {
                                            AddDebugOutputItem(new DebugOutputParams(Result, r, executionId, iterationIndex));
                                        }

                                        iterationIndex++;
                                    }
                                }
                            }
                        }
                    }

                    if (dataObject.IsDebugMode())
                    {
                        AddDebugInputItem(SearchCriteria, "Where", bdle, executionId);
                    }

                    // now push the result to the server
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                }
            }
            finally
            {
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfFindRecordsActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 8
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>();
            var compiler      = DataListFactory.CreateDataListCompiler();
            var dataObject    = context.GetExtension <IDSFDataObject>();
            var errorResultTo = new ErrorResultTO();
            var allErrors     = new ErrorResultTO();
            var executionId   = dataObject.DataListID;

            InitializeDebug(dataObject);


            int iterationIndex;

            try
            {
                IList <string> toSearch = FieldsToSearch.Split(',');
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputValues(dataObject, toSearch, compiler, executionId, ref errorResultTo);
                }

                allErrors.MergeErrors(errorResultTo);
                IEnumerable <string> results = new List <string>();
                var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                toUpsert.IsDebug = dataObject.IsDebugMode();
                bool isFirstIteration = true;
                // ReSharper disable ForCanBeConvertedToForeach
                for (var i = 0; i < ResultsCollection.Count; i++)
                // ReSharper restore ForCanBeConvertedToForeach
                {
                    IEnumerable <string> resultsDuringSearch = new List <string>();
                    var currenSearchResults = new List <string>();
                    IDev2IteratorCollection itrCollection = Dev2ValueObjectFactory.CreateIteratorCollection();

                    IBinaryDataListEntry          binaryDataListEntrySearchCrit = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].SearchCriteria, false, out errorResultTo);
                    IDev2DataListEvaluateIterator searchCritItr = Dev2ValueObjectFactory.CreateEvaluateIterator(binaryDataListEntrySearchCrit);
                    itrCollection.AddIterator(searchCritItr);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry          binaryDataListEntryFrom = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].From, false, out errorResultTo);
                    IDev2DataListEvaluateIterator fromItr = Dev2ValueObjectFactory.CreateEvaluateIterator(binaryDataListEntryFrom);
                    itrCollection.AddIterator(fromItr);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry          binaryDataListEntryTo = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].To, false, out errorResultTo);
                    IDev2DataListEvaluateIterator toItr = Dev2ValueObjectFactory.CreateEvaluateIterator(binaryDataListEntryTo);
                    itrCollection.AddIterator(toItr);
                    allErrors.MergeErrors(errorResultTo);

                    int idx;
                    if (!Int32.TryParse(StartIndex, out idx))
                    {
                        idx = 1;
                    }
                    var toSearchList = compiler.FetchBinaryDataList(executionId, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);



                    var searchType = ResultsCollection[i].SearchType;
                    if (string.IsNullOrEmpty(searchType))
                    {
                        continue;
                    }
                    // ReSharper disable PossibleMultipleEnumeration
                    while (itrCollection.HasMoreData())
                    {
                        var currentResults = results as IList <string> ?? results.ToList();

                        var splitOn        = new[] { "," };
                        var fieldsToSearch = FieldsToSearch.Split(splitOn, StringSplitOptions.RemoveEmptyEntries);

                        SearchTO searchTo;

                        if (fieldsToSearch.Length > 0)
                        {
                            bool isFirstFieldIteration = true;
                            foreach (var field in fieldsToSearch)
                            {
                                IList <string> iterationResults = new List <string>();
                                searchTo = DataListFactory.CreateSearchTO(field, searchType,
                                                                          itrCollection.FetchNextRow(searchCritItr)
                                                                          .TheValue,
                                                                          idx.ToString(CultureInfo.InvariantCulture),
                                                                          Result, MatchCase,
                                                                          false,
                                                                          itrCollection.FetchNextRow(fromItr).TheValue,
                                                                          itrCollection.FetchNextRow(toItr).TheValue);
                                ValidateRequiredFields(searchTo, out errorResultTo);
                                allErrors.MergeErrors(errorResultTo);
                                // ReSharper disable ConvertClosureToMethodGroup
                                (RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errorResultTo)).ToList().ForEach(it => iterationResults.Add(it));
                                // ReSharper restore ConvertClosureToMethodGroup

                                if (RequireAllFieldsToMatch)
                                {
                                    resultsDuringSearch = isFirstFieldIteration ? iterationResults : currenSearchResults.Intersect(iterationResults);
                                    currenSearchResults = resultsDuringSearch.ToList();
                                }
                                else
                                {
                                    resultsDuringSearch = currenSearchResults.Union(iterationResults);
                                    currenSearchResults = RequireAllTrue ? new List <string>() : resultsDuringSearch.ToList();
                                }
                                isFirstFieldIteration = false;
                            }
                        }
                        else
                        {
                            searchTo = (SearchTO)ConvertToSearchTO(itrCollection.FetchNextRow(searchCritItr).TheValue,
                                                                   searchType, idx.ToString(CultureInfo.InvariantCulture),
                                                                   itrCollection.FetchNextRow(fromItr).TheValue,
                                                                   itrCollection.FetchNextRow(toItr).TheValue);

                            ValidateRequiredFields(searchTo, out errorResultTo);
                            allErrors.MergeErrors(errorResultTo);
                            resultsDuringSearch = RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errorResultTo);
                        }

                        allErrors.MergeErrors(errorResultTo);

                        if (RequireAllTrue)
                        {
                            results = isFirstIteration ? resultsDuringSearch : currentResults.Intersect(resultsDuringSearch);
                        }
                        else
                        {
                            results = currentResults.Union(resultsDuringSearch);
                        }
                        isFirstIteration = false;
                    }
                }

                DataListCleaningUtils.SplitIntoRegions(Result);
                var rule           = new IsSingleValueRule(() => Result);
                var singleresError = rule.Check();
                if (singleresError != null)
                {
                    allErrors.AddError(singleresError.Message);
                }
                else
                {
                    string concatRes  = String.Empty;
                    var    allResults = results as IList <string> ?? results.ToList();
                    // ReSharper restore PossibleMultipleEnumeration
                    if (allResults.Count == 0)
                    {
                        allResults.Add("-1");
                    }

                    if (!DataListUtil.IsValueRecordset(Result))
                    {
                        // ReSharper disable LoopCanBeConvertedToQuery
                        foreach (var r in allResults)
                        // ReSharper restore LoopCanBeConvertedToQuery
                        {
                            concatRes = string.Concat(concatRes, r, ",");
                        }

                        if (concatRes.EndsWith(","))
                        {
                            concatRes = concatRes.Remove(concatRes.Length - 1);
                        }
                        toUpsert.Add(Result, concatRes);
                        toUpsert.FlushIterationFrame();
                    }
                    else
                    {
                        iterationIndex = 0;

                        foreach (var r in allResults)
                        {
                            toUpsert.Add(Result, r);
                            toUpsert.FlushIterationFrame();
                            iterationIndex++;
                        }
                    }
                    compiler.Upsert(executionId, toUpsert, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        foreach (var debugTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugTo));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Dev2Logger.Log.Error("DSFRecordsMultipleCriteria", exception);
                allErrors.AddError(exception.Message);
            }
            finally
            {
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfFindRecordsMultipleCriteriaActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo);
                    compiler.Upsert(executionId, Result, (string)null, out errorResultTo);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        iterationIndex = 0;
                        var regions = DataListCleaningUtils.SplitIntoRegions(Result);
                        foreach (var region in regions)
                        {
                            AddDebugOutputItem(new DebugOutputParams(region, "", executionId, iterationIndex));
                            iterationIndex++;
                        }
                    }

                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }