Ejemplo n.º 1
0
        void DebugOutput(IDSFDataObject dataObject)
        {
            try
            {
                if (dataObject.IsDebugMode())
                {
                    var result          = new List <DebugItem>();
                    var debugOutputBase = new DebugItemStaticDataParams(Result, "");
                    var itemToAdd       = new DebugItem();
                    itemToAdd.AddRange(debugOutputBase.GetDebugItemResult());
                    result.Add(itemToAdd);
                    _debugOutputs = result;

                    if (Inner != null)
                    {
                        Inner.SetDebugOutputs(_debugOutputs);
                    }
                }
            }

            catch (Exception e)
            {
                Dev2Logger.Warn(e.Message, GlobalConstants.WarewolfWarn);
            }
        }
Ejemplo n.º 2
0
        void DebugOutput(IDSFDataObject dataObject)
        {
            try
            {
                if (dataObject.IsDebugMode())
                {
                    List <DebugItem> result   = new List <DebugItem>();
                    var       debugOutputBase = new DebugItemStaticDataParams(Result, "");
                    DebugItem itemToAdd       = new DebugItem();
                    itemToAdd.AddRange(debugOutputBase.GetDebugItemResult());
                    result.Add(itemToAdd);
                    _debugOutputs = result;

                    if (Inner != null)
                    {
                        Inner.SetDebugOutputs(_debugOutputs);
                    }
                }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            // ReSharper restore EmptyGeneralCatchClause
            {
            }
        }
Ejemplo n.º 3
0
        public override IDev2Activity Execute(IDSFDataObject data, int update)
        {
            _previousParentId = data.ParentInstanceID;
            _debugInputs?.Clear();
            _debugOutputs?.Clear();
            _dataObject = data;
            var allErrors = new ErrorResultTO();

            try
            {
                _stateNotifier?.LogActivityExecuteState(this);

                bool firstExecution = true;
                if (_dataObject.Gates.TryGetValue(this, out (RetryState, IEnumerator <bool>)retryState))
                {
                    firstExecution = false;
                }
                else
                {
                    retryState = (new RetryState(), null);
                }
                var isRetry = retryState.Item1.NumberOfRetries > 0;

                if (firstExecution)
                {
                    if (GateOptions.GateOpts is Continue onResume)
                    {
                        retryState.Item2 = onResume.Strategy.Create().GetEnumerator();
                    }
                    _dataObject.Gates.Add(this, retryState);
                    _originalExecutionEnvironment = data.Environment.Snapshot();
                }
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("Retry: " + retryState.Item1.NumberOfRetries.ToString(), "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
                if (firstExecution || !isRetry)
                {
                    if (retryState.Item1.NumberOfRetries > 0)
                    {
                        throw new GateException("gate execution corrupt: first execution with invalid number of retries");
                    }
                    if (_dataObject.IsDebugMode())
                    {
                        var debugItemStaticDataParams = new DebugItemStaticDataParams(nameof(ExecuteNormal), "", true);
                        AddDebugOutputItem(debugItemStaticDataParams);
                    }

                    if (_dataObject.IsServiceTestExecution && _originalUniqueId == Guid.Empty)
                    {
                        _originalUniqueId = Guid.Parse(UniqueID);
                    }

                    return(ExecuteNormal(data, update, allErrors));
                }

                return(ExecuteRetry(data, update, allErrors, retryState.Item2));
            }
Ejemplo n.º 4
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var dsfSwitchSwitches = _dsfSwitch.Switches;
            var hasResult         = false;

            if (dataObject.IsDebugMode())
            {
                InitializeDebug(dataObject);
            }
            IDev2Activity activity = null;

            if (ConditionToUse == "Default")
            {
                if (_dsfSwitch.Default != null)
                {
                    activity = _dsfSwitch.Default.FirstOrDefault();
                    if (dataObject.IsDebugMode())
                    {
                        var debugItemStaticDataParams = new DebugItemStaticDataParams("Default", "", true);
                        AddDebugOutputItem(debugItemStaticDataParams);
                        AddDebugAssertResultItem(debugItemStaticDataParams);
                    }
                    hasResult = true;
                }
            }
            else
            {
                if (dsfSwitchSwitches.ContainsKey(ConditionToUse))
                {
                    activity = dsfSwitchSwitches[ConditionToUse];
                    if (dataObject.IsDebugMode())
                    {
                        var debugItemStaticDataParams = new DebugItemStaticDataParams(ConditionToUse, "", true);
                        AddDebugOutputItem(debugItemStaticDataParams);
                        AddDebugAssertResultItem(debugItemStaticDataParams);
                    }
                    hasResult = true;
                }
            }
            if (dataObject.IsDebugMode() && hasResult)
            {
                DispatchDebugState(dataObject, StateType.After, update);
                DispatchDebugState(dataObject, StateType.Duration, update);
            }

            if (!hasResult)
            {
                throw new ArgumentException($"No matching arm for Switch Mock. Mock Arm value '{ConditionToUse}'. Switch Arms: '{string.Join(",", dsfSwitchSwitches.Select(pair => pair.Key))}'.");
            }
            NextNodes = new List <IDev2Activity> {
                activity
            };
        }
Ejemplo n.º 5
0
        void AddInputDebugItemResultsAfterEvaluate(List <IDebugItem> result, ref string userModel, IExecutionEnvironment env, string expression, out ErrorResultTO error, DebugItem parent = null)
        {
            error = new ErrorResultTO();
            if (expression != null && DataListUtil.IsEvaluated(expression))
            {
                DebugOutputBase debugResult;
                if (error.HasErrors())
                {
                    debugResult = new DebugItemStaticDataParams("", expression, "");
                }
                else
                {
                    string expressiomToStringValue;
                    try
                    {
                        expressiomToStringValue = ExecutionEnvironment.WarewolfEvalResultToString(env.Eval(expression, 0, true));
                    }
                    catch (NullValueInVariableException)
                    {
                        expressiomToStringValue = expression;
                    }
                    // EvaluateExpressiomToStringValue(expression, decisionMode, dataList);
                    userModel   = userModel.Replace(expression, expressiomToStringValue);
                    debugResult = new DebugItemWarewolfAtomResult(expressiomToStringValue, expression, "");
                }

                var itemResults = debugResult.GetDebugItemResult();

                var allReadyAdded = new List <IDebugItemResult>();

                itemResults.ForEach(a =>
                {
                    var found = result.SelectMany(r => r.FetchResultsList())
                                .SingleOrDefault(r => r.Variable.Equals(a.Variable));
                    if (found != null)
                    {
                        allReadyAdded.Add(a);
                    }
                });

                allReadyAdded.ForEach(i => itemResults.Remove(i));

                if (parent == null)
                {
                    result.Add(new DebugItem(itemResults));
                }
                else
                {
                    parent.AddRange(itemResults);
                }
            }
        }
Ejemplo n.º 6
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            _errorsTo = new ErrorResultTO();
            try
            {
                var suspensionId = EvalSuspensionId();
                if (string.IsNullOrWhiteSpace(suspensionId))
                {
                    Response = GlobalConstants.Failed;
                    throw new Exception(ErrorResource.ManualResumptionSuspensionIdBlank);
                }

                if (!_persistenceEnabled)
                {
                    Response = GlobalConstants.Failed;
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                var overrideVariables = "";
                if (OverrideInputVariables)
                {
                    var innerActivity = InnerActivity();
                    overrideVariables = ExecuteOverrideDataFunc(innerActivity);
                }

                Response = _scheduler.ResumeJob(_dataObject, suspensionId, OverrideInputVariables, overrideVariables);
                _stateNotifier?.LogActivityExecuteState(this);

                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("SuspensionID: " + suspensionId, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Override Variables: " + OverrideInputVariables, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Result: " + Response, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }

                return(new List <string> {
                    Response
                });
            }
            catch (Exception ex)
            {
                Response = GlobalConstants.Failed;
                _stateNotifier?.LogExecuteException(ex, this);
                Dev2Logger.Error(nameof(ManualResumptionActivity), ex, GlobalConstants.WarewolfError);
                throw new Exception(ex.GetAllMessages());
            }
        }
Ejemplo n.º 7
0
        void AddInputDebugItemResultsAfterEvaluate(List <IDebugItem> result, ref string userModel, IBinaryDataList dataList, Dev2DecisionMode decisionMode, string expression, out ErrorResultTO error, DebugItem parent = null)
        {
            error = new ErrorResultTO();
            if (expression != null && DataListUtil.IsEvaluated(expression))
            {
                DebugOutputBase debugResult;
                if (error.HasErrors())
                {
                    debugResult = new DebugItemStaticDataParams("", expression, "");
                }
                else
                {
                    var expressiomToStringValue = EvaluateExpressiomToStringValue(expression, decisionMode, dataList);
                    userModel = userModel.Replace(expression, expressiomToStringValue);
                    ErrorResultTO        errors;
                    IDataListCompiler    compiler         = DataListFactory.CreateDataListCompiler();
                    IBinaryDataListEntry expressionsEntry = compiler.Evaluate(dataList.UID, enActionType.User, expression, false, out errors);
                    debugResult = new DebugItemVariableParams(expression, "", expressionsEntry, dataList.UID);
                }

                var itemResults = debugResult.GetDebugItemResult();

                var allReadyAdded = new List <IDebugItemResult>();

                itemResults.ForEach(a =>
                {
                    var found = result.SelectMany(r => r.FetchResultsList())
                                .SingleOrDefault(r => r.Variable.Equals(a.Variable));
                    if (found != null)
                    {
                        allReadyAdded.Add(a);
                    }
                });

                allReadyAdded.ForEach(i => itemResults.Remove(i));

                if (parent == null)
                {
                    result.Add(new DebugItem(itemResults));
                }
                else
                {
                    parent.AddRange(itemResults);
                }
            }
        }
Ejemplo n.º 8
0
        protected override void ExecuteTool(IDSFDataObject dataObject, int update)
        {
            var trueArmText  = _dsfDecision.Conditions.TrueArmText;
            var falseArmText = _dsfDecision.Conditions.FalseArmText;

            if (dataObject.IsDebugMode())
            {
                DispatchDebugState(dataObject, StateType.Before, 0, null, null, true);
            }
            var hasResult = false;

            if (NameOfArmToReturn == falseArmText)
            {
                NextNodes = _dsfDecision.FalseArm;
                if (dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams(falseArmText, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    AddDebugAssertResultItem(debugItemStaticDataParams);
                }

                hasResult = true;
            }
            if (NameOfArmToReturn == trueArmText)
            {
                NextNodes = _dsfDecision.TrueArm;
                if (dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams(trueArmText, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    AddDebugAssertResultItem(debugItemStaticDataParams);
                }
                hasResult = true;
            }
            if (dataObject.IsDebugMode() && hasResult)
            {
                DispatchDebugState(dataObject, StateType.After, update);
                DispatchDebugState(dataObject, StateType.Duration, update);
            }
            if (!hasResult)
            {
                throw new ArgumentException($"No matching arm for Decision Mock. Mock Arm value '{NameOfArmToReturn}'. Decision Arms True Arm: '{trueArmText}' False Arm: '{falseArmText}'");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns true if all conditions are passing
        /// Returns true if there are no conditions
        /// Returns false if any condition is failing
        /// Returns false if any variable does not exist
        /// Returns false if there is an exception of any kind
        /// </summary>
        private bool Passing(int update)
        {
            if (!Conditions.Any())
            {
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams(nameof(Passing), "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
                return(true);
            }

            try
            {
                var res = Conditions.Select(a => a.Eval(GetArgumentsFunc, _dataObject.Environment.HasErrors()));
                return(res.All(o => o));
            }
            catch (Exception e)
            {
                Dev2Logger.Warn("failed checking passing state of gate", e, _dataObject?.ExecutionID?.ToString());
                return(false);
            }
        }
        public override IDev2Activity Execute(IDSFDataObject data, int update)
        {
            _previousParentId = data.ParentInstanceID;
            _debugInputs?.Clear();
            _debugOutputs?.Clear();
            _dataObject = data;
            _update     = update;
            _originalExecutionEnvironment = data.Environment.Snapshot();

            _suspensionId = "";
            var allErrors = new ErrorResultTO();

            try
            {
                _dataObject.ForEachNestingLevel++;
                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                if (NextNodes is null)
                {
                    throw new Exception(ErrorResource.NextNodeRequiredForSuspendExecution);
                }

                var persistScheduleValue = PersistSchedulePersistValue();

                if (string.IsNullOrEmpty(persistScheduleValue))
                {
                    throw new Exception(string.Format(ErrorResource.SuspendOptionValueNotSet, GetSuspendValidationMessageType(SuspendOption)));
                }

                var currentEnvironment   = _originalExecutionEnvironment.ToJson();
                var currentuserprincipal = _dataObject.ExecutingUser.Identity.Name;
                var versionNumber        = _dataObject.VersionNumber.ToString();
                var resourceId           = _dataObject.ResourceID;
                if (EncryptData)
                {
                    currentEnvironment   = DpapiWrapper.Encrypt(currentEnvironment);
                    currentuserprincipal = DpapiWrapper.Encrypt(currentuserprincipal);
                }

                var firstActivity = NextNodes.First();
                var activityId    = Guid.Parse(firstActivity?.UniqueID ??
                                               throw new Exception(GlobalConstants.NextNodeIDNotFound));
                var values = new Dictionary <string, StringBuilder>
                {
                    { "resourceID", new StringBuilder(resourceId.ToString()) },
                    { "environment", new StringBuilder(currentEnvironment) },
                    { "startActivityId", new StringBuilder(activityId.ToString()) },
                    { nameof(versionNumber), new StringBuilder(versionNumber) },
                    { nameof(currentuserprincipal), new StringBuilder(currentuserprincipal) }
                };

                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("Allow Manual Resumption: " + AllowManualResumption, "", true);
                    AddDebugInputItem(debugItemStaticDataParams);
                }

                DispatchDebug(_dataObject, StateType.Before, _update);
                _suspensionId = _scheduler.CreateAndScheduleJob(SuspendOption, persistScheduleValue, values);

                _dataObject.ParentInstanceID = UniqueID;
                _dataObject.IsDebugNested    = true;
                DispatchDebug(_dataObject, StateType.After, _update);

                Response = _suspensionId;
                _dataObject.Environment.Assign(Result, Response, 0);
                _dataObject.Environment.CommitAssign();
                _stateNotifier?.LogActivityExecuteState(this);
                Dev2Logger.Debug($"{_dataObject.ServiceName} execution suspended: SuspensionId {_suspensionId} scheduled", GlobalConstants.WarewolfDebug);
                if (AllowManualResumption)
                {
                    ExecuteSaveDataFunc();
                }

                if (_dataObject.IsServiceTestExecution && _originalUniqueID == Guid.Empty)
                {
                    _originalUniqueID = Guid.Parse(UniqueID);
                }
            }
            catch (Hangfire.BackgroundJobClientException)
            {
                LogException(new Exception(ErrorResource.BackgroundJobClientCreateFailed), allErrors);
            }
            catch (Exception ex)
            {
                _stateNotifier?.LogExecuteException(ex, this);
                LogException(ex, allErrors);
            }
            finally
            {
                var serviceTestStep = HandleServiceTestExecution(_dataObject);
                _dataObject.ParentInstanceID = _previousParentId;
                _dataObject.ForEachNestingLevel--;
                _dataObject.IsDebugNested = false;
                HandleDebug(_dataObject, serviceTestStep);
                HandleErrors(_dataObject, allErrors);
            }
            return(null); //fire once the rest should be done on resumption service
        }
Ejemplo n.º 11
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            _errorsTo     = new ErrorResultTO();
            _suspensionId = "";
            var allErrors  = new ErrorResultTO();
            var dataObject = _dataObject;

            try
            {
                dataObject.ForEachNestingLevel++;
                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                if (NextNodes is null)
                {
                    throw new Exception(ErrorResource.NextNodeRequiredForSuspendExecution);
                }

                var activityId = Guid.Parse(NextNodes.First()?.UniqueID ??
                                            throw new Exception(GlobalConstants.NextNodeIDNotFound));
                var currentEnvironment   = _dataObject.Environment.ToJson();
                var currentuserprincipal = _dataObject.ExecutingUser.Identity.Name;
                var versionNumber        = _dataObject.VersionNumber.ToString();
                if (EncryptData)
                {
                    currentEnvironment   = DpapiWrapper.Encrypt(currentEnvironment);
                    currentuserprincipal = DpapiWrapper.Encrypt(currentuserprincipal);
                }

                var values = new Dictionary <string, StringBuilder>
                {
                    { "resourceID", new StringBuilder(_dataObject.ResourceID.ToString()) },
                    { "environment", new StringBuilder(currentEnvironment) },
                    { "startActivityId", new StringBuilder(activityId.ToString()) },
                    { nameof(versionNumber), new StringBuilder(_dataObject.VersionNumber.ToString()) },
                    { nameof(currentuserprincipal), new StringBuilder(currentuserprincipal) }
                };
                var persistScheduleValue = PersistSchedulePersistValue();
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("Allow Manual Resumption: " + AllowManualResumption, "", true);
                    AddDebugInputItem(debugItemStaticDataParams);
                }

                DispatchDebug(dataObject, StateType.Before, _update);
                _suspensionId = _scheduler.CreateAndScheduleJob(SuspendOption, persistScheduleValue, values);

                dataObject.ParentInstanceID = UniqueID;
                dataObject.IsDebugNested    = true;
                DispatchDebug(dataObject, StateType.After, _update);

                Response = _suspensionId;
                _dataObject.Environment.Assign(Result, _suspensionId, 0);
                _dataObject.Environment.CommitAssign();
                _stateNotifier?.LogActivityExecuteState(this);
                Dev2Logger.Debug($"{_dataObject.ServiceName} execution suspended: SuspensionId {_suspensionId} scheduled", GlobalConstants.WarewolfDebug);
                if (AllowManualResumption)
                {
                    ExecuteSaveDataFunc();
                }

                if (_dataObject.IsServiceTestExecution && _originalUniqueID == Guid.Empty)
                {
                    _originalUniqueID = Guid.Parse(UniqueID);
                }

                _dataObject.StopExecution = true;
                return(new List <string> {
                    _suspensionId
                });
            }
            catch (Exception ex)
            {
                _stateNotifier?.LogExecuteException(ex, this);
                Dev2Logger.Error(nameof(SuspendExecutionActivity), ex, GlobalConstants.WarewolfError);
                _dataObject.StopExecution = true;
                allErrors.AddError(ex.GetAllMessages());
                throw;
            }
            finally
            {
                var serviceTestStep = HandleServiceTestExecution(dataObject);
                dataObject.ParentInstanceID = _previousParentId;
                dataObject.ForEachNestingLevel--;
                dataObject.IsDebugNested = false;
                HandleDebug(dataObject, serviceTestStep);
                HandleErrors(dataObject, allErrors);
            }
        }
Ejemplo n.º 12
0
        protected override List <string> PerformExecution(Dictionary <string, string> evaluatedValues)
        {
            var allErrors = new ErrorResultTO();

            Response = string.Empty;
            try
            {
                var suspensionId = EvalSuspensionId();
                if (string.IsNullOrWhiteSpace(suspensionId))
                {
                    throw new Exception(ErrorResource.ManualResumptionSuspensionIdBlank);
                }

                if (!_persistenceEnabled)
                {
                    throw new Exception(ErrorResource.PersistenceSettingsNoConfigured);
                }

                _logger.Info("Performing Resume of job {" + suspensionId + "}, connection established.", suspensionId);

                const string OverrideVariables = "";
                if (OverrideInputVariables)
                {
                    var persistedValues = _scheduler.GetPersistedValues(suspensionId);
                    if (string.IsNullOrEmpty(persistedValues.SuspendedEnvironment))
                    {
                        throw new Exception(ErrorResource.ManualResumptionSuspensionEnvBlank);
                    }

                    if (persistedValues.SuspendedEnvironment.StartsWith("Failed:"))
                    {
                        throw new Exception(persistedValues.SuspendedEnvironment);
                    }
                    var envArray     = _dataObject.Environment.ToJson();
                    var resumeObject = _dataObject;
                    resumeObject.StartActivityId = persistedValues.StartActivityId;
                    resumeObject.Environment.FromJson(persistedValues.SuspendedEnvironment);
                    resumeObject.Environment.FromJson(envArray);
                    resumeObject.ExecutingUser = persistedValues.ExecutingUser;
                    InnerActivity(resumeObject, _update);
                    Response = _scheduler.ManualResumeWithOverrideJob(resumeObject, suspensionId);
                }
                else
                {
                    Response = _scheduler.ResumeJob(_dataObject, suspensionId, OverrideInputVariables, OverrideVariables);
                }

                _stateNotifier?.LogActivityExecuteState(this);
                if (_dataObject.IsDebugMode())
                {
                    var debugItemStaticDataParams = new DebugItemStaticDataParams("SuspensionID: " + suspensionId, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Override Variables: " + OverrideInputVariables, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                    debugItemStaticDataParams = new DebugItemStaticDataParams("Result: " + Response, "", true);
                    AddDebugOutputItem(debugItemStaticDataParams);
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                LogException(new Exception(ErrorResource.BackgroundJobClientResumeFailed), allErrors);
            }
            catch (Exception ex)
            {
                LogException(ex, allErrors);
            }
            finally
            {
                HandleErrors(_dataObject, allErrors);
            }

            return(new List <string> {
                Response
            });
        }