public static object GetInstance(Type service, string key) { if (m_container != null) { return(m_container.GetInstance(service, key)); } return(null); }
public static ActionRoute GetActionRoute(IChromelyContainer container, RoutePath routePath) { object routeObj = container.GetInstance(typeof(ActionRoute), routePath.Key); if ((routeObj == null) || !(routeObj is ActionRoute)) { throw new Exception($"No route found for method:{routePath.Method} route path:{routePath.Path}."); } return (ActionRoute)routeObj; }
public static bool IsActionRouteAsync(IChromelyContainer container, RoutePath routePath) { try { var route = container.GetInstance(typeof(ActionRoute), routePath.Key) as ActionRoute; return(route == null ? false : route.IsAsync); } catch {} return(false); }
public static ActionRoute GetActionRoute(IChromelyContainer container, RoutePath routePath) { var route = container.GetInstance(typeof(ActionRoute), routePath.Key) as ActionRoute; if (route == null) { throw new Exception($"No route found for method:{routePath.Method} route path:{routePath.Path}."); } return(route); }
public static CommandRoute GetCommandRoute(IChromelyContainer container, string commandPath) { var key = CommandRoute.GetKeyFromPath(commandPath); object commandObj = container.GetInstance(typeof(CommandRoute), key); if ((commandObj == null) || !(commandObj is CommandRoute)) { throw new Exception($"No route found for command with key:{key}."); } return (CommandRoute)commandObj; }
public static CommandRoute GetCommandRoute(IChromelyContainer container, string commandPath) { var key = CommandRoute.GetKeyFromPath(commandPath); var command = container.GetInstance(typeof(CommandRoute), key) as CommandRoute; if (command == null) { throw new Exception($"No route found for command with key:{key}."); } return(command); }
/// <summary> /// The set event handlers. /// </summary> /// <param name="browser"> /// The browser. /// </param> public static void SetEventHandlers(this CefGlueBrowser browser, IChromelyContainer container) { try { foreach (var enumKey in CefEventHandlerTypes.GetAllEventHandlerKeys()) { object instance = null; var service = CefEventHandlerTypes.GetHandlerType(enumKey); var keyStr = enumKey.EnumToString(); try { if (container.IsRegistered(service, keyStr)) { instance = container.GetInstance(service, keyStr); } } catch (Exception exception) { Logger.Instance.Log.Error(exception); } switch (enumKey) { case CefEventKey.None: break; case CefEventKey.FrameLoadStart: if (instance is ChromelyEventHandler <FrameLoadStartEventArgs> frameLoadStart) { browser.FrameLoadStart += frameLoadStart.Handler; } break; case CefEventKey.AddressChanged: if (instance is ChromelyEventHandler <AddressChangedEventArgs> addressChanged) { browser.AddressChanged += addressChanged.Handler; } break; case CefEventKey.TitleChanged: if (instance is ChromelyEventHandler <TitleChangedEventArgs> titleChanged) { browser.TitleChanged += titleChanged.Handler; } break; case CefEventKey.FrameLoadEnd: if (instance is ChromelyEventHandler <FrameLoadEndEventArgs> frameLoadEnd) { browser.FrameLoadEnd += frameLoadEnd.Handler; } break; case CefEventKey.LoadingStateChanged: if (instance is ChromelyEventHandler <LoadingStateChangedEventArgs> loadingStateChanged) { browser.LoadingStateChanged += loadingStateChanged.Handler; } break; case CefEventKey.ConsoleMessage: if (instance is ChromelyEventHandler <ConsoleMessageEventArgs> consoleMessage) { browser.ConsoleMessage += consoleMessage.Handler; } break; case CefEventKey.StatusMessage: if (instance is ChromelyEventHandler <StatusMessageEventArgs> statusMessage) { browser.StatusMessage += statusMessage.Handler; } break; case CefEventKey.LoadError: if (instance is ChromelyEventHandler <LoadErrorEventArgs> loadError) { browser.LoadError += loadError.Handler; } break; case CefEventKey.TooltipChanged: if (instance is ChromelyEventHandler <TooltipEventArgs> tooltipChanged) { browser.TooltipChanged += tooltipChanged.Handler; } break; case CefEventKey.BeforeClose: if (instance is ChromelyEventHandler <BeforeCloseEventArgs> beforeClose) { browser.BeforeClose += beforeClose.Handler; } break; case CefEventKey.BeforePopup: if (instance is ChromelyEventHandler <BeforePopupEventArgs> beforePopup) { browser.BeforePopup += beforePopup.Handler; } break; case CefEventKey.PluginCrashed: if (instance is ChromelyEventHandler <PluginCrashedEventArgs> pluginCrashed) { browser.PluginCrashed += pluginCrashed.Handler; } break; case CefEventKey.RenderProcessTerminated: if (instance is ChromelyEventHandler <RenderProcessTerminatedEventArgs> renderProcessTerminated) { browser.RenderProcessTerminated += renderProcessTerminated.Handler; } break; } } } catch (Exception exception) { Logger.Instance.Log.Error(exception); } }
public static T Resolve <T>(this IChromelyContainer self) { return((T)self.GetInstance(typeof(T), typeof(T).Name)); }