Ejemplo n.º 1
0
        /// <summary>
        /// 接入事件,也就是收到对方的调用事件
        /// </summary>
        /// <param name="event"></param>
        public static void Accept(DTObject @event)
        {
            var key     = EventEntry.GetEventKey(@event);
            var args    = @event.GetObject("args");
            var source  = EventFactory.GetLocalEvent(key.EventName, args, true);
            var queueId = key.EventId;

            EventRestorer.UseQueue(queueId, true, (callback) =>
            {
                EventTrigger.Start(key.EventId, source, true, callback); //我们把调用方指定的事件编号作为本地的事件队列编号
            },
                                   (ex) =>
            {
                //发生了错误就发布出去,通知失败了
                EventTrigger.PublishRaiseFailed(AppContext.Identity, key, ex.GetCompleteInfo()); //再恢复
            });
        }
Ejemplo n.º 2
0
        private static void Reverse(EventQueue queue, EventEntry entry)
        {
            if (entry.IsEmpty() ||
                entry.Status == EventStatus.Reversed)//已回逆的不用回逆,保证幂等性
            {
                return;
            }

            var args = entry.GetArgs();

            if (entry.IsLocal)
            {
                ReverseLocalEvent(entry, args);
            }
            else
            {
                var identity = queue.GetIdentity();
                ReverseRemoteEvent(entry, identity, args);
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 根据事件条目获取对应的本地定义的事件
 /// </summary>
 /// <param name="entry"></param>
 /// <returns></returns>
 public static DomainEvent GetLocalEvent(EventEntry entry, DTObject args, bool throwError)
 {
     return(GetLocalEvent(entry.EventName, args, throwError));
 }