예제 #1
0
 protected override object Invoke(MethodInfo targetMethod, object[] args)
 {
     if (!mHandlers.TryGetValue(targetMethod.Name, out ActionHandlerProxy handler))
     {
         var error = new ENException($"{targetMethod.Name} action not found!");
         error.EventError = EventError.NotFound;
         throw error;
     }
     else
     {
         if (!handler.IsTaskResult)
         {
             var error = new ENException("Definition is not supported, please define task with return value!");
             error.EventError = EventError.NotSupport;
             throw error;
         }
         var input = new EventInput();
         input.ID        = EventCenter.GetInputID();
         input.EventPath = handler.Url;
         input.Data      = args;
         if (Actor != EventCenter.ACTOR_NULL_TAG)
         {
             input.Properties = new Dictionary <string, string>();
             input.Properties[EventCenter.ACTOR_TAG] = this.Actor;
         }
         if (mHeader.Count > 0)
         {
             if (input.Properties == null)
             {
                 input.Properties = new Dictionary <string, string>();
             }
             foreach (var item in mHeader)
             {
                 input.Properties[item.Key] = item.Value;
             }
         }
         var            task      = handler.GetCompletionSource();
         ProxyInputWork inputWork = new ProxyInputWork {
             CompletionSource = task, Input = input, EventCenter = EventCenter, DispatchProxy = this
         };
         if (Actor == EventCenter.ACTOR_NULL_TAG)
         {
             if (EventCenter.EnabledLog(LogType.Debug))
             {
                 EventCenter.Log(LogType.Debug, $"{input.Token} {Type.Name} proxy executing {input.EventPath}");
             }
         }
         else
         {
             if (EventCenter.EnabledLog(LogType.Debug))
             {
                 EventCenter.Log(LogType.Debug, $"{input.Token} {Type.Name} proxy {Type.Name}/{Actor} actor executing {input.EventPath} ");
             }
         }
         inputWork.Execute();
         return(task.GetTask());
     }
 }