Beispiel #1
0
        /// <summary>
        /// Gets module info for a given module type
        /// </summary>
        /// <param name="moduleType"></param>
        /// <returns></returns>
        private ModuleInfo GetModuleInfo(Type moduleType, ModuleData moduleData)
        {
            // create module info
            ModuleInfo moduleInfo = new ExtendedModuleInfo()
            {
                ModuleType = moduleType.AssemblyQualifiedName,
                Ref        = moduleType.Assembly.CodeBase,
                ModuleID   = moduleData.ModuleID
            };

            // get module attribute off type
            CustomAttributeData moduleAttributeData =
                moduleType.GetCustomAttributesData().FirstOrDefault(attribute => attribute.Constructor.DeclaringType.Equals(typeof(ModuleAttribute)));

            if (moduleAttributeData != null)
            {
                // get module name
                CustomAttributeNamedArgument moduleNameArg = moduleAttributeData.NamedArguments.FirstOrDefault(arg => arg.MemberInfo.Name == "ModuleName");
                if (moduleNameArg != null)
                {
                    moduleInfo.ModuleName = moduleNameArg.TypedValue.Value as string;
                }

                // get on demand flag and set initialization mode based on it
                CustomAttributeNamedArgument onDemandArg = moduleAttributeData.NamedArguments.FirstOrDefault(arg => arg.MemberInfo.Name == "OnDemand");
                if (onDemandArg != null && (bool)onDemandArg.TypedValue.Value)
                {
                    moduleInfo.InitializationMode = InitializationMode.OnDemand;
                }
                else
                {
                    moduleInfo.InitializationMode = InitializationMode.WhenAvailable;
                }
            }

            // if a name was not provided for the module from its custom attribute, set the name from the value in the db
            if (string.IsNullOrEmpty(moduleInfo.ModuleName))
            {
                moduleInfo.ModuleName = moduleData.ModuleName;
            }

            // get module dependency attributes off type
            IEnumerable <CustomAttributeData> moduleDependencyAttributeDataCollection =
                moduleType.GetCustomAttributesData().Where(attribute => attribute.Constructor.DeclaringType.Equals(typeof(ModuleDependencyAttribute)));

            // add dependencies to module info
            foreach (CustomAttributeData moduleDependencyAttributeData in moduleDependencyAttributeDataCollection)
            {
                moduleInfo.DependsOn.Add(moduleDependencyAttributeData.ConstructorArguments[0].Value as string);
            }

            return(moduleInfo);
        }
        /// <summary>
        /// Gets module info for a given module type
        /// </summary>
        /// <param name="moduleType"></param>
        /// <returns></returns>
        private ModuleInfo GetModuleInfo(Type moduleType, ModuleData moduleData)
        {
            // create module info
            ModuleInfo moduleInfo = new ExtendedModuleInfo()
            {
                ModuleType = moduleType.AssemblyQualifiedName,
                Ref = moduleType.Assembly.CodeBase,
                ModuleID = moduleData.ModuleID
            };

            // get module attribute off type
            CustomAttributeData moduleAttributeData =
                moduleType.GetCustomAttributesData().FirstOrDefault(attribute => attribute.Constructor.DeclaringType.Equals(typeof(ModuleAttribute)));
            if (moduleAttributeData != null)
            {
                // get module name
                CustomAttributeNamedArgument moduleNameArg = moduleAttributeData.NamedArguments.FirstOrDefault(arg => arg.MemberInfo.Name == "ModuleName");
                if (moduleNameArg != null)
                    moduleInfo.ModuleName = moduleNameArg.TypedValue.Value as string;

                // get on demand flag and set initialization mode based on it
                CustomAttributeNamedArgument onDemandArg = moduleAttributeData.NamedArguments.FirstOrDefault(arg => arg.MemberInfo.Name == "OnDemand");
                if (onDemandArg != null && (bool)onDemandArg.TypedValue.Value)
                    moduleInfo.InitializationMode = InitializationMode.OnDemand;
                else
                    moduleInfo.InitializationMode = InitializationMode.WhenAvailable;
            }

            // if a name was not provided for the module from its custom attribute, set the name from the value in the db
            if (string.IsNullOrEmpty(moduleInfo.ModuleName))
                moduleInfo.ModuleName = moduleData.ModuleName;

            // get module dependency attributes off type
            IEnumerable<CustomAttributeData> moduleDependencyAttributeDataCollection =
                moduleType.GetCustomAttributesData().Where(attribute => attribute.Constructor.DeclaringType.Equals(typeof(ModuleDependencyAttribute)));

            // add dependencies to module info
            foreach (CustomAttributeData moduleDependencyAttributeData in moduleDependencyAttributeDataCollection)
                moduleInfo.DependsOn.Add(moduleDependencyAttributeData.ConstructorArguments[0].Value as string);

            return moduleInfo;
        }