コード例 #1
0
        public static Bundle Include(this Bundle bundle, IEnumerable<BundleItem> items)
        {
            foreach (var item in items)
            {
                var file = item.Item as ManifestBundleFile;
                var directory = item.Item as ManifestBundleDirectory;

                try
                {
                    if (file != null)
                    {
                        bundle.Include(file.VirtualPath);
                    }

                    if (directory != null)
                    {
                        bundle.IncludeDirectory(
                            directory.VirtualPath,
                            directory.SearchPattern,
                            directory.SearchSubdirectories);
                    }
                }
                catch (Exception ex)
                {
                    Exception moduleException;

                    if (item.Module.ModuleInstance != null)
                    {
                        var assemblyName = item.Module.ModuleInstance.GetType().Assembly.FullName;
                        moduleException = new ModuleInitializeException(item.Module.ModuleName, assemblyName, ex.Message, ex);
                    }
                    else
                    {
                        moduleException = new ModuleInitializeException(item.Module.ModuleName, ex.Message, ex);
                    }

                    throw moduleException;
                }
            }

            return bundle;
        }
コード例 #2
0
        /// <summary>
        /// Handles any exception occurred in the module Initialization process,
        /// logs the error using the <see cref="ILog"/> and throws a <see cref="ModuleInitializeException"/>.
        /// This method can be overridden 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="ModuleInitializeException"></exception>
        public virtual void HandleModuleInitializationError(ModuleInfo moduleInfo, Exception exception)
        {
            if (moduleInfo == null)
                throw new ArgumentNullException("moduleInfo");
            if (exception == null)
                throw new ArgumentNullException("exception");

            Exception moduleException;

            if (exception is ModuleInitializeException)
            {
                moduleException = exception;
            }
            else
            {
                if (moduleInfo.ModuleInstance != null)
                {
                    var assemblyName = moduleInfo.ModuleInstance.GetType().Assembly.FullName;
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, assemblyName, exception.Message, exception);
                }
                else
                {
                    moduleException = new ModuleInitializeException(moduleInfo.ModuleName, exception.Message, exception);
                }
            }

            _loggerFacade.Error(moduleException.ToString());

            throw moduleException;
        }