Example #1
0
        public static object[] GetAllInstances(Type service)
        {
            if (m_container != null)
            {
                return(m_container.GetAllInstances(service));
            }

            return(null);
        }
Example #2
0
        public static IEnumerable <object> GetAllInstances(Type service)
        {
            if (m_container != null)
            {
                return(m_container.GetAllInstances(service));
            }

            return(null);
        }
Example #3
0
        private object GetCustomHandler(Type handlerType)
        {
            var customHandlers = _container.GetAllInstances(typeof(IChromelyCustomHandler));

            if (customHandlers != null && customHandlers.Any())
            {
                return(customHandlers.FirstOrDefault(x => handlerType.IsAssignableFrom(x.GetType())));
            }

            return(null);
        }
        private object CreateType(Type type)
        {
            object instance = null;

            foreach (var constructor in type.GetConstructors())
            {
                var parameters = constructor.GetParameters();
                if (parameters.Length == 0)
                {
                    instance = Activator.CreateInstance(type);
                    break;
                }

                var paramValues = new object[parameters.Length];

                for (var ix = 0; ix < parameters.Length; ix++)
                {
                    var parameterInfo = parameters[ix];

                    var iocInstance       = _container.GetAllInstances(parameterInfo.ParameterType).FirstOrDefault();
                    var parameterInstance = iocInstance ?? CreateType(parameterInfo.ParameterType);

                    paramValues[ix] = parameterInstance;
                }

                try
                {
                    instance = Activator.CreateInstance(type, paramValues);
                    break;
                }
                catch (Exception ex)
                {
                    Logger.Instance.Log.Error(ex.Message);
                }
            }

            return(instance);
        }
        public static CefGlueCustomHandlers Parse(IChromelyContainer container, IChromelyConfiguration config, IChromelyCommandTaskRunner commandTaskRunner, CefGlueBrowser browser)
        {
            var handlers = new CefGlueCustomHandlers();

            try
            {
                // Set default handlers
                handlers.LifeSpanHandler    = new CefGlueLifeSpanHandler(config, commandTaskRunner, browser);
                handlers.LoadHandler        = new CefGlueLoadHandler(config, browser);
                handlers.RequestHandler     = new CefGlueRequestHandler(config, commandTaskRunner, browser);
                handlers.DisplayHandler     = new CefGlueDisplayHandler(config, browser);
                handlers.ContextMenuHandler = new CefGlueContextMenuHandler(config);

                // Update custom handlers
                var customHandlers = container.GetAllInstances(typeof(IChromelyCustomHandler));
                if (customHandlers != null && customHandlers.Any())
                {
                    foreach (var handler in customHandlers)
                    {
                        if (handler is CefLifeSpanHandler spanHandler)
                        {
                            handlers.LifeSpanHandler = spanHandler;
                        }
                        if (handler is CefLoadHandler loadHandler)
                        {
                            handlers.LoadHandler = loadHandler;
                        }
                        if (handler is CefRequestHandler requestHandler)
                        {
                            handlers.RequestHandler = requestHandler;
                        }
                        if (handler is CefDisplayHandler displayHandler)
                        {
                            handlers.DisplayHandler = displayHandler;
                        }
                        if (handler is CefContextMenuHandler menuHandler)
                        {
                            handlers.ContextMenuHandler = menuHandler;
                        }
                        if (handler is CefFocusHandler focusHandler)
                        {
                            handlers.FocusHandler = focusHandler;
                        }
                        if (handler is CefKeyboardHandler keyboardHandler)
                        {
                            handlers.KeyboardHandler = keyboardHandler;
                        }
                        if (handler is CefJSDialogHandler jsDialogHandler)
                        {
                            handlers.JsDialogHandler = jsDialogHandler;
                        }
                        if (handler is CefDialogHandler dialogHandler)
                        {
                            handlers.DialogHandler = dialogHandler;
                        }
                        if (handler is CefDragHandler dragHandler)
                        {
                            handlers.DragHandler = dragHandler;
                        }
                        if (handler is CefDownloadHandler downloadHandler)
                        {
                            handlers.DownloadHandler = downloadHandler;
                        }
                        if (handler is CefFindHandler cefFinderhandler)
                        {
                            handlers.FindHandler = cefFinderhandler;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.Log.Error(exception);
            }

            return(handlers);
        }