public virtual IDev2Activity Execute(IDSFDataObject data)
        {
            try
            {
                var className = GetType().Name;
                Tracker.TrackEvent(TrackerEventGroup.ActivityExecution, className);

                ExecuteTool(data);
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error("OnExecute", ex);
                var errorString   = ex.Message;
                var errorResultTO = new ErrorResultTO();
                errorResultTO.AddError(errorString);
            }
            finally
            {
                if (!_isExecuteAsync || _isOnDemandSimulation)
                {
                    DoErrorHandling(data);
                }
            }


            if (NextNodes != null && NextNodes.Count() > 0)
            {
                NextNodes.First().Execute(data);
                return(NextNodes.First());
            }
            return(null);
        }
        public virtual IDev2Activity Execute(IDSFDataObject data, int update)
        {
            try
            {
                var className = GetType().Name;
                Tracker.TrackEvent(TrackerEventGroup.ActivityExecution, className);
                _debugInputs  = new List <DebugItem>();
                _debugOutputs = new List <DebugItem>();
                ExecuteTool(data, update);
            }
            catch (Exception ex)
            {
                data.Environment.AddError(ex.Message);
                Dev2Logger.Log.Error("OnExecute", ex);
            }
            finally
            {
                if (!_isExecuteAsync || _isOnDemandSimulation)
                {
                    DoErrorHandling(data, update);
                }
            }


            if (NextNodes != null && NextNodes.Any())
            {
                return(NextNodes.First());
            }
            return(null);
        }
 public override IDev2Activity Execute(IDSFDataObject data)
 {
     ExecuteTool(data);
     if (NextNodes != null && NextNodes.Count() > 0)
     {
         NextNodes.First().Execute(data);
         return(NextNodes.First());
     }
     return(null);
 }
        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
        }
Пример #5
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);
            }
        }