Пример #1
0
        private void InsertToCollection(IEnumerable <string> listToAdd, ModelItem modelItem)
        {
            var modelProperty = modelItem.Properties["MergeCollection"];

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

                if (mic != null)
                {
                    List <DataMergeDTO> listOfValidRows = MergeCollection.Where(c => !c.CanRemove()).ToList();
                    if (listOfValidRows.Count > 0)
                    {
                        DataMergeDTO dataMergeDto = MergeCollection.Last(c => !c.CanRemove());
                        int          startIndex   = MergeCollection.IndexOf(dataMergeDto) + 1;
                        foreach (string s in listToAdd)
                        {
                            mic.Insert(startIndex, new DataMergeDTO(s, MergeCollection[startIndex - 1].MergeType, MergeCollection[startIndex - 1].At, startIndex + 1, MergeCollection[startIndex - 1].Padding, MergeCollection[startIndex - 1].Alignment));
                            startIndex++;
                        }
                        CleanUpCollection(mic, modelItem, startIndex);
                    }
                    else
                    {
                        AddToCollection(listToAdd, modelItem);
                    }
                }
            }
        }
Пример #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = base.GetHashCode();
         hashCode = (hashCode * 397) ^ (Result != null ? Result.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (MergeCollection != null ? MergeCollection.GetHashCode() : 0);
         return(hashCode);
     }
 }
Пример #3
0
        public override void UpdateForEachInputs(IList <Tuple <string, string> > updates, NativeActivityContext context)
        {
            if (updates != null)
            {
                foreach (Tuple <string, string> t in updates)
                {
                    // locate all updates for this tuple
                    Tuple <string, string> t1 = t;
                    var items = MergeCollection.Where(c => !string.IsNullOrEmpty(c.InputVariable) && c.InputVariable.Equals(t1.Item1));

                    // issues updates
                    foreach (var a in items)
                    {
                        a.InputVariable = t.Item2;
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Обновляет коллекцию обьединенных элементов блока
 /// </summary>
 private void updateMergeCollection()
 {
     MergeCollection = null;
     Blocks          = Blocks.OrderByDescending(b => b.IdTime.Index).ToList();
     foreach (var block in Blocks)
     {
         var col = block.GetAllCollection();
         if (col.Length > 0)
         {
             if (MergeCollection.NotIsNull())
             {
                 MergeCollection = MergeCollection.Union(col).ToArray();
             }
             else
             {
                 MergeCollection = col;
             }
         }
     }
 }
Пример #5
0
 public int GetCollectionCount()
 {
     return(MergeCollection.Count(caseConvertTo => !caseConvertTo.CanRemove()));
 }
Пример #6
0
        public override IList <DsfForEachItem> GetForEachInputs()
        {
            var items = (MergeCollection.Where(c => !string.IsNullOrEmpty(c.InputVariable)).Select(c => c.InputVariable).Union(MergeCollection.Where(c => !string.IsNullOrEmpty(c.At)).Select(c => c.At))).ToArray();

            return(GetForEachItems(items));
        }
Пример #7
0
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject       dataObject      = context.GetExtension <IDSFDataObject>();
            IDataListCompiler    compiler        = DataListFactory.CreateDataListCompiler();
            IDev2MergeOperations mergeOperations = new Dev2MergeOperations();
            ErrorResultTO        allErrors       = new ErrorResultTO();
            ErrorResultTO        errorResultTo   = new ErrorResultTO();
            Guid executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug    = dataObject.IsDebugMode();
            toUpsert.ResourceID = dataObject.ResourceID;

            InitializeDebug(dataObject);
            try
            {
                CleanArguments(MergeCollection);

                if (MergeCollection.Count <= 0)
                {
                    return;
                }

                IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();


                allErrors.MergeErrors(errorResultTo);
                Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >();

                #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data

                int dictionaryKey = 0;
                foreach (DataMergeDTO row in MergeCollection)
                {
                    IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    var fieldName        = row.InputVariable;
                    var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName);
                    var datalist         = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString();
                    if (!string.IsNullOrEmpty(datalist))
                    {
                        foreach (var region in splitIntoRegions)
                        {
                            var r           = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region;
                            var isValidExpr = new IsValidExpressionRule(() => r, datalist)
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                row.InputVariable = "";
                                errorResultTo.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errorResultTo);
                        }
                    }

                    allErrors.MergeErrors(errorResultTo);

                    if (dataObject.IsDebugMode())
                    {
                        DebugItem debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem);
                        AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem);

                        //Old workflows don't have this set.
                        if (row.Alignment == null)
                        {
                            row.Alignment = string.Empty;
                        }

                        AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem);

                        _debugInputs.Add(debugItem);
                    }

                    IDev2DataListEvaluateIterator itr    = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry);
                    IDev2DataListEvaluateIterator atItr  = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry);
                    IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry);

                    iteratorCollection.AddIterator(itr);
                    iteratorCollection.AddIterator(atItr);
                    iteratorCollection.AddIterator(padItr);

                    listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> {
                        itr, atItr, padItr
                    });
                    dictionaryKey++;
                }

                #endregion

                #region Iterate and Merge Data
                if (!allErrors.HasErrors())
                {
                    while (iteratorCollection.HasMoreData())
                    {
                        int pos = 0;
                        foreach (var iterator in listOfIterators)
                        {
                            var val = iteratorCollection.FetchNextRow(iterator.Value[0]);
                            var at  = iteratorCollection.FetchNextRow(iterator.Value[1]);
                            var pad = iteratorCollection.FetchNextRow(iterator.Value[2]);

                            if (val != null)
                            {
                                if (at != null)
                                {
                                    if (pad != null)
                                    {
                                        if (MergeCollection[pos].MergeType == "Index")
                                        {
                                            if (string.IsNullOrEmpty(at.TheValue))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }

                                            int atValue;
                                            if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0)
                                            {
                                                allErrors.AddError("The 'Using' value must be a real number.");
                                            }
                                            if (pad.TheValue.Length > 1)
                                            {
                                                allErrors.AddError("'Padding' must be a single character");
                                            }
                                        }
                                        else
                                        {
                                            if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }
                                        }
                                        mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment);
                                        pos++;
                                    }
                                }
                            }
                        }
                    }
                    if (!allErrors.HasErrors())
                    {
                        if (string.IsNullOrEmpty(Result))
                        {
                            AddDebugOutputItem(new DebugItemStaticDataParams("", ""));
                        }
                        else
                        {
                            var rule   = new IsSingleValueRule(() => Result);
                            var single = rule.Check();
                            if (single != null)
                            {
                                allErrors.AddError(single.Message);
                            }
                            else
                            {
                                toUpsert.Add(Result, mergeOperations.MergeData.ToString());
                                toUpsert.FlushIterationFrame();
                                compiler.Upsert(executionId, toUpsert, out errorResultTo);
                                allErrors.MergeErrors(errorResultTo);

                                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                                {
                                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                                    {
                                        if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null)
                                        {
                                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion Iterate and Merge Data
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDataMerge", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors

                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfDataMergeActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo);
                    compiler.Upsert(executionId, Result, (string)null, out errorResultTo);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }

                #endregion
            }
        }
Пример #8
0
        private void TryExecuteTool(IDSFDataObject dataObject, int update, IDev2MergeOperations mergeOperations, ErrorResultTO allErrors, ErrorResultTO errorResultTo)
        {
            IWarewolfListIterator warewolfListIterator = new WarewolfListIterator();

            allErrors.MergeErrors(errorResultTo);
            var listOfIterators = new Dictionary <int, List <IWarewolfIterator> >();

            #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data

            var dictionaryKey = 0;
            foreach (DataMergeDTO row in MergeCollection)
            {
                allErrors.MergeErrors(errorResultTo);

                if (dataObject.IsDebugMode())
                {
                    var debugItem = new DebugItem();
                    AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem);
                    AddDebugItem(new DebugEvalResult(row.InputVariable, "", dataObject.Environment, update, true), debugItem);
                    AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem);
                    AddDebugItem(new DebugEvalResult(row.At, "Using", dataObject.Environment, update), debugItem);
                    AddDebugItem(new DebugEvalResult(row.Padding, "Pad", dataObject.Environment, update), debugItem);

                    //Old workflows don't have this set.
                    if (row.Alignment == null)
                    {
                        row.Alignment = string.Empty;
                    }

                    AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem);

                    _debugInputs.Add(debugItem);
                }
                var listOfEvalResultsForInput = dataObject.Environment.EvalForDataMerge(row.InputVariable, update);
                var innerIterator             = new WarewolfListIterator();
                var innerListOfIters          = new List <WarewolfIterator>();

                foreach (var listOfIterator in listOfEvalResultsForInput)
                {
                    var inIterator = new WarewolfIterator(listOfIterator);
                    innerIterator.AddVariableToIterateOn(inIterator);
                    innerListOfIters.Add(inIterator);
                }
                var atomList = new List <DataStorage.WarewolfAtom>();
                while (innerIterator.HasMoreData())
                {
                    var stringToUse = "";
                    foreach (var warewolfIterator in innerListOfIters)
                    {
                        stringToUse += warewolfIterator.GetNextValue();
                    }
                    atomList.Add(DataStorage.WarewolfAtom.NewDataString(stringToUse));
                }
                var finalString     = string.Join("", atomList);
                var inputListResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomListresult(new WarewolfAtomList <DataStorage.WarewolfAtom>(DataStorage.WarewolfAtom.Nothing, atomList));
                if (DataListUtil.IsFullyEvaluated(finalString))
                {
                    inputListResult = dataObject.Environment.Eval(finalString, update);
                }

                var inputIterator   = new WarewolfIterator(inputListResult);
                var atIterator      = new WarewolfIterator(dataObject.Environment.Eval(row.At, update));
                var paddingIterator = new WarewolfIterator(dataObject.Environment.Eval(row.Padding, update));
                warewolfListIterator.AddVariableToIterateOn(inputIterator);
                warewolfListIterator.AddVariableToIterateOn(atIterator);
                warewolfListIterator.AddVariableToIterateOn(paddingIterator);

                listOfIterators.Add(dictionaryKey, new List <IWarewolfIterator> {
                    inputIterator, atIterator, paddingIterator
                });
                dictionaryKey++;
            }

            #endregion

            #region Iterate and Merge Data

            if (!allErrors.HasErrors())
            {
                while (warewolfListIterator.HasMoreData())
                {
                    var pos = 0;
                    foreach (var iterator in listOfIterators)
                    {
                        var val = warewolfListIterator.FetchNextValue(iterator.Value[0]);
                        var at  = warewolfListIterator.FetchNextValue(iterator.Value[1]);
                        var pad = warewolfListIterator.FetchNextValue(iterator.Value[2]);
                        pos = AddErrorAndMerge(mergeOperations, allErrors, pos, val, at, pad);
                    }
                }
                if (!allErrors.HasErrors())
                {
                    if (string.IsNullOrEmpty(Result))
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", ""));
                    }
                    else
                    {
                        AddToErrorsToDebugOutput(dataObject, update, mergeOperations, allErrors, errorResultTo);
                    }
                }
            }

            #endregion Iterate and Merge Data
        }
Пример #9
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            IDev2MergeOperations mergeOperations = new Dev2MergeOperations();
            ErrorResultTO        allErrors       = new ErrorResultTO();
            ErrorResultTO        errorResultTo   = new ErrorResultTO();

            InitializeDebug(dataObject);
            try
            {
                CleanArguments(MergeCollection);

                if (MergeCollection.Count <= 0)
                {
                    return;
                }
                IWarewolfListIterator warewolfListIterator = new WarewolfListIterator();
                allErrors.MergeErrors(errorResultTo);
                Dictionary <int, List <IWarewolfIterator> > listOfIterators = new Dictionary <int, List <IWarewolfIterator> >();

                #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data

                int dictionaryKey = 0;
                foreach (DataMergeDTO row in MergeCollection)
                {
                    allErrors.MergeErrors(errorResultTo);

                    if (dataObject.IsDebugMode())
                    {
                        DebugItem debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugEvalResult(row.InputVariable, "", dataObject.Environment, update, true), debugItem);
                        AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem);
                        AddDebugItem(new DebugEvalResult(row.At, "Using", dataObject.Environment, update), debugItem);
                        AddDebugItem(new DebugEvalResult(row.Padding, "Pad", dataObject.Environment, update), debugItem);

                        //Old workflows don't have this set.
                        if (row.Alignment == null)
                        {
                            row.Alignment = string.Empty;
                        }

                        AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem);

                        _debugInputs.Add(debugItem);
                    }
                    var listOfEvalResultsForInput = dataObject.Environment.EvalForDataMerge(row.InputVariable, update);
                    var innerIterator             = new WarewolfListIterator();
                    var innerListOfIters          = new List <WarewolfIterator>();

                    foreach (var listOfIterator in listOfEvalResultsForInput)
                    {
                        var inIterator = new WarewolfIterator(listOfIterator);
                        innerIterator.AddVariableToIterateOn(inIterator);
                        innerListOfIters.Add(inIterator);
                    }
                    var atomList = new List <DataASTMutable.WarewolfAtom>();
                    while (innerIterator.HasMoreData())
                    {
                        var stringToUse = "";
                        foreach (var warewolfIterator in innerListOfIters)
                        {
                            stringToUse += warewolfIterator.GetNextValue();
                        }
                        atomList.Add(DataASTMutable.WarewolfAtom.NewDataString(stringToUse));
                    }
                    var finalString     = string.Join("", atomList);
                    var inputListResult = WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomListresult(new WarewolfAtomList <DataASTMutable.WarewolfAtom>(DataASTMutable.WarewolfAtom.Nothing, atomList));
                    if (DataListUtil.IsFullyEvaluated(finalString))
                    {
                        inputListResult = dataObject.Environment.Eval(finalString, update);
                    }

                    var inputIterator   = new WarewolfIterator(inputListResult);
                    var atIterator      = new WarewolfIterator(dataObject.Environment.Eval(row.At, update));
                    var paddingIterator = new WarewolfIterator(dataObject.Environment.Eval(row.Padding, update));
                    warewolfListIterator.AddVariableToIterateOn(inputIterator);
                    warewolfListIterator.AddVariableToIterateOn(atIterator);
                    warewolfListIterator.AddVariableToIterateOn(paddingIterator);

                    listOfIterators.Add(dictionaryKey, new List <IWarewolfIterator> {
                        inputIterator, atIterator, paddingIterator
                    });
                    dictionaryKey++;
                }

                #endregion

                #region Iterate and Merge Data

                if (!allErrors.HasErrors())
                {
                    while (warewolfListIterator.HasMoreData())
                    {
                        int pos = 0;
                        foreach (var iterator in listOfIterators)
                        {
                            var val = warewolfListIterator.FetchNextValue(iterator.Value[0]);
                            var at  = warewolfListIterator.FetchNextValue(iterator.Value[1]);
                            var pad = warewolfListIterator.FetchNextValue(iterator.Value[2]);

                            if (val != null)
                            {
                                if (at != null)
                                {
                                    if (pad != null)
                                    {
                                        if (MergeCollection[pos].MergeType == "Index")
                                        {
                                            if (string.IsNullOrEmpty(at))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }

                                            int atValue;
                                            if (!Int32.TryParse(at, out atValue) || atValue < 0)
                                            {
                                                allErrors.AddError("The 'Using' value must be a real number.");
                                            }
                                            if (pad.Length > 1)
                                            {
                                                allErrors.AddError("'Padding' must be a single character");
                                            }
                                        }
                                        else
                                        {
                                            if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }
                                        }
                                        mergeOperations.Merge(val, MergeCollection[pos].MergeType, at, pad, MergeCollection[pos].Alignment);
                                        pos++;
                                    }
                                }
                            }
                        }
                    }
                    if (!allErrors.HasErrors())
                    {
                        if (string.IsNullOrEmpty(Result))
                        {
                            AddDebugOutputItem(new DebugItemStaticDataParams("", ""));
                        }
                        else
                        {
                            dataObject.Environment.Assign(Result, mergeOperations.MergeData.ToString(), update);
                            allErrors.MergeErrors(errorResultTo);

                            if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                            {
                                AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update));
                            }
                        }
                    }
                }

                #endregion Iterate and Merge Data
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDataMerge", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors

                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfDataMergeActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }

                #endregion
            }
        }