Ejemplo n.º 1
0
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugOutputs.Clear();

            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder();

            _isDebugMode        = dataObject.IsDebugMode();
            toUpsert.IsDebug    = _isDebugMode;
            toUpsert.ResourceID = dataObject.ResourceID;
            ErrorResultTO errors      = new ErrorResultTO();
            ErrorResultTO allErrors   = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);
            XPathParser   parser      = new XPathParser();
            int           i           = 0;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, SourceString, false, out errors);

                    if (_isDebugMode)
                    {
                        AddSourceStringDebugInputItem(SourceString, expressionsEntry, executionId);
                        AddResultDebugInputs(ResultsCollection, executionId, compiler, out errors);
                        allErrors.MergeErrors(errors);
                    }
                    if (!allErrors.HasErrors())
                    {
                        IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                        while (itr.HasMoreRecords())
                        {
                            IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                            foreach (IBinaryDataListItem c in cols)
                            {
                                for (i = 0; i < ResultsCollection.Count; i++)
                                {
                                    if (!string.IsNullOrEmpty(ResultsCollection[i].OutputVariable))
                                    {
                                        IBinaryDataListEntry          xpathEntry = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].XPath, false, out errors);
                                        IDev2DataListEvaluateIterator xpathItr   = Dev2ValueObjectFactory.CreateEvaluateIterator(xpathEntry);
                                        while (xpathItr.HasMoreRecords())
                                        {
                                            IList <IBinaryDataListItem> xpathCols = xpathItr.FetchNextRowData();
                                            foreach (IBinaryDataListItem xPathCol in xpathCols)
                                            {
                                                try
                                                {
                                                    List <string> eval = parser.ExecuteXPath(c.TheValue, xPathCol.TheValue).ToList();

                                                    //2013.06.03: Ashley Lewis for bug 9498 - handle line breaks in multi assign
                                                    string[] openParts  = Regex.Split(ResultsCollection[i].OutputVariable, @"\[\[");
                                                    string[] closeParts = Regex.Split(ResultsCollection[i].OutputVariable, @"\]\]");
                                                    if (openParts.Count() == closeParts.Count() && openParts.Count() > 2 && closeParts.Count() > 2)
                                                    {
                                                        foreach (var newFieldName in openParts)
                                                        {
                                                            if (!string.IsNullOrEmpty(newFieldName))
                                                            {
                                                                string cleanFieldName;
                                                                if (newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2 < newFieldName.Length)
                                                                {
                                                                    cleanFieldName = "[[" + newFieldName.Remove(newFieldName.IndexOf("]]", StringComparison.Ordinal) + 2);
                                                                }
                                                                else
                                                                {
                                                                    cleanFieldName = "[[" + newFieldName;
                                                                }
                                                                toUpsert.Add(cleanFieldName, eval);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        toUpsert.Add(ResultsCollection[i].OutputVariable, eval);
                                                    }
                                                }
                                                catch (Exception)
                                                {
                                                    toUpsert.Add(ResultsCollection[i].OutputVariable, null);
                                                }
                                            }
                                        }
                                    }
                                }
                                compiler.Upsert(executionId, toUpsert, out errors);
                            }

                            allErrors.MergeErrors(errors);
                        }
                    }
                    if (_isDebugMode && !allErrors.HasErrors())
                    {
                        var innerCount = 1;
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugItemVariableParams(debugOutputTo), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                            innerCount++;
                        }
                        toUpsert.DebugOutputs.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                allErrors.AddError(ex.Message);
            }
            finally
            {
                // Handle Errors

                var actualIndex = i - 1;
                var hasErrors   = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfXPathActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, ResultsCollection[actualIndex].OutputVariable, (string)null, out errors);
                }
                if (_isDebugMode)
                {
                    if (hasErrors)
                    {
                        if (_isDebugMode)
                        {
                            ResultsCollection[actualIndex].XPath = "";
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", (actualIndex + 1).ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugOutputParams(ResultsCollection[actualIndex].OutputVariable, "", executionId, actualIndex + 1), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 2
0
        // ReSharper restore RedundantOverridenMember


        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            _indexCounter = 0;
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false);

            InitializeDebug(dataObject);

            try
            {
                CleanArgs();

                toUpsert.IsDebug = dataObject.IsDebugMode();

                foreach (var item in ConvertCollection)
                {
                    try
                    {
                        _indexCounter++;
                        // Travis.Frisinger - This needs to be in the ViewModel not here ;)
                        if (item.ToExpression == string.Empty)
                        {
                            item.ToExpression = item.FromExpression;
                        }
                        IsSingleValueRule.ApplyIsSingleValueRule(item.FromExpression, allErrors);
                        var fieldName = item.FromExpression;
                        fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName;
                        var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors);
                        if (!datalist.IsNullOrEmpty())
                        {
                            var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist.ToString())
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                item.FromExpression = "";
                                errors.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errors);
                        }

                        IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.FromExpression, false, out errors);
                        if (dataObject.IsDebugMode())
                        {
                            AddDebugInputItem(item.FromExpression, tmp, executionId, item.FromType, item.ToType);
                        }
                        allErrors.MergeErrors(errors);
                        if (tmp != null)
                        {
                            IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp);

                            IBaseConverter        from   = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType)));
                            IBaseConverter        to     = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType)));
                            IBaseConversionBroker broker = _fac.CreateBroker(from, to);

                            // process result information
                            while (itr.HasMoreRecords())
                            {
                                IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                                foreach (IBinaryDataListItem c in cols)
                                {
                                    // set up live flushing iterator details
                                    if (c.IsDeferredRead)
                                    {
                                        if (toUpsert != null)
                                        {
                                            toUpsert.HasLiveFlushing      = true;
                                            toUpsert.LiveFlushingLocation = executionId;
                                        }
                                    }

                                    int indexToUpsertTo = c.ItemCollectionIndex;

                                    string val        = string.IsNullOrEmpty(c.TheValue) ? "" : broker.Convert(c.TheValue);
                                    string expression = item.ToExpression;

                                    if (DataListUtil.IsValueRecordset(item.ToExpression) && DataListUtil.GetRecordsetIndexType(item.ToExpression) == enRecordsetIndexType.Star)
                                    {
                                        expression = item.ToExpression.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                                    }
                                    toUpsert.Add(expression, val);
                                    if (toUpsert != null && toUpsert.HasLiveFlushing)
                                    {
                                        toUpsert.FlushIterationFrame();
                                        toUpsert = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                    finally
                    {
                        if (allErrors.HasErrors())
                        {
                            toUpsert.Add(item.ToExpression, null);
                        }
                    }
                }

                if (toUpsert != null && toUpsert.HasLiveFlushing)
                {
                    try
                    {
                        toUpsert.FlushIterationFrame();
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                }
                else
                {
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                }

                if (!allErrors.HasErrors() && toUpsert != null)
                {
                    var outIndex = 1;
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem);
                        _debugOutputs.Add(debugItem);
                        outIndex++;
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFBaseConvert", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfBaseConvertActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
        public IDev2DataListUpsertPayloadBuilder <string> Replace(Guid exIdx, string expression, string oldString, string newString, bool caseMatch, IDev2DataListUpsertPayloadBuilder <string> payloadBuilder, out ErrorResultTO errors, out int ReplaceCount, out IBinaryDataListEntry entryToReplaceIn)
        {
            ReplaceCount = 0;
            oldString    = oldString.Replace("\\", "\\\\");
            // ReSharper disable RedundantAssignment
            ErrorResultTO allErrors = new ErrorResultTO();

            errors = new ErrorResultTO();
            // ReSharper restore RedundantAssignment
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();

            entryToReplaceIn = compiler.Evaluate(exIdx, enActionType.User, expression, false, out errors);
            allErrors.MergeErrors(errors);

            if (entryToReplaceIn != null)
            {
                RegexOptions regexOptions;
                if (caseMatch)
                {
                    regexOptions = NoneCompiled;
                }
                else
                {
                    regexOptions = IgnoreCaseCompiled;
                }

                //Massimo Guerrera -  Added the Regex.Escape to escape certain characters - Bug 9937
                Regex regex = new Regex(Regex.Escape(oldString), regexOptions);

                IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(entryToReplaceIn);
                while (itr.HasMoreRecords())
                {
                    IList <IBinaryDataListItem> rowList = itr.FetchNextRowData();
                    if (rowList != null)
                    {
                        foreach (IBinaryDataListItem binaryDataListItem in rowList)
                        {
                            int    tmpCount = ReplaceCount;
                            string tmpVal   = binaryDataListItem.TheValue;
                            if (tmpVal.Contains("\\") && oldString.Contains("\\"))
                            {
                                tmpVal = tmpVal.Replace("\\", "\\\\");
                            }

                            ReplaceCount += regex.Matches(tmpVal).Count;
                            if (ReplaceCount > tmpCount)
                            {
                                if (entryToReplaceIn.IsRecordset)
                                {
                                    string recsetDisplayValue =
                                        DataListUtil.CreateRecordsetDisplayValue(entryToReplaceIn.Namespace, binaryDataListItem.FieldName, binaryDataListItem.ItemCollectionIndex.ToString());
                                    expression = string.Concat("[[", recsetDisplayValue, "]]");
                                }

                                var replaceValue = regex.Replace(tmpVal, newString);
                                payloadBuilder.Add(expression, replaceValue);
                            }
                        }
                    }
                }
                payloadBuilder.FlushIterationFrame();
            }
            else
            {
                allErrors.AddError("DataList entry is null.");
            }

            errors = allErrors;

            return(payloadBuilder);
        }
Ejemplo n.º 4
0
        // ReSharper restore RedundantOverridenMember

        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();

            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug = dataObject.IsDebugMode();
            toUpsert.ReplaceStarWithFixedIndex = true;

            ErrorResultTO allErrors   = new ErrorResultTO();
            ErrorResultTO errors      = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);

            InitializeDebug(dataObject);
            try
            {
                CleanArgs();
                ICaseConverter converter = CaseConverterFactory.CreateCaseConverter();

                allErrors.MergeErrors(errors);

                int index    = 1;
                int outIndex = 0;
                foreach (ICaseConvertTO item in ConvertCollection)
                {
                    outIndex++;
                    IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors);
                    allErrors.MergeErrors(errors);
                    ValidateVariable(item.Result, compiler, dataObject, out errors);
                    allErrors.MergeErrors(errors);
                    IsSingleValueRule.ApplyIsSingleValueRule(item.ExpressionToConvert, allErrors);
                    if (dataObject.IsDebugMode())
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", index.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(item.StringToConvert, "Convert", tmp, executionId), debugItem);
                        AddDebugItem(new DebugItemStaticDataParams(item.ConvertType, "To"), debugItem);
                        _debugInputs.Add(debugItem);
                        index++;
                    }

                    if (tmp != null)
                    {
                        IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp);

                        while (itr.HasMoreRecords())
                        {
                            foreach (IBinaryDataListItem itm in itr.FetchNextRowData())
                            {
                                try
                                {
                                    IBinaryDataListItem res = converter.TryConvert(item.ConvertType, itm);
                                    string expression       = item.Result;

                                    // 27.08.2013
                                    // NOTE : The result must remain [ as this is how the fliping studio generates the result when using (*) notation
                                    // There is a proper bug in to fix this issue, but since the studio is spaghetti I will leave this to the experts ;)
                                    // This is a tmp fix to the issue
                                    if (expression == "[" || DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star)
                                    {
                                        expression = DataListUtil.AddBracketsToValueIfNotExist(res.DisplayValue);
                                    }
                                    //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                                    IsSingleValueRule rule = new IsSingleValueRule(() => expression);
                                    var singleresError     = rule.Check();
                                    if (singleresError != null)
                                    {
                                        allErrors.AddError(singleresError.Message);
                                    }
                                    else
                                    {
                                        toUpsert.Add(expression, res.TheValue);
                                        // Upsert the entire payload
                                    }
                                    allErrors.MergeErrors(errors);
                                }
                                catch (Exception e)
                                {
                                    allErrors.AddError(e.Message);
                                    toUpsert.Add(item.Result, null);
                                }
                            }
                        }
                        compiler.Upsert(executionId, toUpsert, out errors);
                        if (!allErrors.HasErrors() && dataObject.IsDebugMode())
                        {
                            foreach (var debugOutputTo in toUpsert.DebugOutputs)
                            {
                                var debugItem = new DebugItem();
                                AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                                AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem);
                                _debugOutputs.Add(debugItem);
                            }
                            toUpsert.DebugOutputs.Clear();
                        }
                    }
                }
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfCaseConvertActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        int outIndex = 1;
                        foreach (ICaseConvertTO item in ConvertCollection)
                        {
                            IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors);
                            var debugItem            = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                            AddDebugItem(new DebugItemVariableParams(item.Result, "", tmp, executionId), debugItem);
                            _debugOutputs.Add(debugItem);
                            outIndex++;
                        }
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 5
0
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            _indexCounter = 1;
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            Guid          dlId           = dataObject.DataListID;
            ErrorResultTO allErrors      = new ErrorResultTO();
            ErrorResultTO errors;

            _datalistString = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors).ToString();

            InitializeDebug(dataObject);
            try
            {
                var sourceString = SourceString ?? "";
                IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dlId, enActionType.User, sourceString, false, out errors);

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemVariableParams(sourceString, "String to Split", expressionsEntry, dlId));
                    AddDebugInputItem(new DebugItemStaticDataParams(ReverseOrder ? "Backward" : "Forward", "Process Direction"));
                    AddDebugInputItem(new DebugItemStaticDataParams(SkipBlankRows ? "Yes" : "No", "Skip blank rows"));
                }
                CleanArguments(ResultsCollection);
                ResultsCollection.ToList().ForEach(a => IsSingleValueRule.ApplyIsSingleValueRule(a.OutputVariable, allErrors));
                if (ResultsCollection.Count > 0)
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebug(ResultsCollection, compiler, dlId);
                    }

                    CheckIndex(sourceString);
                    allErrors.MergeErrors(errors);
                    IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                    IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                    bool singleInnerIteration = ArePureScalarTargets(ResultsCollection);
                    bool exit = false;
                    while (itr.HasMoreRecords())
                    {
                        IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                        foreach (IBinaryDataListItem c in cols)
                        {
                            // set up live flushing iterator details
                            toUpsert.HasLiveFlushing      = true;
                            toUpsert.LiveFlushingLocation = dlId;

#pragma warning disable 219
                            int opCnt = 0;
#pragma warning restore 219
                            if (!string.IsNullOrEmpty(c.TheValue))
                            {
                                string val       = c.TheValue;
                                var    blankRows = new List <int>();
                                if (SkipBlankRows)
                                {
                                    var strings         = val.Split(new[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                                    var newSourceString = string.Join(Environment.NewLine, strings);
                                    val = newSourceString;
                                }
                                else
                                {
                                    var strings = val.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                                    for (int blankRow = 0; blankRow < strings.Length; blankRow++)
                                    {
                                        if (String.IsNullOrEmpty(strings[blankRow]))
                                        {
                                            blankRows.Add(blankRow);
                                        }
                                    }
                                }

                                IDev2Tokenizer tokenizer = CreateSplitPattern(ref val, ResultsCollection, compiler, dlId, out errors);
                                allErrors.MergeErrors(errors);

                                if (!allErrors.HasErrors())
                                {
                                    if (tokenizer != null)
                                    {
                                        int pos = 0;
                                        int end = (ResultsCollection.Count - 1);

                                        // track used tokens so we can adjust flushing ;)
                                        HashSet <string> usedTokens = new HashSet <string>();

                                        while (tokenizer.HasMoreOps() && !exit)
                                        {
                                            string tmp = tokenizer.NextToken();
                                            if (blankRows.Contains(opCnt) && blankRows.Count != 0)
                                            {
                                                tmp = tmp.Replace(Environment.NewLine, "");
                                                while (pos != end + 1)
                                                {
                                                    UpdateOutputVariableWithValue(pos, usedTokens, toUpsert, "");
                                                    pos++;
                                                }
                                                pos = CompletedRow(usedTokens, toUpsert, singleInnerIteration, ref opCnt, ref exit);
                                            }
                                            UpdateOutputVariableWithValue(pos, usedTokens, toUpsert, tmp);

                                            // Per pass
                                            if (pos == end)
                                            {
                                                //row has been processed
                                                pos = CompletedRow(usedTokens, toUpsert, singleInnerIteration, ref opCnt, ref exit);
                                            }
                                            else
                                            {
                                                pos++;
                                            }
                                        }

                                        // flush the final frame ;)

                                        toUpsert.FlushIterationFrame();
                                        toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                                    }
                                }
                            }
                        }
                    }
                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        AddResultToDebug(compiler, dlId);
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDataSplit", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfDataSplitActivity", allErrors);
                    compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddResultToDebug(compiler, dlId);
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// When overridden runs the activity's execution logic
        /// </summary>
        /// <param name="context">The context to be used.</param>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs           = new List <DebugItem>();
            _debugOutputs          = new List <DebugItem>();
            _nativeActivityContext = context;
            var dataObject = _nativeActivityContext.GetExtension <IDSFDataObject>();
            var compiler   = DataListFactory.CreateDataListCompiler();

            var           dlId      = dataObject.DataListID;
            var           allErrors = new ErrorResultTO();
            ErrorResultTO errors;


            var exeToken = _nativeActivityContext.GetExtension <IExecutionToken>();

            InitializeDebug(dataObject);
            try
            {
                IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dlId, enActionType.User, CommandFileName, false, out errors);
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemVariableParams(CommandFileName, "Command", expressionsEntry, dlId));
                }
                allErrors.MergeErrors(errors);
                IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry);
                IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);
                toUpsert.IsDebug = dataObject.IsDebugMode();
                if (!allErrors.HasErrors())
                {
                    while (itr.HasMoreRecords())
                    {
                        IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                        foreach (IBinaryDataListItem c in cols)
                        {
                            if (c.IsDeferredRead)
                            {
                                if (toUpsert != null)
                                {
                                    toUpsert.HasLiveFlushing      = true;
                                    toUpsert.LiveFlushingLocation = dlId;
                                }
                            }

                            if (string.IsNullOrEmpty(c.TheValue))
                            {
                                throw new Exception("Empty script to execute");
                            }

                            string        val = c.TheValue;
                            StreamReader  errorReader;
                            StringBuilder outputReader;
                            if (!ExecuteProcess(val, exeToken, out errorReader, out outputReader))
                            {
                                return;
                            }

                            allErrors.AddError(errorReader.ReadToEnd());
                            var    bytes     = Encoding.Default.GetBytes(outputReader.ToString().Trim());
                            string readValue = Encoding.ASCII.GetString(bytes).Replace("?", " ");

                            //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                            foreach (var region in DataListCleaningUtils.SplitIntoRegions(CommandResult))
                            {
                                if (toUpsert != null)
                                {
                                    toUpsert.Add(region, readValue);
                                }
                            }

                            errorReader.Close();

                            if (toUpsert != null && toUpsert.HasLiveFlushing)
                            {
                                try
                                {
                                    toUpsert.FlushIterationFrame();
                                    toUpsert = null;
                                }
                                catch (Exception e)
                                {
                                    Dev2Logger.Log.Error("DSFExecuteCommandLine", e);
                                    allErrors.AddError(e.Message);
                                }
                            }
                            else
                            {
                                compiler.Upsert(dlId, toUpsert, out errors);
                                allErrors.MergeErrors(errors);
                            }
                        }
                    }

                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        if (toUpsert == null)
                        {
                            return;
                        }
                        foreach (var debugOutputTo in toUpsert.DebugOutputs)
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFCommandLine", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors);
                    compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(dlId, CommandResult, (string)null, out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", CommandResult, ""));
                    }
                    DispatchDebugState(_nativeActivityContext, StateType.Before);
                    DispatchDebugState(_nativeActivityContext, StateType.After);
                }

                if (!string.IsNullOrEmpty(_fullPath))
                {
                    File.Delete(_fullPath);
                }
            }
        }
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);
                }
            }
        }