protected static IEngine CreateEngineInstance(NopConfig config) { if(config != null && !string.IsNullOrEmpty(config.EngineType)) // nếu có yêu cầu dùng 1 IEngine khác với IEngine mặc định { var engineType = Type.GetType(config.EngineType); if(engineType == null) throw new ConfigurationErrorsException("The type '" + config.EngineType + "' could not be found. Please check the configuration at /configuration/nop/engine[@engineType] or check for missing assemblies."); else if(!typeof(IEngine).IsAssignableFrom(engineType)) throw new ConfigurationErrorsException("The type '" + engineType + "' doesn't implement 'Nop.Core.Infrastructure.IEngine' and cannot be configured in /configuration/nop/engine[@engineType] for that purpose."); return (IEngine)Activator.CreateInstance(engineType); } // dùng IEngine mặc định return new NopEngine(); }
/// <summary> /// Creates a configuration section handler. Đọc nội dung xml để lấy về các thông tin cấu hình cần thiết cho toàn bộ ứng dụng /// </summary> /// <param name="parent">Parent object.</param> /// <param name="configContext">Configuration context object.</param> /// <param name="section">Section XML node.</param> /// <returns>The created section handler object.</returns> public object Create(object parent, object configContext, XmlNode section) { var config = new NopConfig(); // dạng : <DynamicDiscovery Enabled="true" /> ReadXmlConfigData(section, "DynamicDiscovery", "Enabled", value => { config.DynamicDiscovery = Convert.ToBoolean(value); }); // dạng : <Engine Type="Nop.MyEngine" /> ReadXmlConfigData(section, "Engine", "Type", value => { config.EngineType = value; }); ReadXmlConfigData(section, "Startup", "IgnoreStartupTasks", value => { config.IgnoreStartupTasks = Convert.ToBoolean(value); }); ReadXmlConfigData(section, "Themes", "basePath", value => { config.ThemeBasePath = value; }); ReadXmlConfigData(section, "UserAgentStrings", "databasePath", value => { config.UserAgentStringsPath = value; }); return config; }
/// <summary> /// Khởi tạo đối tượng với thông tin cấu hình cho bởi config /// </summary> /// <param name="config"></param> public WebAppTypeFinder(NopConfig config) { this.EnsureBinFolderAssembliesLoaded = config.DynamicDiscovery; }