public async Task Execute()
 {
     try
     {
         var result = Handler.MethodHandler.Execute(Controller, Input.Data);
         if (result is Task task)
         {
             await task;
         }
         object data = Handler.GetResult(result);
         mEventOutput.EventError = EventError.Success;
         if (data != null)
         {
             mEventOutput.Data = new object[] { data }
         }
         ;
     }
     catch (Exception e_)
     {
         mEventOutput.EventError = EventError.InnerError;
         mEventOutput.Data       = new object[] { $"Process event {Input.EventPath} error {e_.Message}" };
         if (EventCenter.EnabledLog(LogType.Error))
         {
             EventCenter.Log(LogType.Error, $"{Input.Token} process event {Input.EventPath} error {e_.Message}@{e_.StackTrace}");
         }
     }
     finally
     {
         mEventCompleted.Completed(mEventOutput);
     }
 }
Beispiel #2
0
 private void OnFlush(EventCenter center, ActorCollectionItem item)
 {
     if (item.Actor is IActorState actorState)
     {
         try
         {
             actorState.ActorFlush();
             if (center.EnabledLog(LogType.Debug))
             {
                 center.Log(LogType.Debug, $"Free {item.ActorID}@{item.Interface.Name} actor flush success!");
             }
         }
         catch (Exception e_)
         {
             if (center.EnabledLog(LogType.Error))
             {
                 center.Log(LogType.Error, $"Free {item.ActorID}@{item.Interface.Name} actor flush error {e_.Message}@{e_.StackTrace}!");
             }
         }
     }
 }
Beispiel #3
0
 public void Free(EventCenter center, bool clearAll = false)
 {
     foreach (var item in mServices.Values)
     {
         if (EventCenter.Watch.ElapsedMilliseconds > item.TimeOut || clearAll)
         {
             OnFlush(center, item);
             mServices.TryRemove(item.ActorID, out ActorCollectionItem value);
             if (center.EnabledLog(LogType.Debug))
             {
                 center.Log(LogType.Debug, $"Free {item.ActorID}@{item.Interface.Name} success!");
             }
         }
     }
 }
        public async Task Execute()
        {
            IList <IEventActionExecuteHandler> eaeh = EventCenter.ExecuteHandlers;

            ActionFilterAttribute[] filters = Handler.Filters;
            int  index     = 0;
            bool _continue = true;
            int  subindex  = 0;

            try
            {
                if (Controller is IActorState state)
                {
                    state.Token     = Input.Token;
                    state.EventPath = Input.EventPath;
                    if (ActorItem != null)
                    {
                        state.Sequence = ActorItem.GetSequence();
                    }
                }
                if (EventCenter.EnabledLog(LogType.Debug))
                {
                    EventCenter.Log(LogType.Debug, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} beginning invoke method");
                }
                EventCenter.EventActionContext = this;
                for (int i = 0; i < eaeh.Count; i++)
                {
                    _continue = eaeh[i].Executing(EventCenter, Handler, Input, mEventOutput);
                    index++;
                    if (!_continue)
                    {
                        break;
                    }
                }
                for (int i = 0; i < filters.Length; i++)
                {
                    _continue = filters[i].Executing(EventCenter, Handler, Input, mEventOutput);
                    subindex++;
                    if (!_continue)
                    {
                        break;
                    }
                }
                if (_continue)
                {
                    var result = Handler.MethodHandler.Execute(Controller, Input.Data);
                    if (result is Task task)
                    {
                        await task;
                    }
                    object data = Handler.GetResult(result);
                    mEventOutput.EventError = EventError.Success;
                    if (data != null)
                    {
                        mEventOutput.Data = new object[] { data }
                    }
                    ;
                    if (EventCenter.EnabledLog(LogType.Debug))
                    {
                        EventCenter.Log(LogType.Debug, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} invoke method completed");
                    }
                }
            }
            catch (Exception e_)
            {
                mEventOutput.EventError = EventError.InnerError;
                mEventOutput.Data       = new object[] { $"Process event {Input.EventPath} error {e_.Message}" };
                if (EventCenter.EnabledLog(LogType.Error))
                {
                    EventCenter.Log(LogType.Error, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} invoke method error {e_.Message}@{e_.StackTrace}");
                }
            }
            finally
            {
                for (int i = subindex - 1; i >= 0; i--)
                {
                    try
                    {
                        filters[i].Executed(EventCenter, Handler, Input, mEventOutput);
                    }
                    catch (Exception e_)
                    {
                        if (EventCenter.EnabledLog(LogType.Error))
                        {
                            EventCenter.Log(LogType.Error, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} filter invoke executed error {e_.Message}@{e_.StackTrace}");
                        }
                    }
                }

                for (int i = index - 1; i >= 0; i--)
                {
                    try
                    {
                        eaeh[i].Executed(EventCenter, Handler, Input, mEventOutput);
                    }
                    catch (Exception e_)
                    {
                        if (EventCenter.EnabledLog(LogType.Error))
                        {
                            EventCenter.Log(LogType.Error, $"[{Input.ID}]{Input.Token} process event {Input.EventPath} invoke executed handler error {e_.Message}@{e_.StackTrace}");
                        }
                    }
                }

                mEventCompleted.Completed(mEventOutput);
            }
        }