Esempio n. 1
0
        void IterateOverXPath(IDSFDataObject dataObject, int update, XPathParser parser, ErrorResultTO allErrors, string c, int i)
        {
            var xpathEntry    = dataObject.Environment.Eval(ResultsCollection[i].XPath, update);
            var xpathIterator = new WarewolfIterator(xpathEntry);

            while (xpathIterator.HasMoreData())
            {
                var xpathCol = xpathIterator.GetNextValue();
                try
                {
                    var eval     = parser.ExecuteXPath(c, xpathCol).ToList();
                    var variable = ResultsCollection[i].OutputVariable;
                    AssignResult(variable, dataObject, eval, update);
                }
                catch (Exception e)
                {
                    allErrors.AddError(e.Message);
                    dataObject.Environment.Assign(ResultsCollection[i].OutputVariable, null, update);
                }
            }
        }
 private int Process(IDSFDataObject dataObject, int update, int i, XPathParser parser, ErrorResultTO allErrors, ErrorResultTO errors)
 {
     if (!string.IsNullOrEmpty(SourceString))
     {
         var itr            = new WarewolfListIterator();
         var sourceIterator = new WarewolfIterator(dataObject.Environment.Eval(SourceString, update));
         itr.AddVariableToIterateOn(sourceIterator);
         while (itr.HasMoreData())
         {
             var c = itr.FetchNextValue(sourceIterator);
             for (i = 0; i < ResultsCollection.Count; i++)
             {
                 if (!string.IsNullOrEmpty(ResultsCollection[i].OutputVariable))
                 {
                     var xpathEntry    = dataObject.Environment.Eval(ResultsCollection[i].XPath, update);
                     var xpathIterator = new WarewolfIterator(xpathEntry);
                     while (xpathIterator.HasMoreData())
                     {
                         var xpathCol = xpathIterator.GetNextValue();
                         try
                         {
                             List <string> eval     = parser.ExecuteXPath(c, xpathCol).ToList();
                             var           variable = ResultsCollection[i].OutputVariable;
                             AssignResult(variable, dataObject, eval, update);
                         }
                         catch (Exception e)
                         {
                             allErrors.AddError(e.Message);
                             dataObject.Environment.Assign(ResultsCollection[i].OutputVariable, null, update);
                         }
                     }
                 }
             }
             allErrors.MergeErrors(errors);
         }
     }
     return(i);
 }
Esempio n. 3
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);
                }
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject)
        {
            _debugOutputs.Clear();

            _isDebugMode = dataObject.IsDebugMode();
            ErrorResultTO errors    = new ErrorResultTO();
            ErrorResultTO allErrors = new ErrorResultTO();
            XPathParser   parser    = new XPathParser();
            int           i         = 0;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    if (_isDebugMode)
                    {
                        AddSourceStringDebugInputItem(SourceString, dataObject.Environment);
                        AddResultDebugInputs(ResultsCollection, out errors);
                        allErrors.MergeErrors(errors);
                    }
                    if (!allErrors.HasErrors())
                    {
                        var itr            = new WarewolfListIterator();
                        var sourceIterator = new WarewolfIterator(dataObject.Environment.Eval(SourceString));
                        itr.AddVariableToIterateOn(sourceIterator);
                        while (itr.HasMoreData())
                        {
                            var c = itr.FetchNextValue(sourceIterator);
                            //foreach(IBinaryDataListItem c in cols)
                            {
                                for (i = 0; i < ResultsCollection.Count; i++)
                                {
                                    if (!string.IsNullOrEmpty(ResultsCollection[i].OutputVariable))
                                    {
                                        var xpathEntry    = dataObject.Environment.Eval(ResultsCollection[i].XPath);
                                        var xpathIterator = new WarewolfIterator(xpathEntry);
                                        while (xpathIterator.HasMoreData())
                                        {
                                            var xpathCol = xpathIterator.GetNextValue();
                                            //foreach(IBinaryDataListItem xPathCol in xpathCols)
                                            {
                                                try
                                                {
                                                    List <string> eval = parser.ExecuteXPath(c, xpathCol).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;
                                                                }
                                                                AssignResult(cleanFieldName, dataObject, eval);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        var variable = ResultsCollection[i].OutputVariable;
                                                        AssignResult(variable, dataObject, eval);
                                                    }
                                                }
                                                catch (Exception e)
                                                {
                                                    allErrors.AddError(e.Message);
                                                    dataObject.Environment.Assign(ResultsCollection[i].OutputVariable, null);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            allErrors.MergeErrors(errors);
                        }
                    }
                    if (_isDebugMode && !allErrors.HasErrors())
                    {
                        var innerCount = 1;
                        foreach (var debugOutputTo in ResultsCollection)
                        {
                            var itemToAdd = new DebugItem();
                            AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd);
                            AddDebugItem(new DebugEvalResult(DataListUtil.ReplaceRecordsetBlankWithStar(debugOutputTo.OutputVariable), "", dataObject.Environment), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                            innerCount++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                allErrors.AddError(ex.Message);
            }
            finally
            {
                // Handle Errors

                var actualIndex = i - 1;
                var hasErrors   = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfXPathActivity", allErrors);
                    var errorString = allErrors.MakeDataListReady();
                    dataObject.Environment.AddError(errorString);
                    if (actualIndex > -1)
                    {
                        dataObject.Environment.Assign(ResultsCollection[actualIndex].OutputVariable, null);
                    }
                }
                if (_isDebugMode)
                {
                    if (hasErrors)
                    {
                        if (_isDebugMode)
                        {
                            var itemToAdd = new DebugItem();
                            if (actualIndex < 0)
                            {
                                actualIndex = 0;
                            }
                            AddDebugItem(new DebugItemStaticDataParams("", (actualIndex + 1).ToString(CultureInfo.InvariantCulture)), itemToAdd);

                            AddDebugItem(new DebugEvalResult(ResultsCollection[actualIndex].OutputVariable, "", dataObject.Environment), itemToAdd);
                            _debugOutputs.Add(itemToAdd);
                        }
                    }
                    DispatchDebugState(dataObject, StateType.Before);
                    DispatchDebugState(dataObject, StateType.After);
                }
            }
        }