private void ActivityCompleted(NativeActivityContext context, ActivityInstance instance, bool result)
        {
            var dataObject = context.GetExtension <IDSFDataObject>();

            if (dataObject != null && operationalData != null)
            {
                operationalData.IncIterationCount();

                if (operationalData.IndexIterator.HasMore())
                {
                    var idx = operationalData.IndexIterator.FetchNextIndex();
                    // Re-jigger the mapping ;)
                    if (operationalData.ForEachType != enForEachType.NumOfExecution)
                    {
                        IterateIOMapping(idx);
                    }
                    dataObject.ParentInstanceID = UniqueID;
                    // ReSharper disable RedundantTypeArgumentsOfMethod
                    context.ScheduleFunc <string, bool>(DataFunc, UniqueID, ActivityCompleted);
                    // ReSharper restore RedundantTypeArgumentsOfMethod
                    return;
                }

                // that is all she wrote ;)
                dataObject.IsDataListScoped = false;
                // return it all to normal
                if (ForEachType != enForEachType.NumOfExecution)
                {
                    RestoreHandlerFn();
                }

                dataObject.ParentInstanceID = _previousParentId;
                dataObject.ForEachNestingLevel--;
                dataObject.IsDebugNested = false;
            }
        }
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            _previousParentId = dataObject.ParentInstanceID;
            _debugInputs      = new List <DebugItem>();
            _debugOutputs     = new List <DebugItem>();

            ErrorResultTO  allErrors = new ErrorResultTO();
            IIndexIterator itr       = null;

            InitializeDebug(dataObject);
            dataObject.ForEachNestingLevel++;
            try
            {
                ErrorResultTO      errors;
                ForEachBootstrapTO exePayload = FetchExecutionType(dataObject, dataObject.Environment, out errors, update);

                foreach (var err in errors.FetchErrors())
                {
                    dataObject.Environment.AddError(err);
                }
                itr = exePayload.IndexIterator;

                string error;
                ForEachInnerActivityTO innerA = GetInnerActivity(out error);
                var exeAct = innerA?.InnerActivity;
                allErrors.AddError(error);
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.Before, update);
                }
                dataObject.ParentInstanceID = UniqueID;
                dataObject.IsDebugNested    = true;
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(dataObject, StateType.After, update);
                }
                exePayload.InnerActivity = innerA;

                while (itr?.HasMore() ?? false)
                {
                    operationalData = exePayload;
                    int idx         = exePayload.IndexIterator.FetchNextIndex();
                    int innerupdate = 0;
                    if (exePayload.ForEachType != enForEachType.NumOfExecution)
                    {
                        innerupdate = idx;
                    }
                    _childUniqueID = exeAct?.UniqueID;
                    exeAct?.Execute(dataObject, innerupdate);

                    operationalData.IncIterationCount();
                }
                if (errors.HasErrors())
                {
                    allErrors.MergeErrors(errors);
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Error("DSFForEach", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                if (itr != null)
                {
                    if (ForEachType != enForEachType.NumOfExecution)
                    {
                        RestoreHandlerFn();
                    }
                }
                var serviceTestStep = dataObject.ServiceTest?.TestSteps?.Flatten(step => step.Children)?.FirstOrDefault(step => step.UniqueId == _originalUniqueID);
                if (dataObject.IsServiceTestExecution)
                {
                    var serviceTestSteps = serviceTestStep?.Children;
                    UpdateDebugStateWithAssertions(dataObject, serviceTestSteps?.ToList());
                    if (serviceTestStep != null)
                    {
                        var testRunResult = new TestRunResult();
                        GetFinalTestRunResult(serviceTestStep, testRunResult);
                        serviceTestStep.Result = testRunResult;
                    }
                }
                dataObject.ParentInstanceID = _previousParentId;
                dataObject.ForEachNestingLevel--;
                dataObject.IsDebugNested = false;
                if (dataObject.IsDebugMode())
                {
                    if (dataObject.IsServiceTestExecution && serviceTestStep != null)
                    {
                        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);
                    }
                    DispatchDebugState(dataObject, StateType.Duration, 0);
                }
                // Handle Errors
                if (allErrors.HasErrors())
                {
                    dataObject.ParentInstanceID = _previousParentId;
                    dataObject.ForEachNestingLevel--;
                    dataObject.IsDebugNested = false;
                    // Handle Errors
                    if (allErrors.HasErrors())
                    {
                        DisplayAndWriteError("DsfForEachActivity", allErrors);
                        foreach (var fetchError in allErrors.FetchErrors())
                        {
                            dataObject.Environment.AddError(fetchError);
                        }

                        dataObject.ParentInstanceID = _previousParentId;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            lock (_forEachExecutionObject)
            {
                _previousParentId = dataObject.ParentInstanceID;
                _debugInputs      = new List <DebugItem>();
                _debugOutputs     = new List <DebugItem>();



                dataObject.ForEachNestingLevel++;
                ErrorResultTO  allErrors = new ErrorResultTO();
                IIndexIterator itr       = null;
                InitializeDebug(dataObject);
                try
                {
                    ErrorResultTO      errors;
                    ForEachBootstrapTO exePayload = FetchExecutionType(dataObject, dataObject.Environment, out errors, update);

                    foreach (var err in errors.FetchErrors())
                    {
                        dataObject.Environment.AddError(err);
                    }
                    itr = exePayload.IndexIterator;


                    string error;
                    ForEachInnerActivityTO innerA = GetInnerActivity(out error);
                    var exeAct = innerA.InnerActivity;
                    allErrors.AddError(error);
                    if (dataObject.IsDebugMode())
                    {
                        DispatchDebugState(dataObject, StateType.Before, update);
                    }
                    dataObject.ParentInstanceID = UniqueID;
                    dataObject.IsDebugNested    = true;
                    if (dataObject.IsDebugMode())
                    {
                        DispatchDebugState(dataObject, StateType.After, update);
                    }
                    exePayload.InnerActivity = innerA;


                    while (itr.HasMore())
                    {
                        operationalData = exePayload;
                        int idx         = exePayload.IndexIterator.FetchNextIndex();
                        int innerupdate = 0;
                        if (exePayload.ForEachType != enForEachType.NumOfExecution)
                        {
                            innerupdate = idx;
                        }

                        exeAct.Execute(dataObject, innerupdate);


                        operationalData.IncIterationCount();
                    }
                    if (errors.HasErrors())
                    {
                        allErrors.MergeErrors(errors);
                    }


                    if (dataObject.IsDebugMode())
                    {
                        _debugOutputs = new List <DebugItem>();
                        _debugOutputs = new List <DebugItem>();
                        DispatchDebugState(dataObject, StateType.Duration, 0);
                    }
                }
                catch (Exception e)
                {
                    Dev2Logger.Log.Error("DSFForEach", e);
                    allErrors.AddError(e.Message);
                }
                finally
                {
                    if (itr != null)
                    {
                        if (ForEachType != enForEachType.NumOfExecution)
                        {
                            RestoreHandlerFn();
                        }
                    }
                    dataObject.ParentInstanceID = _previousParentId;
                    dataObject.ForEachNestingLevel--;
                    dataObject.IsDebugNested = false;
                    // Handle Errors
                    if (allErrors.HasErrors())
                    {
                        dataObject.ParentInstanceID = _previousParentId;
                        dataObject.ForEachNestingLevel--;
                        dataObject.IsDebugNested = false;
                        // Handle Errors
                        if (allErrors.HasErrors())
                        {
                            DisplayAndWriteError("DsfForEachActivity", allErrors);
                            foreach (var fetchError in allErrors.FetchErrors())
                            {
                                dataObject.Environment.AddError(fetchError);
                            }

                            dataObject.ParentInstanceID = _previousParentId;
                        }
                    }
                }
            }
        }