Ejemplo n.º 1
0
        public EmbeddedViewTable GetEmbeddedViews()
        {
            var assemblies = TypeSearcher.Instance().Assemblies;

            if (assemblies == null || assemblies.Count == 0)
            {
                return(null);
            }

            var table = new EmbeddedViewTable();

            foreach (var assembly in assemblies)
            {
                var names = GetNamesOfAssemblyResources(assembly);
                if (names == null || names.Length == 0)
                {
                    continue;
                }

                foreach (var name in names)
                {
                    var key = name.ToLowerInvariant();

                    if (!key.Contains(".views.") && !key.Contains(".widgets."))
                    {
                        continue;
                    }

                    table.AddView(name, assembly.FullName);
                }
            }

            return(table);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the availdable observers.
        /// </summary>
        /// <param name="eventName"></param>
        /// <returns></returns>
        public IEnumerable <IObserver> GetObservers(string eventName)
        {
            if (string.IsNullOrEmpty(eventName))
            {
                throw new ArgumentNullException("eventName");
            }

            List <Type> observerTypes = null;

            if (typeCache.ContainsKey(eventName))
            {
                observerTypes = typeCache[eventName];
            }
            else
            {
                var observers = TypeSearcher.Instance().SearchTypesByBaseType(typeof(IObserver));
                if (observers != null)
                {
                    observerTypes = observers.Where(o => !o.IsAbstract && !o.IsInterface && o.IsDefined(typeof(BindToAttribute), false) && ((BindToAttribute)o.GetCustomAttributes(typeof(BindToAttribute), false).First()).EventName.Equals(eventName)).ToList();
                }
                this.typeCache.Add(eventName, observerTypes);
            }


            if (observerTypes != null)
            {
                var instances = new List <IObserver>();

                foreach (var _type in observerTypes)
                {
                    try
                    {
                        var instance = Activator.CreateInstance(_type) as IObserver;
                        if (instance != null)
                        {
                            instances.Add(instance);
                        }
                    }
                    catch (Exception e)
                    {
                        continue;
                    }
                }

                return(instances.OrderByDescending(i => i.Order).ToList());
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get all job object
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <Job> GetAllJobs()
        {
            var jobs  = new List <Job>();
            var types = TypeSearcher.Instance().SearchTypesByBaseType(typeof(Job));

            foreach (var t in types)
            {
                try
                {
                    jobs.Add((Job)Activator.CreateInstance(t));
                }
                catch
                {
                    continue;
                }
            }
            return(jobs);
        }