Beispiel #1
0
        /// <summary>
        /// Scans all registered assemblies for controller classes of <see cref="ChromelyController"/> type.
        /// The classes must have the <see cref="ControllerPropertyAttribute"/> attribute.
        /// </summary>
        /// <returns>
        /// The <see cref="IDictionary"/>.
        /// </returns>
        public Tuple <Dictionary <string, ActionRoute>, Dictionary <string, CommandRoute> > Scan()
        {
            var routeDictionary   = new Dictionary <string, ActionRoute>();
            var commandDictionary = new Dictionary <string, CommandRoute>();

            try
            {
                var types = from type in _assembly.GetLoadableTypes()
                            where Attribute.IsDefined(type, typeof(ControllerPropertyAttribute))
                            select type;

                foreach (var type in types)
                {
                    if (typeof(ChromelyController).IsAssignableFrom(type.BaseType))
                    {
                        var controller               = new ChromelyControllerFactory(_container);
                        var instance                 = controller.CreateControllerInstance(type);
                        var currentRouteDictionary   = instance.ActionRouteDictionary;
                        var currentCommandDictionary = instance.CommandRouteDictionary;

                        // Merge with return route dictionary
                        if ((currentRouteDictionary != null) && currentRouteDictionary.Any())
                        {
                            foreach (var item in currentRouteDictionary)
                            {
                                if (!routeDictionary.ContainsKey(item.Key))
                                {
                                    routeDictionary.Add(item.Key, item.Value);
                                }
                            }
                        }

                        // Merge with return command dictionary
                        if ((currentCommandDictionary != null) && currentCommandDictionary.Any())
                        {
                            foreach (var item in currentCommandDictionary)
                            {
                                if (!commandDictionary.ContainsKey(item.Key))
                                {
                                    commandDictionary.Add(item.Key, item.Value);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.Log.Error(exception);
            }

            return(new Tuple <Dictionary <string, ActionRoute>, Dictionary <string, CommandRoute> >(routeDictionary, commandDictionary));
        }
Beispiel #2
0
        /// <summary>
        /// Scans all registered assemblies for controller classes of <see cref="ChromelyController"/> type.
        /// The classes must have the <see cref="ControllerPropertyAttribute"/> attribute.
        /// </summary>
        /// <returns>
        /// The <see cref="IDictionary"/>.
        /// </returns>
        public Dictionary <string, Route> Scan()
        {
            var routeDictionary = new Dictionary <string, Route>();

            try
            {
                var types = from type in _assembly.GetLoadableTypes()
                            where Attribute.IsDefined(type, typeof(ControllerPropertyAttribute))
                            select type;

                foreach (var type in types)
                {
                    if (type.BaseType == typeof(ChromelyController))
                    {
                        var instance = ChromelyControllerFactory.CreateControllerInstance(type);
                        var currentRouteDictionary = instance.RouteDictionary;

                        // Merge with return route dictionary
                        if ((currentRouteDictionary != null) && currentRouteDictionary.Any())
                        {
                            foreach (var item in currentRouteDictionary)
                            {
                                if (!routeDictionary.ContainsKey(item.Key))
                                {
                                    routeDictionary.Add(item.Key, item.Value);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
            }

            return(routeDictionary);
        }