예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="manager_path"></param>
        public ManagerEngine(string prefix, string manager_path)
        {
            this.rootPaths    = new StringList();
            this.rootNames    = new NameValueCollection();
            this.plugins      = new PluginList();
            this.fileSystems  = new FileFactoryDictionary();
            this.langPack     = null;
            this.logger       = new Logger();
            this.pluginLookup = new Hashtable();

            if (manager_path != null)
            {
                this.ManagerPath = manager_path;
            }
            else
            {
                this.ManagerPath = System.Web.HttpContext.Current.Server.MapPath("..");
            }

            this.Plugins.Add(new CorePlugin());

            ManagerConfig coreConfig = (ManagerConfig)System.Web.HttpContext.Current.GetConfig("CorePlugin");

            this.prefix = prefix;

            // Add instance of each plugin
            foreach (string className in coreConfig.Plugins)
            {
                IPlugin plugin = (IPlugin)InstanceFactory.CreateInstance(className);

                if (plugin == null)
                {
                    throw new ManagerException("Could not create instance of plugin class: " + className);
                }

                this.Plugins.Add(plugin);
            }

            this.DispatchEvent(EventType.PreInit, prefix);
            this.SetupConfigItems();

            // Setup logger
            if (!this.Config.GetBool("log.enabled", false))
            {
                this.logger.Level = LoggerLevel.Fatal;
            }
            else
            {
                this.logger.LevelName = this.Config.Get("log.level", "fatal");
            }

            this.logger.Path       = this.ToAbsPath(this.Config.Get("log.path", "logs"));
            this.logger.FileFormat = this.Config.Get("log.filename", "{level}.log");
            this.logger.Format     = this.Config.Get("log.format", "[{time}] [{level}] {message}");
            this.logger.MaxSize    = this.Config.Get("log.max_size", "100k");
            this.logger.MaxFiles   = this.Config.GetInt("log.max_files", 10);

            // Add instance of each plugin
            AssemblyLoader loader = new AssemblyLoader();

            foreach (string className in this.Config.Plugins)
            {
                IPlugin plugin = (IPlugin)loader.CreateInstance(className);

                if (plugin == null)
                {
                    throw new Exception("Could not create instance of plugin class: " + className);
                }

                this.Plugins.Add(plugin);

                // Add by class name and by short name
                this.pluginLookup[className] = plugin;

                if (plugin.ShortName != null)
                {
                    this.pluginLookup[plugin.ShortName] = plugin;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="manager_path"></param>
        public ManagerEngine(string prefix, string manager_path)
        {
            this.rootPaths = new StringList();
            this.rootNames = new NameValueCollection();
            this.plugins = new PluginList();
            this.fileSystems = new FileFactoryDictionary();
            this.langPack = null;
            this.logger = new Logger();
            this.pluginLookup = new Hashtable();

            if (manager_path != null)
                this.ManagerPath = manager_path;
            else
                this.ManagerPath = System.Web.HttpContext.Current.Server.MapPath("..");

            this.Plugins.Add(new CorePlugin());

            ManagerConfig coreConfig = (ManagerConfig) System.Web.HttpContext.Current.GetConfig("CorePlugin");

            this.prefix = prefix;

            // Add instance of each plugin
            foreach (string className in coreConfig.Plugins) {
                IPlugin plugin = (IPlugin) InstanceFactory.CreateInstance(className);

                if (plugin == null)
                    throw new ManagerException("Could not create instance of plugin class: " + className);

                this.Plugins.Add(plugin);
            }

            this.DispatchEvent(EventType.PreInit, prefix);
            this.SetupConfigItems();

            // Setup logger
            if (!this.Config.GetBool("log.enabled", false))
                this.logger.Level = LoggerLevel.Fatal;
            else
                this.logger.LevelName = this.Config.Get("log.level", "fatal");

            this.logger.Path = this.ToAbsPath(this.Config.Get("log.path", "logs"));
            this.logger.FileFormat = this.Config.Get("log.filename", "{level}.log");
            this.logger.Format = this.Config.Get("log.format", "[{time}] [{level}] {message}");
            this.logger.MaxSize = this.Config.Get("log.max_size", "100k");
            this.logger.MaxFiles = this.Config.GetInt("log.max_files", 10);

            // Add instance of each plugin
            AssemblyLoader loader = new AssemblyLoader();
            foreach (string className in this.Config.Plugins) {
                IPlugin plugin = (IPlugin) loader.CreateInstance(className);

                if (plugin == null)
                    throw new Exception("Could not create instance of plugin class: " + className);

                this.Plugins.Add(plugin);

                // Add by class name and by short name
                this.pluginLookup[className] = plugin;

                if (plugin.ShortName != null)
                    this.pluginLookup[plugin.ShortName] = plugin;
            }
        }