示例#1
0
        private void InsertToCollection(IEnumerable <string> listToAdd, ModelItem modelItem)
        {
            var modelProperty = modelItem.Properties["ResultsCollection"];

            if (modelProperty != null)
            {
                ModelItemCollection mic = modelProperty.Collection;

                if (mic != null)
                {
                    List <DataSplitDTO> listOfValidRows = ResultsCollection.Where(c => !c.CanRemove()).ToList();
                    if (listOfValidRows.Count > 0)
                    {
                        DataSplitDTO dataSplitDto = ResultsCollection.Last(c => !c.CanRemove());
                        int          startIndex   = ResultsCollection.IndexOf(dataSplitDto) + 1;
                        foreach (string s in listToAdd)
                        {
                            mic.Insert(startIndex, new DataSplitDTO(s, ResultsCollection[startIndex - 1].SplitType, ResultsCollection[startIndex - 1].At, startIndex + 1));
                            startIndex++;
                        }
                        CleanUpCollection(mic, modelItem, startIndex);
                    }
                    else
                    {
                        AddToCollection(listToAdd, modelItem);
                    }
                }
            }
        }
        void InsertToCollection(IEnumerable <string> listToAdd, ModelItem modelItem)
        {
            var modelProperty = modelItem.Properties["ResultsCollection"];

            if (modelProperty == null)
            {
                return;
            }
            var mic = modelProperty.Collection;

            if (mic == null)
            {
                return;
            }
            var listOfValidRows = ResultsCollection.Where(c => !c.CanRemove()).ToList();

            if (listOfValidRows.Count > 0)
            {
                FindRecordsTO findRecordsTo = ResultsCollection.Last(c => !c.CanRemove());
                var           startIndex    = ResultsCollection.IndexOf(findRecordsTo) + 1;
                foreach (var s in listToAdd)
                {
                    mic.Insert(startIndex, new FindRecordsTO(s, ResultsCollection[startIndex - 1].SearchType, startIndex + 1));
                    startIndex++;
                }
                CleanUpCollection(mic, modelItem, startIndex);
            }
            else
            {
                AddToCollection(listToAdd, modelItem);
            }
        }
示例#3
0
        public override void UpdateForEachOutputs(IList <Tuple <string, string> > updates)
        {
            if (updates != null)
            {
                foreach (Tuple <string, string> t in updates)
                {
                    // locate all updates for this tuple
                    Tuple <string, string> t1 = t;
                    var items = ResultsCollection.Where(c => !string.IsNullOrEmpty(c.OutputVariable) && c.OutputVariable.Equals(t1.Item1));

                    // issues updates
                    foreach (var a in items)
                    {
                        a.OutputVariable = t.Item2;
                    }
                }
            }
        }
        public override void UpdateForEachInputs(IList <Tuple <string, string> > updates)
        {
            if (updates != null)
            {
                foreach (Tuple <string, string> t in updates)
                {
                    // locate all updates for this tuple
                    Tuple <string, string> t1 = t;
                    var items = ResultsCollection.Where(c => !string.IsNullOrEmpty(c.SearchCriteria) && c.SearchCriteria.Equals(t1.Item1));

                    // issues updates
                    foreach (var a in items)
                    {
                        a.SearchCriteria = t.Item2;
                    }

                    if (FieldsToSearch == t.Item1)
                    {
                        FieldsToSearch = t.Item2;
                    }
                }
            }
        }
示例#5
0
        public override void UpdateForEachInputs(IList <Tuple <string, string> > updates)
        {
            if (updates != null)
            {
                foreach (Tuple <string, string> t in updates)
                {
                    // locate all updates for this tuple
                    var t1    = t;
                    var items = ResultsCollection.Where(c => !string.IsNullOrEmpty(c.XPath) && c.XPath.Equals(t1.Item1));

                    // issues updates
                    foreach (var a in items)
                    {
                        a.XPath = t.Item2;
                    }

                    if (SourceString == t.Item1)
                    {
                        SourceString = t.Item2;
                    }
                }
            }
        }
        public override IList <DsfForEachItem> GetForEachInputs()
        {
            var items = new[] { FieldsToSearch }.Union(ResultsCollection.Where(c => !string.IsNullOrEmpty(c.SearchCriteria)).Select(c => c.SearchCriteria)).ToArray();

            return(GetForEachItems(items));
        }
        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);
                }
            }
        }
示例#8
0
        public override IList <DsfForEachItem> GetForEachOutputs()
        {
            var items = ResultsCollection.Where(c => !string.IsNullOrEmpty(c.OutputVariable)).Select(c => c.OutputVariable).ToArray();

            return(GetForEachItems(items));
        }
示例#9
0
        public override IList <DsfForEachItem> GetForEachInputs()
        {
            var items = new[] { SourceString }.Union(ResultsCollection.Where(c => !string.IsNullOrEmpty(c.At)).Select(c => c.At)).ToArray();

            return(GetForEachItems(items));
        }