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); } }
public void Execute(IEventInput input, IEventCompleted callBackEvent) { if (input.ID == 0) { input.ID = GetInputID(); } EventOutput output = new EventOutput(); output.Token = input.Token; output.ID = input.ID; output.EventError = EventError.Success; EventActionHandler handler = GetActionHandler(input.EventPath); if (handler == null) { output.EventError = EventError.NotFound; output.Data = new object[] { $"Process event error {input.EventPath} not found!" }; if (EnabledLog(LogType.Warring)) { Log(LogType.Warring, $"[{input.ID}]{input.Token} Process event error {input.EventPath} not found!"); } callBackEvent.Completed(output); } else { OnExecute(input, output, handler, callBackEvent); } }
public void Execute(IEventInput input, IEventCompleted callBackEvent) { if (input.ID == 0) { input.ID = GetInputID(); } EventOutput output = new EventOutput(); output.Token = input.Token; output.ID = input.ID; output.EventError = EventError.Success; EventActionHandler handler = GetActionHandler(input.EventPath); if (handler == null) { output.EventError = EventError.NotFound; output.Data = new object[] { $"Process event error {input.EventPath} not found!" }; if (EnabledLog(LogType.Warring)) { Log(LogType.Warring, $"{input.Token} Process event error {input.EventPath} not found!"); } callBackEvent.Completed(output); } else { try { OnExecute(input, output, handler, callBackEvent); } catch (Exception e_) { output.EventError = EventError.InnerError; output.Data = new object[] { $"Process event {input.EventPath} error {e_.Message}" }; if (EnabledLog(LogType.Error)) { Log(LogType.Error, $"{input.Token} process event {input.EventPath} error {e_.Message}@{e_.StackTrace}"); } callBackEvent.Completed(output); } } }
private async void OnExecute(IEventInput input, EventOutput output, EventActionHandler handler, IEventCompleted callBackEvent) { try { string actorID = null; input.Properties?.TryGetValue(ACTOR_TAG, out actorID); string actorPath = null; object controller = null; NextQueue nextQueue = null; ActorCollection.ActorItem item = null; if (string.IsNullOrEmpty(actorID)) { nextQueue = this.InputNextQueue.Next(this.NextQueueWaits); if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} Process event {input.EventPath}"); } controller = handler.Controller; if (handler.ThreadType == ThreadType.SingleQueue) { nextQueue = handler.GetNextQueue(input.Data); } if (!handler.SingleInstance) { controller = CreateController(handler.ControllerType); } } else { item = handler.Actors.Get(actorID); if (item == null) { actorPath = "/" + handler.ServiceName + "/" + actorID; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} {handler.ControllerType.Name}@{actorPath} create actor"); } item = new ActorCollection.ActorItem(); item.ActorID = actorID; item.Actor = CreateController(handler.Actors.ServiceType); item.ServiceName = handler.ServiceName; item.Interface = handler.Interface; item.TimeOut = EventCenter.Watch.ElapsedMilliseconds + ActorFreeTime * 1000; item = handler.Actors.Set(actorID, item, out bool add); controller = item.Actor; if (controller is IActorState state) { state.ActorID = actorID; state.ActorPath = actorPath; state.EventCenter = this; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} {handler.ControllerType.Name}@{actorPath} actor initialized"); } } } else { item.TimeOut = EventCenter.Watch.ElapsedMilliseconds + ActorFreeTime * 1000; controller = item.Actor; } nextQueue = item.NextQueue; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} Process event {input.EventPath} in /{item.ServiceName}/{item.ActorID} actor"); } await item.Initialize(); } EventActionHandlerContext context = new EventActionHandlerContext(this, input, handler, controller, nextQueue, item); context.Execute(output, callBackEvent); } catch (Exception e_) { output.EventError = EventError.InnerError; output.Data = new object[] { $"Process event {input.EventPath} error {e_.Message}" }; if (EnabledLog(LogType.Error)) { Log(LogType.Error, $"[{input.ID}]{input.Token} process event {input.EventPath} error {e_.Message}@{e_.StackTrace}"); } callBackEvent.Completed(output); } }
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); } }