コード例 #1
0
ファイル: EventLogger.cs プロジェクト: wangpengxpy/nactivity
        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);
            }
        }
コード例 #2
0
        /// <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);
            }
        }