Esempio n. 1
0
        public virtual void OnEvent(IActivitiEvent @event)
        {
            IEventLoggerEventHandler eventHandler = GetEventHandler(@event);

            if (eventHandler != null)
            {
                // Events are flushed when command context is closed
                ICommandContext currentCommandContext = Context.CommandContext;
                IEventFlusher   eventFlusher          = (IEventFlusher)currentCommandContext.GetAttribute(EVENT_FLUSHER_KEY);

                if (eventFlusher == null)
                {
                    eventFlusher = CreateEventFlusher();
                    if (eventFlusher == null)
                    {
                        eventFlusher = new DatabaseEventFlusher(); // Default
                    }
                    currentCommandContext.AddAttribute(EVENT_FLUSHER_KEY, eventFlusher);

                    currentCommandContext.AddCloseListener(eventFlusher);
                    currentCommandContext.AddCloseListener(new CommandContextCloseListenerAnonymousInnerClass(this));
                }

                eventFlusher.AddEventHandler(eventHandler);
            }
        }
Esempio n. 2
0
        public virtual object Execute(ICommandContext commandContext)
        {
            if (jobId is null)
            {
                throw new ActivitiIllegalArgumentException("jobId and job is null");
            }

            IJob job = commandContext.JobEntityManager.FindById <IJob>(new KeyValuePair <string, object>("id", jobId));

            if (job == null)
            {
                throw new JobNotFoundException(jobId);
            }

            if (log.IsEnabled(LogLevel.Debug))
            {
                log.LogDebug($"Executing job {job.Id}");
            }

            commandContext.AddCloseListener(new FailedJobListener(commandContext.ProcessEngineConfiguration.CommandExecutor, job));

            try
            {
                commandContext.JobManager.Execute(job);
            }
            catch (Exception exception)
            {
                // Finally, Throw the exception to indicate the ExecuteJobCmd failed
                throw new ActivitiException("Job " + jobId + " failed", exception);
            }

            return(null);
        }
        public override T Execute <T>(CommandConfig config, ICommand <T> command)
        {
            ICommandContext commandContext = Context.CommandContext;
            // Storing it in a variable, to reference later (it can change during command execution)
            bool isReused = commandContext.Reused;

            try
            {
                if (transactionContextFactory != null && !isReused)
                {
                    ITransactionContext transactionContext = transactionContextFactory.OpenTransactionContext(commandContext);
                    Context.TransactionContext = transactionContext;
                    commandContext.AddCloseListener(new TransactionCommandContextCloseListener(transactionContext));
                }

                return(next.Execute(config, command));
            }
            catch (Exception e)
            {
                throw;
            }
            finally
            {
                if (transactionContextFactory != null && !isReused)
                {
                    Context.RemoveTransactionContext();
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="element"></param>

        public virtual void Add(E element)
        {
            ICommandContext currentCommandContext = CurrentCommandContext;
            IList <E>       attributes            = currentCommandContext.GetGenericAttribute <IList <E> >(AttributeKey);

            if (attributes == null)
            {
                attributes = new List <E>();
                currentCommandContext.AddAttribute(AttributeKey, attributes);
            }
            attributes.Add(element);

            if (!currentCommandContext.HasCloseListener(CloseListenerClass))
            {
                currentCommandContext.AddCloseListener(CloseListener);
            }
        }