static Kernel GetDefaultKernel(ConfigData config, KernelLoadDirective loadDirective) { IItemRepository repository = GetRepository(config); var kernel = new Kernel() { PlaybackControllers = new List <IPlaybackController>(), MetadataProviderFactories = MetadataProviderHelper.DefaultProviders(), ConfigData = config, ServiceConfigData = ServiceConfigData.FromFile(ApplicationPaths.ServiceConfigFile), StringData = LocalizedStrings.Instance, ImageResolvers = DefaultImageResolvers(config.EnableProxyLikeCaching), ItemRepository = repository, MediaLocationFactory = new MediaBrowser.Library.Factories.MediaLocationFactory(), TrailerProviders = new List <ITrailerProvider>() { new LocalTrailerProvider() } }; //Kernel.UseNewSQLRepo = config.UseNewSQLRepo; // kernel.StringData.Save(); //save this in case we made mods (no other routine saves this data) if (LoadContext == MBLoadContext.Core) { kernel.PlaybackControllers.Add(new PlaybackController()); } // set up assembly resolution hooks, so earlier versions of the plugins resolve properly AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(OnAssemblyResolve); kernel.EntityResolver = DefaultResolver(kernel.ConfigData); // we need to enforce that the root folder is an aggregate folder var root = kernel.GetLocation(ResolveInitialFolder(kernel.ConfigData.InitialFolder)); kernel.RootFolder = (AggregateFolder)BaseItemFactory <AggregateFolder> .Instance.CreateInstance(root, null); // our root folder needs metadata kernel.RootFolder = kernel.ItemRepository.RetrieveItem(kernel.RootFolder.Id) as AggregateFolder ?? kernel.RootFolder; //create our default config panels with localized names kernel.AddConfigPanel(kernel.StringData.GetString("GeneralConfig"), ""); kernel.AddConfigPanel(kernel.StringData.GetString("MediaOptionsConfig"), ""); kernel.AddConfigPanel(kernel.StringData.GetString("ThemesConfig"), ""); kernel.AddConfigPanel(kernel.StringData.GetString("ParentalControlConfig"), ""); using (new Profiler("Plugin Loading and Init")) { kernel.Plugins = DefaultPlugins((loadDirective & KernelLoadDirective.ShadowPlugins) == KernelLoadDirective.ShadowPlugins); // initialize our plugins (maybe we should add a kernel.init ? ) // The ToList enables us to remove stuff from the list if there is a failure foreach (var plugin in kernel.Plugins.ToList()) { try { //Logger.ReportInfo("LoadContext is: " + LoadContext + " " + plugin.Name + " Initdirective is: " + plugin.InitDirective); if ((LoadContext & plugin.InitDirective) > 0) { plugin.Init(kernel); } } catch (Exception e) { Logger.ReportException("Failed to initialize Plugin : " + plugin.Name, e); kernel.Plugins.Remove(plugin); } } } return(kernel); }
static Kernel GetDefaultKernel(CommonConfigData config, KernelLoadDirective loadDirective) { var repository = new MB3ApiRepository(); var localRepo = GetLocalRepository(); var kernel = new Kernel() { PlaybackControllers = new List <BasePlaybackController>(), //MetadataProviderFactories = MetadataProviderHelper.DefaultProviders(), CommonConfigData = config, //ServiceConfigData = ServiceConfigData.FromFile(ApplicationPaths.ServiceConfigFile), StringData = LocalizedStrings.Instance, ImageResolvers = DefaultImageResolvers(false), MB3ApiRepository = repository, LocalRepo = localRepo, MediaLocationFactory = new MediaLocationFactory(), }; //Kernel.UseNewSQLRepo = config.UseNewSQLRepo; // kernel.StringData.Save(); //save this in case we made mods (no other routine saves this data) if (LoadContext == MBLoadContext.Core) { kernel.PlaybackControllers.Add(new PlaybackController()); } //kernel.EntityResolver = DefaultResolver(kernel.ConfigData); //need a blank root in case plug-ins will add virtual items kernel.RootFolder = new AggregateFolder { Name = "My Media", Id = new Guid("{F6109BAE-CA26-4746-9EBC-1CD233A7B56F}") }; //create our default config panels with localized names kernel.AddConfigPanel(kernel.StringData.GetString("GeneralConfig"), ""); kernel.AddConfigPanel(kernel.StringData.GetString("ViewOptionsConfig"), ""); kernel.AddConfigPanel(kernel.StringData.GetString("ThemesConfig"), ""); kernel.AddConfigPanel(kernel.StringData.GetString("PlaybackConfig"), ""); //kick off log clean up task if needed if (config.LastFileCleanup < DateTime.UtcNow.AddDays(-7)) { Async.Queue(Async.ThreadPoolName.LogfileCleanup, () => { Logger.ReportInfo("Running Logfile clean-up..."); var minDateModified = DateTime.UtcNow.AddDays(-(config.LogFileRetentionDays)); foreach (var source in new DirectoryInfo(ApplicationPaths.AppLogPath).GetFileSystemInfos("*.log") .Where(f => f.LastWriteTimeUtc < minDateModified)) { try { source.Delete(); } catch (Exception e) { Logger.ReportException("Error deleting log file {0}", e, source.Name); } } config.LastFileCleanup = DateTime.UtcNow; config.Save(); }); Async.Queue(Async.ThreadPoolName.ImageCacheCleanup, () => ImageCache.Instance.Clean(DateTime.UtcNow.AddDays(-(Instance.CommonConfigData.CacheFileRetentionDays)))); } return(kernel); }