public int Load(System.Reflection.Assembly assembly) { int count = 0; foreach (var t in assembly.GetTypes()) { if (t.GetInterface("IAgentRequestingHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IAgentRequestingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); AgentRequestingHandler.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] agent requesting handler success"); RouteBinderAttribute routeBinderAttribute = t.GetCustomAttribute <RouteBinderAttribute>(false); if (routeBinderAttribute != null) { if (string.IsNullOrEmpty(routeBinderAttribute.RouteUrl)) { Gateway.Pluginer.SetAgentRequesting(handler.Name); } else { var route = Gateway.Routes.NewOrGet(routeBinderAttribute.RouteUrl, null, null, routeBinderAttribute.ApiLoader); route.Pluginer.SetAgentRequesting(handler.Name); } } mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} agent requesting handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IHeaderWritingHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IHeaderWritingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); HeaderWritingHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] header writing handler success"); RouteBinderAttribute routeBinderAttribute = t.GetCustomAttribute <RouteBinderAttribute>(false); if (routeBinderAttribute != null) { if (string.IsNullOrEmpty(routeBinderAttribute.RouteUrl)) { Gateway.Pluginer.SetHeaderWriting(handler.Name); } else { var route = Gateway.Routes.NewOrGet(routeBinderAttribute.RouteUrl, null, null, routeBinderAttribute.ApiLoader); route.Pluginer.SetHeaderWriting(handler.Name); } } mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} header writing handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IResponseErrorHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IResponseErrorHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); ResponseErrorHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] response error handler success"); mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} response error handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IRequestingHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IRequestingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); RequestingHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] requesting handler success"); RouteBinderAttribute routeBinderAttribute = t.GetCustomAttribute <RouteBinderAttribute>(false); if (routeBinderAttribute != null) { if (string.IsNullOrEmpty(routeBinderAttribute.RouteUrl)) { Gateway.Pluginer.SetRequesting(handler.Name); } else { var route = Gateway.Routes.NewOrGet(routeBinderAttribute.RouteUrl, null, null, routeBinderAttribute.ApiLoader); route.Pluginer.SetRequesting(handler.Name); } } mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} requesting handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IRespondingHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IRespondingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); RespondingHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] responding handler success"); RouteBinderAttribute routeBinderAttribute = t.GetCustomAttribute <RouteBinderAttribute>(false); if (routeBinderAttribute != null) { if (string.IsNullOrEmpty(routeBinderAttribute.RouteUrl)) { Gateway.Pluginer.SetResponding(handler.Name); } else { var route = Gateway.Routes.NewOrGet(routeBinderAttribute.RouteUrl, null, null, routeBinderAttribute.ApiLoader); route.Pluginer.SetResponding(handler.Name); } } mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} responding handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IRequestedHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IRequestedHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); RequestedHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] requested handler success"); RouteBinderAttribute routeBinderAttribute = t.GetCustomAttribute <RouteBinderAttribute>(false); if (routeBinderAttribute != null) { if (string.IsNullOrEmpty(routeBinderAttribute.RouteUrl)) { Gateway.Pluginer.SetRequested(handler.Name); } else { var route = Gateway.Routes.NewOrGet(routeBinderAttribute.RouteUrl, null, null, routeBinderAttribute.ApiLoader); route.Pluginer.SetRequested(handler.Name); } } mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} requested handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IGetServerHandler") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IGetServerHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); GetServerHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] route get server handler success"); RouteBinderAttribute routeBinderAttribute = t.GetCustomAttribute <RouteBinderAttribute>(false); if (routeBinderAttribute != null) { if (string.IsNullOrEmpty(routeBinderAttribute.RouteUrl)) { Gateway.Pluginer.SetRequested(handler.Name); } else { var route = Gateway.Routes.NewOrGet(routeBinderAttribute.RouteUrl, null, null, routeBinderAttribute.ApiLoader); route.Pluginer.GetServerHandler = handler; } } mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} route get server handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IGatewayLoader") != null && !t.IsAbstract && t.IsClass) { try { count++; var handler = (IGatewayLoader)Activator.CreateInstance(t); handler.Init(Gateway, assembly); LoaderHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.GetType()}[{assembly.GetName().Version}] gateway loader handler success"); mPlugins[handler.Name] = handler; InitPluginEnabled(handler); LoadSetting(handler); SaveSetting(handler, false); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.GetType()} gateway loader handler error {e_.Message} {e_.StackTrace}"); } } } return(count); }
public void Load(System.Reflection.Assembly assembly) { foreach (var t in assembly.GetTypes()) { if (t.GetInterface("IAgentRequestingHandler") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IAgentRequestingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); AgentRequestingHandler.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] agent requesting handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} agent requesting handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IHeaderWritingHandler") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IHeaderWritingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); HeaderWritingHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] header writing handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} header writing handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IResponseErrorHandler") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IResponseErrorHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); ResponseErrorHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] response error handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} response error handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IRequestingHandler") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IRequestingHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); RequestingHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] requesting handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} requesting handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IRequestedHandler") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IRequestedHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); RequestedHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] requested handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} requested handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IGetServerHandler") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IGetServerHandler)Activator.CreateInstance(t); handler.Init(Gateway, assembly); GetServerHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] route get server handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} route get server handler error {e_.Message} {e_.StackTrace}"); } } if (t.GetInterface("IGatewayLoader") != null && !t.IsAbstract && t.IsClass) { try { var handler = (IGatewayLoader)Activator.CreateInstance(t); handler.Init(Gateway, assembly); LoaderHandlers.Add(handler); Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Info, $"gateway load {t.Name}[{assembly.GetName().Version}] gateway loader handler success"); } catch (Exception e_) { Gateway.HttpServer.Log(BeetleX.EventArgs.LogType.Error, $"gateway load {t.Name} gateway loader handler error {e_.Message} {e_.StackTrace}"); } } } }