Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="ownerEntry"></param>
        /// <param name="entries"></param>
        /// <param name="idCount"></param>
        private void FillPreEntries(DomainEvent source, EventEntry sourceEntry, List <EventEntry> entries, ref int idCount)
        {
            const string argsCode = ""; //条目事件的参数在队列没执行的时候,是空的

            foreach (var eventName in source.PreEvents)
            {
                var local = EventFactory.GetLocalEvent(eventName, DTObject.Empty, false);
                if (local == null)
                {
                    idCount++;
                    var entry = new EventEntry(sourceEntry, idCount, eventName, Guid.NewGuid(), argsCode);
                    entries.Add(entry);
                }
                else
                {
                    //将本地事件转为条目
                    idCount++;
                    var localEntry = new EventEntry(sourceEntry, idCount, eventName, Guid.NewGuid(), argsCode);
                    FillPreEntries(local, localEntry, entries, ref idCount);
                    entries.Add(localEntry);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 触发队列事件
        /// </summary>
        /// <param name="queue"></param>
        private static void Raise(Guid queueId, EventCallback callback)
        {
            bool isSucceeded = false;
            bool isRunning   = false;

            while (!isRunning && !isSucceeded)
            {
                DataContext.NewScope(() =>
                {
                    //触发队列事件
                    var queue = EventQueue.Find(queueId);
                    var entry = queue.GetPreRaise();
                    if (!entry.IsEmpty())
                    {
                        var args = entry.GetArgs(); //获取条目的事件参数
                        EventLog.FlushRaise(queue, entry);
                        if (entry.IsLocal)
                        {
                            var source = entry.GetSourceEvent();
                            var local  = EventFactory.GetLocalEvent(entry, args, true);
                            RaiseLocalEvent(entry, local, source);
                        }
                        else
                        {
                            var identity = queue.GetIdentity();
                            RaiseRemoteEvent(entry, identity, args);
                        }
                    }
                    EventQueue.Update(queue);
                    isRunning   = queue.IsRunning;
                    isSucceeded = queue.IsSucceeded;
                }, true);
            }

            bool        completed = false;
            DomainEvent @event    = null;

            if (isSucceeded)
            {
                DataContext.NewScope(() =>
                {
                    var queue = EventQueue.Find(queueId);
                    if (queue.IsSubqueue)
                    {
                        var entry    = queue.Source;
                        var argsCode = entry.ArgsCode;

                        var identity  = queue.GetIdentity();
                        var eventName = entry.EventName;
                        var eventId   = entry.EventId;
                        callback.Mount(() => //挂载回调事件,这样所有操作执行完毕后,会发布事件被完成的消息
                        {
                            //发布事件被完成的消息
                            PublishRaiseSucceeded(identity, eventName, eventId, argsCode);
                        });
                    }
                    else
                    {
                        //不是被外界调用的,所以整个事件场景已完成
                        completed = true;
                        @event    = queue.Source.GetSourceEvent();
                    }
                }, true);
                EventLog.FlushEnd(queueId); //指示恢复管理器事件队列的操作已经全部完成
            }

            if (completed)
            {
                callback.Mount(() => //挂载回调事件
                {
                    DomainEvent.OnSucceeded(queueId, @event);
                });
            }
        }