public async Task Handle(string message, IServiceProvider provider) { var settings = NewtonsoftJsonUtil.UseCustomNewtonsoftSettings(); var eventData = JsonConvert.DeserializeObject(message, EventType, settings); var handler = provider.GetService(HandlerType); await(Task) HandlerType.GetMethod("Handle") .Invoke(handler, new[] { eventData }); }
/// <summary> /// return an integer that specifies where to place the menu. /// </summary> /// <returns></returns> public virtual PreferredLocation GetMenuPreferedLocation() { var TargetMethod = HandlerType.GetMethod("GetMenuPreferedLocation"); if (TargetMethod == null) { return(PreferredLocation.Default); } return((PreferredLocation)TargetMethod.Invoke(Handler, null)); }
public void RegisterListener() { ConstructorInfo constructor = HandlerType.GetConstructor(Type.EmptyTypes); //create instance of handler class _handlerClass = constructor.Invoke(new object[] { }); if (_handlerClass == null) { throw new Exception("HandlerType class not found"); } var t = Channel.MessageConverter.TypeMapper.GetTypeForKey(TypeKey); _handlerMethod = HandlerType.GetMethod(HandlerMethod, new [] { t }); Log.Info("Listener Type " + TypeKey + " Registered"); }
public HandlerMethod(object handler, string handlerMethodName, params Type[] parameterTypes) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } if (string.IsNullOrEmpty(nameof(handlerMethodName))) { throw new ArgumentNullException(nameof(handlerMethodName)); } _handler = handler; HandlerType = handler.GetType(); Method = HandlerType.GetMethod(handlerMethodName, parameterTypes); _argCount = Method.GetParameters().Length; _invoker = CreateInvoker(); }
/// <summary> /// 执行程序集中的类的 ProcessRequest 方法。 /// </summary> internal void ExecuteProcessRequestMethodInHandler() { if (this.DBProcess == false && this.HandlerType != null && this.Request != null) { // 创建实例。 object handler = Activator.CreateInstance(HandlerType); // 获取 ProcessRequest 执行方法。 MethodInfo method = HandlerType.GetMethod("ProcessRequest"); // 创建参数数组。 object[] parameters = new object[] { this.Request, this.DBProcess }; // 执行方法。 this.Response = (ResponseResultBase)method.Invoke(handler, parameters); // 设置 ref 参数。 this.DBProcess = (bool)parameters[1]; } }
public string GetFriendlyName() { return((string)HandlerType.GetMethod("GetFriendlyName").Invoke(Handler, Array.Empty <object>())); }
public string GetDialogBoxExt() { return((string)HandlerType.GetMethod("GetDialogBoxExt").Invoke(Handler, Array.Empty <object>())); }
public void WriteData(StreamReader Source, StreamWriter Output) { HandlerType.GetMethod("WriteData").Invoke(Handler, new object[] { Source, Output }); }
public string GetPreferredExtension() { return((string)HandlerType.GetMethod("GetPreferredExtension").Invoke(Handler, Array.Empty <object>())); }
{/* * public object Handler; * public AppDomain Domain; * public Assembly LoadedAssembly; * public Type HandlerType; */ public void ReadData(StreamReader Source, StreamWriter Output, out bool ContainsRtfTags) { // a cludge, I would not figure out to get out args to work this way in the remote class ContainsRtfTags = false; HandlerType.GetMethod("ReadData").Invoke(Handler, new object[] { Source, Output, ContainsRtfTags }); }
/// <summary> /// get the base command (pre template processing) that will be ran with the menu. /// </summary> /// <returns></returns> public virtual string GetMenuItemCommand() { return((string)HandlerType.GetMethod("GetMenuItemCommand").Invoke(Handler, Array.Empty <object>())); }
public EventHandlerWrapper(Type eventType) { HandlerType = typeof(IEventHandler <>).MakeGenericType(eventType); _handleMethod = HandlerType.GetMethod(nameof(IEventHandler <IEvent> .Handle)); }