Ejemplo n.º 1
0
        IEnumerable <string> BuildQueryFromTo(SharepointSearchTo sharepointSearchTo, IExecutionEnvironment env, ISharepointFieldTo sharepointFieldTo, int update)
        {
            WarewolfIterator iterator = new WarewolfIterator(env.Eval(sharepointSearchTo.ValueToMatch, update));

            while (iterator.HasMoreData())
            {
                var fieldType = sharepointFieldTo.GetFieldType();
                yield return(string.Format("{0}<FieldRef Name=\"{1}\"></FieldRef><Value Type=\"{2}\">{3}</Value>{4}", SharepointSearchOptions.GetStartTagForSearchOption(sharepointSearchTo.SearchType), sharepointSearchTo.InternalName, fieldType, CastWarewolfValueToCorrectType(iterator.GetNextValue(), sharepointFieldTo.Type), SharepointSearchOptions.GetEndTagForSearchOption(sharepointSearchTo.SearchType)));
            }
        }
Ejemplo n.º 2
0
        public void WarewolfIterator_Construct_GivenScalarWithUnixNewLine()
        {
            var item1 = DataStorage.WarewolfAtom.NewDataString("some \nstring");

            var warewolfAtomResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(item1);

            var iterator = new WarewolfIterator(warewolfAtomResult);

            Assert.AreEqual("\n", iterator.NewLineFormat);

            Assert.AreEqual(1, iterator.GetLength());

            Assert.IsTrue(iterator.HasMoreData());
            Assert.AreEqual("some \nstring", iterator.GetNextValue());
        }
Ejemplo n.º 3
0
        public void WarewolfIterator_Construct_GivenScalarWithInvalidCalculate()
        {
            var item1 = DataStorage.WarewolfAtom.NewDataString("!~calculation~!\"2- nos2w()-200\"!~~calculation~!");

            var warewolfAtomResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(item1);

            var iterator = new WarewolfIterator(warewolfAtomResult, Common.Interfaces.Diagnostics.Debug.FunctionEvaluatorOption.DotNetDateTimeFormat);

            Assert.AreEqual("\r\n", iterator.NewLineFormat);

            Assert.AreEqual(1, iterator.GetLength());

            Assert.IsTrue(iterator.HasMoreData());
            var nowString = iterator.GetNextValue();

            Assert.AreEqual("2- nos2w()-200", nowString);
        }
Ejemplo n.º 4
0
        public void WarewolfIterator_Construct_GivenScalarWithCalculate()
        {
            var item1 = DataStorage.WarewolfAtom.NewDataString("!~calculation~!\"now()\"!~~calculation~!");

            var warewolfAtomResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(item1);

            var iterator = new WarewolfIterator(warewolfAtomResult, Common.Interfaces.Diagnostics.Debug.FunctionEvaluatorOption.DotNetDateTimeFormat);

            Assert.AreEqual("\r\n", iterator.NewLineFormat);

            Assert.AreEqual(1, iterator.GetLength());

            Assert.IsTrue(iterator.HasMoreData());
            var realNow   = DateTime.Now;
            var nowString = iterator.GetNextValue();
            var now       = DateTime.Parse(nowString, System.Globalization.CultureInfo.InvariantCulture);

            Assert.IsTrue(now > realNow);
        }
Ejemplo n.º 5
0
        private void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, IExecutionEnvironment env)
        {
            var scriptItr = new WarewolfIterator(dataObject.Environment.Eval(Script, update, false, EscapeScript));

            while (scriptItr.HasMoreData())
            {
                var engine = new ScriptingEngineRepo().CreateEngine(ScriptType, _sources);
                var value  = engine.Execute(scriptItr.GetNextValue());

                foreach (var region in DataListCleaningUtils.SplitIntoRegions(Result))
                {
                    env.Assign(region, value, update);
                    if (dataObject.IsDebugMode() && !allErrors.HasErrors() && !string.IsNullOrEmpty(region))
                    {
                        AddDebugOutputItem(new DebugEvalResult(region, "", env, update));
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void PerformLogExecution(string logUri, int update)
 {
     
     var expressionsEntry = DataObject.Environment.Eval(logUri, update);
     var itr = new WarewolfIterator(expressionsEntry);
     while (itr.HasMoreData())
     {
         var val = itr.GetNextValue();
         {
             var buildGetWebRequest = BuildSimpleGetWebRequest(val);
             if (buildGetWebRequest == null)
             {
                 throw new Exception("Invalid Url to execute for logging");
             }
             buildGetWebRequest.UseDefaultCredentials = true;
             ExecuteWebRequestAsync(buildGetWebRequest);
         }
     }
 }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
        public void WarewolfIterator_Construct_GivenEmptyCalculate()
        {
            var item1 = DataStorage.WarewolfAtom.NewDataString("!~calculation~!!~~calculation~!");

            var warewolfAtomResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(item1);

            var iterator = new WarewolfIterator(warewolfAtomResult, Common.Interfaces.Diagnostics.Debug.FunctionEvaluatorOption.DotNetDateTimeFormat);

            Assert.AreEqual("\r\n", iterator.NewLineFormat);

            Assert.AreEqual(1, iterator.GetLength());

            Assert.IsTrue(iterator.HasMoreData());
            try
            {
                var nowString = iterator.GetNextValue();
                Assert.Fail("expected exception Nothing to Evaluate");
            }
            catch (Exception e)
            {
                Assert.AreEqual("Nothing to Evaluate", e.Message);
            }
        }
Ejemplo n.º 10
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            AddScriptSourcePathsToList();
            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            var env = dataObject.Environment;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        var language = ScriptType.GetDescription();
                        AddDebugInputItem(new DebugItemStaticDataParams(language, "Language"));
                        AddDebugInputItem(new DebugEvalResult(Script, "Script", env, update));
                    }

                    allErrors.MergeErrors(errors);

                    if (allErrors.HasErrors())
                    {
                        return;
                    }

                    var scriptItr = new WarewolfIterator(dataObject.Environment.Eval(Script, update, false, EscapeScript));
                    while (scriptItr.HasMoreData())
                    {
                        var engine = new ScriptingEngineRepo().CreateEngine(ScriptType, _sources);
                        var value  = engine.Execute(scriptItr.GetNextValue());

                        foreach (var region in DataListCleaningUtils.SplitIntoRegions(Result))
                        {
                            env.Assign(region, value, update);
                            if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                            {
                                if (!string.IsNullOrEmpty(region))
                                {
                                    AddDebugOutputItem(new DebugEvalResult(region, "", env, update));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e) when(e is NullReferenceException || e is RuntimeBinderException)
            {
                if (e.GetType() == typeof(NullReferenceException) || e.GetType() == typeof(RuntimeBinderException))
                {
                    allErrors.AddError(ErrorResource.ScriptingErrorReturningValue);
                }
                else
                {
                    allErrors.AddError(e.Message.Replace(" for main:Object", string.Empty));
                }
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfScriptingJavaScriptActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                if (dataObject.IsDebugMode())
                {
                    if (allErrors.HasErrors())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
Ejemplo n.º 11
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            _indexCounter = 1;

            ErrorResultTO        allErrors = new ErrorResultTO();
            var                  env       = dataObject.Environment;
            WarewolfListIterator iter      = new WarewolfListIterator();

            InitializeDebug(dataObject);
            try
            {
                var sourceString = SourceString ?? "";
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugEvalResult(sourceString, "String to Split", env, update));
                    AddDebugInputItem(new DebugItemStaticDataParams(ReverseOrder ? "Backward" : "Forward", "Process Direction"));
                    AddDebugInputItem(new DebugItemStaticDataParams(SkipBlankRows ? "Yes" : "No", "Skip blank rows"));
                    AddDebug(ResultsCollection, dataObject.Environment, update);
                }
                var res = new WarewolfIterator(env.Eval(sourceString, update));
                iter.AddVariableToIterateOn(res);
                IDictionary <string, int> positions = new Dictionary <string, int>();
                CleanArguments(ResultsCollection);
                ResultsCollection.ToList().ForEach(a =>
                {
                    if (!positions.ContainsKey(a.OutputVariable))
                    {
                        positions.Add(a.OutputVariable, update == 0 ? 1 : update);
                    }
                    IsSingleValueRule.ApplyIsSingleValueRule(a.OutputVariable, allErrors);
                });
                bool singleInnerIteration = ArePureScalarTargets(ResultsCollection);
                var  resultsEnumerator    = ResultsCollection.GetEnumerator();
                var  debugDictionary      = new List <string>();
                while (res.HasMoreData())
                {
                    const int OpCnt = 0;

                    var item = res.GetNextValue(); // item is the thing we split on
                    if (!string.IsNullOrEmpty(item))
                    {
                        string val = item;

                        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);
                                }
                            }
                        }

                        ErrorResultTO  errors;
                        IDev2Tokenizer tokenizer = CreateSplitPattern(ref val, ResultsCollection, env, out errors, update);
                        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 ;)
                                while (tokenizer.HasMoreOps())
                                {
                                    var currentval = resultsEnumerator.MoveNext();
                                    if (!currentval)
                                    {
                                        if (singleInnerIteration)
                                        {
                                            break;
                                        }
                                        resultsEnumerator.Reset();
                                        resultsEnumerator.MoveNext();
                                    }
                                    string tmp = tokenizer.NextToken();

                                    if (tmp.StartsWith(Environment.NewLine) && !SkipBlankRows)
                                    {
                                        resultsEnumerator.Reset();
                                        while (resultsEnumerator.MoveNext())
                                        {
                                            var tovar = resultsEnumerator.Current.OutputVariable;
                                            if (!String.IsNullOrEmpty(tovar))
                                            {
                                                var assignToVar = ExecutionEnvironment.ConvertToIndex(tovar, positions[tovar]);
                                                env.AssignWithFrame(new AssignValue(assignToVar, ""), update);
                                                positions[tovar] = positions[tovar] + 1;
                                            }
                                        }
                                        resultsEnumerator.Reset();
                                        resultsEnumerator.MoveNext();
                                    }
                                    if (blankRows.Contains(OpCnt) && blankRows.Count != 0)
                                    {
                                        tmp = tmp.Replace(Environment.NewLine, "");
                                        while (pos != end + 1)
                                        {
                                            pos++;
                                        }
                                    }
                                    var outputVar = resultsEnumerator.Current.OutputVariable;

                                    if (!String.IsNullOrEmpty(outputVar))
                                    {
                                        var assignVar = ExecutionEnvironment.ConvertToIndex(outputVar, positions[outputVar]);
                                        if (ExecutionEnvironment.IsRecordsetIdentifier(assignVar))
                                        {
                                            env.AssignWithFrame(new AssignValue(assignVar, tmp), update);
                                        }
                                        else if (ExecutionEnvironment.IsScalar(assignVar) && positions[outputVar] == 1)
                                        {
                                            env.AssignWithFrame(new AssignValue(assignVar, tmp), update);
                                        }
                                        else
                                        {
                                            env.AssignWithFrame(new AssignValue(assignVar, tmp), update);
                                        }
                                        positions[outputVar] = positions[outputVar] + 1;
                                    }
                                    if (dataObject.IsDebugMode())
                                    {
                                        var debugItem   = new DebugItem();
                                        var outputVarTo = resultsEnumerator.Current.OutputVariable;
                                        AddDebugItem(new DebugEvalResult(outputVarTo, "", env, update), debugItem);
                                        if (!debugDictionary.Contains(outputVarTo))
                                        {
                                            debugDictionary.Add(outputVarTo);
                                        }
                                    }
                                    if (pos == end)
                                    {
                                    }
                                    else
                                    {
                                        pos++;
                                    }
                                }
                            }
                        }
                    }
                    env.CommitAssign();
                    if (singleInnerIteration)
                    {
                        break;
                    }
                }

                if (dataObject.IsDebugMode())
                {
                    var outputIndex = 1;
                    foreach (var varDebug in debugDictionary)
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", outputIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                        var dataSplitUsesStarForOutput = varDebug.Replace("().", "(*).");
                        AddDebugItem(new DebugEvalResult(dataSplitUsesStarForOutput, "", env, update), debugItem);
                        _debugOutputs.Add(debugItem);
                        outputIndex++;
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFDataSplit", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfDataSplitActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                    DispatchDebugState(dataObject, StateType.After, update);
                }
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject)
        {
            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors    = new ErrorResultTO();

            allErrors.MergeErrors(errors);
            var env = dataObject.Environment;

            InitializeDebug(dataObject);
            try
            {
                if (!errors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        var language = ScriptType.GetDescription();
                        AddDebugInputItem(new DebugItemStaticDataParams(language, "Language"));
                        AddDebugInputItem(new DebugEvalResult(Script, "Script", env));
                    }

                    var listOfEvalResultsForInput = dataObject.Environment.EvalForDataMerge(Script);
                    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);
                    }

                    allErrors.MergeErrors(errors);

                    if (allErrors.HasErrors())
                    {
                        return;
                    }
                    var scriptItr = new WarewolfIterator(inputListResult);
                    while (scriptItr.HasMoreData())
                    {
                        var engine = new ScriptingEngineRepo().CreateEngine(ScriptType);
                        var value  = engine.Execute(scriptItr.GetNextValue());

                        //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result
                        foreach (var region in DataListCleaningUtils.SplitIntoRegions(Result))
                        {
                            env.Assign(region, value);
                            if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                            {
                                AddDebugOutputItem(new DebugEvalResult(region, "", env));
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(NullReferenceException) || e.GetType() == typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException))
                {
                    allErrors.AddError("There was an error when returning a value from your script, remember to use the 'Return' keyword when returning the result");
                }
                else
                {
                    allErrors.AddError(e.Message.Replace(" for main:Object", string.Empty));
                }
            }
            finally
            {
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfScriptingJavaScriptActivity", allErrors);
                    var errorString = allErrors.MakeDisplayReady();
                    dataObject.Environment.AddError(errorString);
                }

                if (dataObject.IsDebugMode())
                {
                    if (allErrors.HasErrors())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(dataObject, StateType.Before);
                    DispatchDebugState(dataObject, StateType.After);
                }
            }
        }
Ejemplo n.º 13
0
        IEnumerable <string> BuildQueryFromTo(SharepointSearchTo sharepointSearchTo, IExecutionEnvironment env, ISharepointFieldTo sharepointFieldTo, int update)
        {
            var warewolfEvalResult = env.Eval(sharepointSearchTo.ValueToMatch, update);
            var fieldType          = sharepointFieldTo.GetFieldType();

            if (sharepointSearchTo.SearchType == "In")
            {
                var startSearchTerm = string.Format("{0}<FieldRef Name=\"{1}\"></FieldRef>", SharepointSearchOptions.GetStartTagForSearchOption(sharepointSearchTo.SearchType), sharepointSearchTo.InternalName);

                startSearchTerm += "<Values>";
                if (warewolfEvalResult.IsWarewolfAtomListresult)
                {
                    var listResult = warewolfEvalResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult;
                    if (listResult != null)
                    {
                        foreach (var warewolfAtom in listResult.Item)
                        {
                            var valueString = warewolfAtom.ToString();
                            if (valueString.Contains(","))
                            {
                                var listOfValues = valueString.Split(',');
                                startSearchTerm = listOfValues.Select(listOfValue => CastWarewolfValueToCorrectType(listOfValue, sharepointFieldTo.Type)).Aggregate(startSearchTerm, (current, value) => current + string.Format("<Value Type=\"{0}\">{1}</Value>", fieldType, value));
                            }
                            else
                            {
                                var value = CastWarewolfValueToCorrectType(valueString, sharepointFieldTo.Type);
                                startSearchTerm += string.Format("<Value Type=\"{0}\">{1}</Value>", fieldType, value);
                            }
                        }
                    }
                }
                else
                {
                    var scalarResult = warewolfEvalResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult;
                    if (scalarResult != null)
                    {
                        var valueString = scalarResult.Item.ToString();
                        if (valueString.Contains(","))
                        {
                            var listOfValues = valueString.Split(',');
                            startSearchTerm = listOfValues.Select(listOfValue => CastWarewolfValueToCorrectType(listOfValue, sharepointFieldTo.Type)).Aggregate(startSearchTerm, (current, value) => current + string.Format("<Value Type=\"{0}\">{1}</Value>", fieldType, value));
                        }
                        else
                        {
                            var value = CastWarewolfValueToCorrectType(valueString, sharepointFieldTo.Type);
                            startSearchTerm += string.Format("<Value Type=\"{0}\">{1}</Value>", fieldType, value);
                        }
                    }
                }
                startSearchTerm += "</Values>";
                startSearchTerm += SharepointSearchOptions.GetEndTagForSearchOption(sharepointSearchTo.SearchType);
                yield return(startSearchTerm);
            }
            else
            {
                WarewolfIterator iterator = new WarewolfIterator(warewolfEvalResult);
                while (iterator.HasMoreData())
                {
                    yield return(string.Format("{0}<FieldRef Name=\"{1}\"></FieldRef><Value Type=\"{2}\">{3}</Value>{4}", SharepointSearchOptions.GetStartTagForSearchOption(sharepointSearchTo.SearchType), sharepointSearchTo.InternalName, fieldType, CastWarewolfValueToCorrectType(iterator.GetNextValue(), sharepointFieldTo.Type), SharepointSearchOptions.GetEndTagForSearchOption(sharepointSearchTo.SearchType)));
                }
            }
        }
Ejemplo n.º 14
0
        protected override void ExecuteTool(IDSFDataObject dataObject)
        {
            IExecutionToken exeToken = dataObject.ExecutionToken;

            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();

            var allErrors = new ErrorResultTO();

            InitializeDebug(dataObject);
            try
            {
                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugEvalResult(CommandFileName, "Command", dataObject.Environment));
                }
                var itr = new WarewolfIterator(dataObject.Environment.Eval(CommandFileName));
                if (!allErrors.HasErrors())
                {
                    while (itr.HasMoreData())
                    {
                        var val = itr.GetNextValue();
                        {
                            if (string.IsNullOrEmpty(val))
                            {
                                throw new Exception("Empty script to execute");
                            }

                            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 (dataObject.Environment != null)
                                {
                                    dataObject.Environment.Assign(region, readValue);
                                }
                            }
                            errorReader.Close();
                        }
                    }

                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        if (!string.IsNullOrEmpty(CommandResult))
                        {
                            AddDebugOutputItem(new DebugEvalResult(CommandResult, "", dataObject.Environment));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFCommandLine", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfExecuteCommandLineActivity", allErrors);
                    if (dataObject.Environment != null)
                    {
                        var errorString = allErrors.MakeDisplayReady();
                        dataObject.Environment.AddError(errorString);
                        dataObject.Environment.Assign(CommandResult, null);
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", CommandResult, ""));
                    }
                    DispatchDebugState(dataObject, StateType.Before);
                    DispatchDebugState(dataObject, StateType.After);
                }

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