Example #1
0
        /// <summary>
        /// Check if component type is OK for adding (since there are limitations, like the one instance limitation).
        /// </summary>
        /// <param name="componentType"></param>
        /// <returns></returns>
        public bool CanAcceptComponent(Type componentType)
        {
            bool allowMultipleInstances = ComponentManagementAttribute.GetTypeAttribute(componentType).AllowMultipleInstances;

            if (GetComponentsByType(componentType).Count > 0 && allowMultipleInstances == false)
            {// Instance already exists and no more instances allowed.
                return(false);
            }
            return(true);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        protected List <Type> GetMandatoryComponentsTypes()
        {
            // Establish mandatory component types.
            List <Type> mandatoryComponentTypes = new List <Type>();
            List <Type> candidateTypes          = ReflectionHelper.GatherTypeChildrenTypesFromAssemblies(typeof(PlatformComponent), ReflectionHelper.GetApplicationEntryAssemblyAndReferencedAssemblies(), true, false);

            foreach (Type type in candidateTypes)
            {
                if (ComponentManagementAttribute.GetTypeAttribute(type).IsMandatory)
                {
                    mandatoryComponentTypes.Add(type);
                }
            }

            return(mandatoryComponentTypes);
        }
Example #3
0
        /// <summary>
        /// Will sort but also create any mandatory components from mandatory types.
        /// Components sorted by component level. Lower level components are closer to the platform,
        /// like sources, etc. Higher level components are user/custom components. Lowest level components
        /// are started first, and stopped last.
        /// </summary>
        public SortedList <int, List <PlatformComponent> > GetComponentsByLevel(IEnumerable <PlatformComponent> components)
        {
            SortedList <int, List <PlatformComponent> > componentsByLevel = new SortedList <int, List <PlatformComponent> >();

            lock (this)
            {
                foreach (PlatformComponent component in components)
                {
                    int level = ComponentManagementAttribute.GetTypeAttribute(component.GetType()).ComponentLevel;
                    if (componentsByLevel.ContainsKey(level) == false)
                    {
                        componentsByLevel[level] = new List <PlatformComponent>();
                    }
                    componentsByLevel[level].Add(component);
                }
            }

            return(componentsByLevel);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        protected void GatherMandatoryComponents(SortedList <int, List <PlatformComponent> > componentsByLevel)
        {
            List <Type> mandatoryComponentTypes = GetMandatoryComponentsTypes();

            // Find if a mandatory already exists and remove it if it does.
            foreach (int level in componentsByLevel.Keys)
            {
                foreach (PlatformComponent component in componentsByLevel[level])
                {
                    mandatoryComponentTypes.Remove(component.GetType());
                }
            }

            // Create and add any mandatories to the sorted list.
            foreach (Type type in mandatoryComponentTypes)
            {
                ConstructorInfo info = type.GetConstructor(new Type[] { });
                if (info == null)
                {
                    SystemMonitor.Warning("Mandatory type [" + type.Name + "] has no default parameterless constructor.");
                    continue;
                }

                int level = ComponentManagementAttribute.GetTypeAttribute(type).ComponentLevel;
                PlatformComponent component = (PlatformComponent)info.Invoke(new object[] { });

                if (componentsByLevel.ContainsKey(level) == false)
                {
                    componentsByLevel[level] = new List <PlatformComponent>();
                }

                // By default they remain invisible.
                component.UISerializationInfo.AddValue("componentVisible", false);

                componentsByLevel[level].Add(component);
            }
        }