Esempio n. 1
0
        /// <summary>
        /// Handles any exception ocurred in the module Initialization process,
        /// logs the error using the <seealso cref="ILoggerFacade"/> and throws a <seealso cref="ModuleInitializeException"/>.
        /// This method can be overriden to provide a different behavior. 
        /// </summary>
        /// <param name="moduleInfo">The module metadata where the error happenened.</param>
        /// <param name="assemblyName">The assembly name.</param>
        /// <param name="exception">The exception thrown that is the cause of the current error.</param>
        /// <exception cref="ModuleInitializeException"></exception>
        public virtual void HandleModuleInitializationError(ModuleInfo moduleInfo, string assemblyName, Exception exception)
        {
            Exception moduleException;

            if (exception is ModuleInitializeException)
            {
                moduleException = exception;
            }
            else
            {
                if (!string.IsNullOrEmpty(assemblyName))
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, assemblyName, exception.Message, exception);
                }
                else
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, exception.Message, exception);
                }
            }

            this.loggerFacade.LogException(String.Format("Error on {0} module {1}",
                    moduleInfo.State == ModuleState.Initializing ? "initialize" : "run",
                    moduleInfo.ModuleName), moduleException, Priority.High);
            throw moduleException;
        }
Esempio n. 2
0
        public ModuleInfo BuildModuleInfo(Type type)
        {
            var moduleInfo = new ModuleInfo(type.Name, type.AssemblyQualifiedName);
            var attributes = type.GetCustomAttributes(true);

            foreach (var attr in attributes)
            {
                if (attr.GetType() == typeof(ModuleAttribute))
                    moduleInfo.ModuleName = ((ModuleAttribute)attr).ModuleName;
                else if (attr.GetType() == typeof(ModuleDependencyAttribute))
                    moduleInfo.DependsOn.Add(((ModuleDependencyAttribute)attr).ModuleName);
                else if (attr.GetType() == typeof(ModuleCategoryAttribute))
                    moduleInfo.ModuleCategory = ((ModuleCategoryAttribute)attr).Category;
                else if (attr.GetType() == typeof(ModuleDescriptionAttribute))
                    moduleInfo.ModuleDescription = ((ModuleDescriptionAttribute)attr).Description;
                else if (attr.GetType() == typeof(ModulePriorityAttribute))
                    moduleInfo.ModulePriority = ((ModulePriorityAttribute)attr).Priority;
            }
            return moduleInfo;
        }
Esempio n. 3
0
        private void RunModule(ModuleInfo moduleInfo)
        {
            if (moduleInfo.State == ModuleState.Initialized)
            {
                loggerFacade.Log(String.Format("Running module {0}, Order: {1}",
                        moduleInfo.ModuleName,
                        moduleInfo.LoadOrder.ToString()),
                        Category.Debug, Priority.High);

                this.moduleInitializer.RunModule(moduleInfo);
                moduleInfo.State = ModuleState.Running;
            }
        }
Esempio n. 4
0
        private void InitializeModule(ModuleInfo moduleInfo)
        {
            if (moduleInfo.State == ModuleState.Initializing)
            {
                moduleInfo.LoadOrder = ++_orderCount;

                loggerFacade.Log(String.Format("Initializing module {0}, Category: {1}, Priority: {2}, SortKey: {3}, Order: {4}",
                        moduleInfo.ModuleName,
                        moduleInfo.ModuleCategory.ToString(),
                        moduleInfo.ModulePriority.ToString(),
                        moduleInfo.LoadOrderIndex.ToString(),
                        moduleInfo.LoadOrder.ToString()),
                        Category.Debug, Priority.High);

                this.moduleInitializer.Initialize(moduleInfo);
                moduleInfo.State = ModuleState.Initialized;
            }
        }
Esempio n. 5
0
        private IModuleTypeLoader GetTypeLoaderForModule(ModuleInfo moduleInfo)
        {
            foreach (IModuleTypeLoader typeLoader in this.ModuleTypeLoaders)
            {
                if (typeLoader.CanLoadModuleType(moduleInfo))
                {
                    return typeLoader;
                }
            }

            throw new ModuleTypeLoaderNotFoundException(moduleInfo.ModuleName, String.Format(CultureInfo.CurrentCulture, Messages.NoRetrieverCanRetrieveModule, moduleInfo.ModuleName), null);
        }
Esempio n. 6
0
        private bool AreDependenciesLoaded(ModuleInfo moduleInfo)
        {
            IEnumerable<ModuleInfo> requiredModules = this.moduleCatalog.GetDependentModules(moduleInfo);
            if (requiredModules == null)
            {
                return true;
            }

            int notReadyRequiredModuleCount =
                requiredModules.Count(requiredModule =>
                    !(requiredModule.State == ModuleState.Initialized || requiredModule.State == ModuleState.Running));

            return notReadyRequiredModuleCount == 0;
        }
Esempio n. 7
0
        /// <summary>
        /// Handles any exception ocurred in the module typeloading process,
        /// logs the error using the <seealso cref="ILoggerFacade"/> and throws a <seealso cref="ModuleTypeLoadingException"/>.
        /// This method can be overriden to provide a different behavior. 
        /// </summary>
        /// <param name="moduleInfo">The module metadata where the error happenened.</param>
        /// <param name="exception">The exception thrown that is the cause of the current error.</param>
        /// <exception cref="ModuleTypeLoadingException"></exception>
        protected virtual void HandleModuleTypeLoadingError(ModuleInfo moduleInfo, Exception exception)
        {
            ModuleTypeLoadingException moduleTypeLoadingException = exception as ModuleTypeLoadingException;

            if (moduleTypeLoadingException == null)
            {
                moduleTypeLoadingException = new ModuleTypeLoadingException(moduleInfo.ModuleName, exception.Message, exception);
            }

            this.loggerFacade.Log(moduleTypeLoadingException.Message, Category.Exception, Priority.High);

            throw moduleTypeLoadingException;
        }
Esempio n. 8
0
 protected void ExecuteModuleMethod(ModuleInfo moduleInfo, Action method)
 {
     try
     {
         method();
     }
     catch (Exception ex)
     {
         this.HandleModuleInitializationError(
             moduleInfo,
             moduleInfo.ModuleInstance != null ? moduleInfo.ModuleInstance.GetType().Assembly.FullName : null,
             ex);
     }
 }
Esempio n. 9
0
 public void RunModule(ModuleInfo moduleInfo)
 {
     if (moduleInfo.ModuleInstance == null)
         throw new ModuleInitializeException(String.Format("The module {0} has no instance", moduleInfo.ModuleName));
     if (moduleInfo.State == ModuleState.Initialized)
         ExecuteModuleMethod(moduleInfo, moduleInfo.ModuleInstance.Run);
 }
Esempio n. 10
0
        public void Initialize(ModuleInfo moduleInfo)
        {
            if (moduleInfo.ModuleInstance == null)
                moduleInfo.ModuleInstance = this.CreateModule(moduleInfo.ModuleType);

            ExecuteModuleMethod(moduleInfo, moduleInfo.ModuleInstance.Initialize);
        }