public IExecutionEnvironment UpdatePreviousEnvironmentWithSubExecutionResultUsingOutputMappings(IDSFDataObject dataObject, string outputDefs, int update)
        {
            var innerEnvironment = dataObject.Environment;

            dataObject.PopEnvironment();
            DataListUtil.OutputsToEnvironment(innerEnvironment, dataObject.Environment, outputDefs, update);

            return(innerEnvironment);
        }
        public IExecutionEnvironment UpdatePreviousEnvironmentWithSubExecutionResultUsingOutputMappings(IDSFDataObject dataObject, string outputDefs)
        {
            var innerEnvironment = dataObject.Environment;

            dataObject.PopEnvironment();
            DataListUtil.OutputsToEnvironment(innerEnvironment, dataObject.Environment, outputDefs);
            innerEnvironment.Errors.ForEach(s => dataObject.Environment.AddError(s));
            return(innerEnvironment);
        }
        public IExecutionEnvironment UpdatePreviousEnvironmentWithSubExecutionResultUsingOutputMappings(IDSFDataObject dataObject, string outputDefs, int update, bool handleErrors, ErrorResultTO errors)
        {
            var innerEnvironment = dataObject.Environment;

            dataObject.PopEnvironment();
            OutputsToEnvironment(innerEnvironment, dataObject.Environment, outputDefs, update);
            if (innerEnvironment.HasErrors() && !handleErrors)
            {
                CopyErrors(dataObject, errors, innerEnvironment);
            }
            if (innerEnvironment.HasErrors() && handleErrors)
            {
                CopyErrorsAndHandleThem(dataObject, errors, innerEnvironment);
            }
            return(innerEnvironment);
        }
        public IExecutionEnvironment UpdatePreviousEnvironmentWithSubExecutionResultUsingOutputMappings(IDSFDataObject dataObject, string outputDefs, int update, bool handleErrors, ErrorResultTO errors)
        {
            var innerEnvironment = dataObject.Environment;

            dataObject.PopEnvironment();
            OutputsToEnvironment(innerEnvironment, dataObject.Environment, outputDefs, update);
            if (innerEnvironment.HasErrors() && !handleErrors)
            {
                foreach (var error in innerEnvironment.AllErrors)
                {
                    if (!dataObject.Environment.AllErrors.Contains(error))
                    {
                        dataObject.Environment.AllErrors.Add(error);
                        errors.AddError(error);
                    }
                }
                foreach (var error in innerEnvironment.Errors)
                {
                    if (!dataObject.Environment.AllErrors.Contains(error))
                    {
                        dataObject.Environment.AllErrors.Add(error);
                        errors.AddError(error);
                    }
                }
            }
            if (innerEnvironment.HasErrors() && handleErrors)
            {
                foreach (var error in innerEnvironment.AllErrors)
                {
                    if (!dataObject.Environment.AllErrors.Contains(error))
                    {
                        errors.AddError(error);
                    }
                }
                foreach (var error in innerEnvironment.Errors)
                {
                    if (!dataObject.Environment.AllErrors.Contains(error))
                    {
                        errors.AddError(error);
                    }
                }
            }
            return(innerEnvironment);
        }
Exemple #5
0
#pragma warning disable S1541 // Methods and properties should not be too complex
#pragma warning disable S3776 // Cognitive Complexity of methods should not be too high
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
#pragma warning restore S3776 // Cognitive Complexity of methods should not be too high
#pragma warning restore S1541 // Methods and properties should not be too complex
        {
            var allErrors = new ErrorResultTO();

            InitializeDebug(dataObject);

            if (string.IsNullOrEmpty(DataSource))
            {
                allErrors.AddError(ErrorResource.DataSourceEmpty);
            }
            if (string.IsNullOrEmpty(Alias))
            {
                allErrors.AddError(string.Format(ErrorResource.CanNotBeEmpty, "Alias"));
            }
            if (allErrors.HasErrors())
            {
                DisplayAndWriteError("DsfSelectAndApplyActivity", allErrors);
                foreach (var fetchError in allErrors.FetchErrors())
                {
                    dataObject.Environment.AddError(fetchError);
                }
            }
            var startTime = DateTime.Now;

            _previousParentId = dataObject.ParentInstanceID;
            _debugInputs      = new List <DebugItem>();
            _debugOutputs     = new List <DebugItem>();

            dataObject.ForEachNestingLevel++;

            var expressions = new List <string>();

            try
            {
                string ds;
                try
                {
                    ds          = dataObject.Environment.ToStar(DataSource);
                    expressions = dataObject.Environment.GetIndexes(ds);
                    if (expressions.Count == 0)
                    {
                        expressions.Add(ds);
                    }
                }
                catch (NullReferenceException)
                {
                    //Do nothing exception aleady added to errors
                    throw new NullDataSource();
                }

                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemStaticDataParams(Alias, "As", DataSource));
                }

                var scopedEnvironment = new ScopedEnvironment(dataObject.Environment, ds, Alias);

                //Push the new environment
                dataObject.PushEnvironment(scopedEnvironment);
                dataObject.ForEachNestingLevel++;
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                }
                dataObject.ParentInstanceID = UniqueID;
                dataObject.IsDebugNested    = true;
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.After, update);
                }

                foreach (var exp in expressions)
                {
                    //Assign the warewolfAtom to Alias using new environment
                    scopedEnvironment.SetDataSource(exp);

                    if (ApplyActivityFunc.Handler is IDev2Activity exeAct)
                    {
                        _childUniqueID = exeAct.UniqueID;
                        exeAct.Execute(dataObject, 0);
                    }
                }
            }
            catch (NullDataSource e)
            {
                Dev2Logger.Error("DSFSelectAndApply", e, GlobalConstants.WarewolfError);
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFSelectAndApply", e, GlobalConstants.WarewolfError);
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (dataObject.IsServiceTestExecution)
                {
                    if (dataObject.IsDebugMode())
                    {
                        GetTestOurputResultForDebug(dataObject);
                    }
                    else
                    {
                        GetTestOutputForBrowserExecution(dataObject);
                    }
                }

                dataObject.PopEnvironment();
                dataObject.ForEachNestingLevel--;
                if (allErrors.HasErrors())
                {
                    DisplayAndWriteError("DsfSelectAndApplyActivity", allErrors);
                    foreach (var fetchError in allErrors.FetchErrors())
                    {
                        dataObject.Environment.AddError(fetchError);
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    foreach (var expression in expressions)
                    {
                        AddExpresionEvalOutputItem(dataObject, update, expression);
                    }

                    DispatchDebugState(dataObject, StateType.End, update, startTime, DateTime.Now);
                }
                OnCompleted(dataObject);
            }
        }
Exemple #6
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            ErrorResultTO allErrors = new ErrorResultTO();

            InitializeDebug(dataObject);

            if (string.IsNullOrEmpty(DataSource))
            {
                allErrors.AddError(ErrorResource.DataSourceEmpty);
            }
            if (string.IsNullOrEmpty(Alias))
            {
                allErrors.AddError(string.Format(ErrorResource.CanNotBeEmpty, "Alias"));
            }
            if (allErrors.HasErrors())
            {
                DisplayAndWriteError("DsfSelectAndApplyActivity", allErrors);
                foreach (var fetchError in allErrors.FetchErrors())
                {
                    dataObject.Environment.AddError(fetchError);
                }
            }
            var startTime = DateTime.Now;

            _previousParentId = dataObject.ParentInstanceID;
            _debugInputs      = new List <DebugItem>();
            _debugOutputs     = new List <DebugItem>();

            dataObject.ForEachNestingLevel++;

            List <string> expressions = new List <string>();

            try
            {
                string ds;
                try
                {
                    ds          = dataObject.Environment.ToStar(DataSource);
                    expressions = dataObject.Environment.GetIndexes(ds);
                    if (expressions.Count == 0)
                    {
                        expressions.Add(ds);
                    }
                }
                catch (NullReferenceException)
                {
                    //Do nothing exception aleady added to errors
                    throw new NullDataSource();
                }


                if (dataObject.IsDebugMode())
                {
                    AddDebugInputItem(new DebugItemStaticDataParams(Alias, "As", DataSource));
                }

                var scopedEnvironment = new ScopedEnvironment(dataObject.Environment, ds, Alias);

                //Push the new environment
                dataObject.PushEnvironment(scopedEnvironment);
                dataObject.ForEachNestingLevel++;
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                }
                dataObject.ParentInstanceID = UniqueID;
                dataObject.IsDebugNested    = true;
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.After, update);
                }

                foreach (var exp in expressions)
                {
                    //Assign the warewolfAtom to Alias using new environment
                    scopedEnvironment.SetDataSource(exp);

                    var exeAct = ApplyActivityFunc.Handler as IDev2Activity;
                    if (exeAct != null)
                    {
                        _childUniqueID = exeAct.UniqueID;
                        exeAct.Execute(dataObject, 0);
                    }
                }
            }
            catch (NullDataSource e)
            {
                Dev2Logger.Error("DSFSelectAndApply", e);
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFSelectAndApply", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (dataObject.IsDebugMode())
                {
                    if (dataObject.IsServiceTestExecution)
                    {
                        var serviceTestStep  = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.UniqueId == _originalUniqueID);
                        var serviceTestSteps = serviceTestStep?.Children;
                        UpdateDebugStateWithAssertions(dataObject, serviceTestSteps?.ToList());
                        if (serviceTestStep != null)
                        {
                            var testRunResult = new TestRunResult();
                            GetFinalTestRunResult(serviceTestStep, testRunResult, dataObject);
                            serviceTestStep.Result = testRunResult;

                            var debugItems = TestDebugMessageRepo.Instance.GetDebugItems(dataObject.ResourceID, dataObject.TestName);
                            debugItems = debugItems.Where(state => state.WorkSurfaceMappingId == serviceTestStep.UniqueId).ToList();
                            var debugStates = debugItems.LastOrDefault();

                            var       debugItemStaticDataParams = new DebugItemServiceTestStaticDataParams(serviceTestStep.Result.Message, serviceTestStep.Result.RunTestResult == RunResult.TestFailed);
                            DebugItem itemToAdd = new DebugItem();
                            itemToAdd.AddRange(debugItemStaticDataParams.GetDebugItemResult());
                            debugStates?.AssertResultList?.Add(itemToAdd);
                        }
                    }
                }
                dataObject.PopEnvironment();
                dataObject.ForEachNestingLevel--;
                if (allErrors.HasErrors())
                {
                    if (allErrors.HasErrors())
                    {
                        DisplayAndWriteError("DsfSelectAndApplyActivity", allErrors);
                        foreach (var fetchError in allErrors.FetchErrors())
                        {
                            dataObject.Environment.AddError(fetchError);
                        }
                    }
                }
                if (dataObject.IsDebugMode())
                {
                    foreach (var expression in expressions)
                    {
                        var data = dataObject.Environment.Eval(expression, update);
                        if (data.IsWarewolfAtomListresult)
                        {
                            var lst = data as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult;
                            AddDebugOutputItem(new DebugItemWarewolfAtomListResult(lst, "", "", expression, "", "", "="));
                        }
                        else
                        {
                            if (data.IsWarewolfAtomResult)
                            {
                                var atom = data as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult;
                                if (atom != null)
                                {
                                    AddDebugOutputItem(new DebugItemWarewolfAtomResult(atom.Item.ToString(), expression, ""));
                                }
                            }
                        }
                    }

                    DispatchDebugState(dataObject, StateType.End, update, startTime, DateTime.Now);
                }
                OnCompleted(dataObject);
            }
        }