Exemple #1
0
        /// <summary>
        /// The register event handler.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="handler">
        /// The handler.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// The <see cref="ChromelyConfiguration"/>.
        /// </returns>
        public virtual ChromelyConfiguration RegisterEventHandler <T>(CefEventKey key, ChromelyEventHandler <T> handler)
        {
            var service = CefEventHandlerFakeTypes.GetHandlerType(key);

            IoC.RegisterInstance(service, handler.Key, handler);
            return(this);
        }
        /// <summary>
        /// The set event handlers.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        public static void SetEventHandlers(this CefGlueBrowser browser)
        {
            try
            {
                foreach (var enumKey in CefEventHandlerFakeTypes.GetAllEventHandlerKeys())
                {
                    object instance = null;

                    var service = CefEventHandlerFakeTypes.GetHandlerType(enumKey);
                    var keyStr  = enumKey.EnumToString();
                    try
                    {
                        if (IoC.IsRegistered(service, keyStr))
                        {
                            instance = IoC.GetInstance(service, keyStr);
                        }
                    }
                    catch (Exception exception)
                    {
                        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 <LoadingStateChangeEventArgs> 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)
            {
                Log.Error(exception);
            }
        }
        /// <summary>
        /// The set event handlers.
        /// </summary>
        /// <param name="browser">
        /// The browser.
        /// </param>
        public static void SetEventHandlers(this ChromiumWebBrowser browser)
        {
            try
            {
                foreach (var enumKey in CefEventHandlerFakeTypes.GetAllEventHandlerKeys())
                {
                    object instance = null;

                    var service = CefEventHandlerFakeTypes.GetHandlerType(enumKey);
                    var keyStr  = enumKey.EnumToString();
                    try
                    {
                        if (IoC.IsRegistered(service, keyStr))
                        {
                            instance = IoC.GetInstance(service, keyStr);
                        }
                    }
                    catch (Exception exception)
                    {
                        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;
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }
        }