コード例 #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;
        }
コード例 #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;
        }
コード例 #3
0
ファイル: ModuleManager.cs プロジェクト: christal1980/wingsoa
        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;
            }
        }
コード例 #4
0
ファイル: ModuleManager.cs プロジェクト: christal1980/wingsoa
        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;
            }
        }
コード例 #5
0
ファイル: ModuleManager.cs プロジェクト: christal1980/wingsoa
        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);
        }
コード例 #6
0
ファイル: ModuleManager.cs プロジェクト: christal1980/wingsoa
        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;
        }
コード例 #7
0
ファイル: ModuleManager.cs プロジェクト: christal1980/wingsoa
        /// <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;
        }
コード例 #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);
     }
 }
コード例 #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);
 }
コード例 #10
0
        public void Initialize(ModuleInfo moduleInfo)
        {
            if (moduleInfo.ModuleInstance == null)
                moduleInfo.ModuleInstance = this.CreateModule(moduleInfo.ModuleType);

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