Beispiel #1
0
        public static void Init(KernelLoadDirective directives)
        {
            ConfigData config = null;

            config = ConfigData.FromFile(ApplicationPaths.ConfigFile);

            Init(directives, config);
        }
Beispiel #2
0
        public static void Init(KernelLoadDirective directives, ConfigData config)
        {
            lock (sync) {
                // we must set up some paths as well as a side effect (should be refactored)
                if (!string.IsNullOrEmpty(config.UserSettingsPath) && Directory.Exists(config.UserSettingsPath))
                {
                    ApplicationPaths.SetUserSettingsPath(config.UserSettingsPath);
                }


                // its critical to have the logger initialized early so initialization routines can use the right logger.
                Logger.LoggerInstance = GetDefaultLogger(config);
                var kernel = GetDefaultKernel(config, directives);
                Kernel.Instance = kernel;

                // add the podcast home
                var podcastHome = kernel.GetItem <Folder>(kernel.ConfigData.PodcastHome);
                if (podcastHome != null && podcastHome.Children.Count > 0)
                {
                    kernel.RootFolder.AddVirtualChild(podcastHome);
                }
            }
        }
Beispiel #3
0
        public static void Init(KernelLoadDirective directives, CommonConfigData config)
        {
            lock (sync) {
                // Its critical to have the logger initialized early so initialization
                //   routines can use the right logger.
                if (Logger.LoggerInstance != null)
                {
                    Logger.LoggerInstance.Dispose();
                }

                Logger.LoggerInstance = GetDefaultLogger(config);

                AppDomain.CurrentDomain.UnhandledException += CrashHandler;

                // Now try and wake the last server we connected to if set
                if (config.WakeServer && !string.IsNullOrEmpty(config.LastServerMacAddress))
                {
                    Helper.WakeMachine(config.LastServerMacAddress);
                }

                var defaultKernel = GetDefaultKernel(config, directives);
                Instance = defaultKernel;
            }
        }
Beispiel #4
0
        static Kernel GetDefaultKernel(ConfigData config, KernelLoadDirective loadDirective)
        {
            var kernel = new Kernel()
            {
                PlaybackControllers       = new List <IPlaybackController>(),
                MetadataProviderFactories = MetadataProviderHelper.DefaultProviders(),
                ImageResolvers            = DefaultImageResolvers,
                ConfigData           = config,
                ItemRepository       = new SafeItemRepository(new ItemRepository()),
                MediaLocationFactory = new MediaBrowser.Library.Factories.MediaLocationFactory()
            };


            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);

            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 {
                    plugin.Init(kernel);
                } catch (Exception e) {
                    Logger.ReportException("Failed to initialize Plugin : " + plugin.Name, e);
                    kernel.Plugins.Remove(plugin);
                }
            }

            return(kernel);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public static void Init(KernelLoadDirective directives, ConfigData config)
        {
            lock (sync) {
                // we must set up some paths as well as a side effect (should be refactored)
                if (!string.IsNullOrEmpty(config.UserSettingsPath) && Directory.Exists(config.UserSettingsPath))
                {
                    ApplicationPaths.SetUserSettingsPath(config.UserSettingsPath.Trim());
                }

                // Its critical to have the logger initialized early so initialization
                //   routines can use the right logger.
                if (Logger.LoggerInstance != null)
                {
                    Logger.LoggerInstance.Dispose();
                }

                Logger.LoggerInstance = GetDefaultLogger(config);

                var kernel = GetDefaultKernel(config, directives);
                Kernel.Instance = kernel;

                // setup IBN if not there
                string ibnLocation = Config.Instance.ImageByNameLocation;
                if (string.IsNullOrEmpty(ibnLocation))
                {
                    ibnLocation = Path.Combine(ApplicationPaths.AppConfigPath, "ImagesByName");
                }
                if (!Directory.Exists(ibnLocation))
                {
                    try
                    {
                        Directory.CreateDirectory(ibnLocation);
                        Directory.CreateDirectory(Path.Combine(ibnLocation, "Genre"));
                        Directory.CreateDirectory(Path.Combine(ibnLocation, "People"));
                        Directory.CreateDirectory(Path.Combine(ibnLocation, "Studio"));
                        Directory.CreateDirectory(Path.Combine(ibnLocation, "Year"));
                        Directory.CreateDirectory(Path.Combine(ibnLocation, "General"));
                        Directory.CreateDirectory(Path.Combine(ibnLocation, "MediaInfo"));
                    }
                    catch (Exception e)
                    {
                        Logger.ReportException("Unable to create IBN location.", e);
                    }
                }

                if (LoadContext == MBLoadContext.Core || LoadContext == MBLoadContext.Configurator)
                {
                    Async.Queue("Start Service", () =>
                    {
                        //start our service if its not already going
                        if (!MBServiceController.IsRunning)
                        {
                            Logger.ReportInfo("Starting MB Service...");
                            MBServiceController.StartService();
                        }
                    });
                }
                if (LoadContext == MBLoadContext.Core)
                {
                    //listen for commands
                    if (!MBClientConnector.StartListening())
                    {
                        //we couldn't start our listener - probably another instance going so we shut down
                        Logger.ReportInfo("Could not start listener - assuming another instance of MB.  Closing...");
                        Microsoft.MediaCenter.Hosting.AddInHost.Current.ApplicationContext.CloseApplication();
                        return;
                    }
                    MBServiceController.ConnectToService(); //set up for service to tell us to do things
                }

                // create filewatchers for each of our top-level folders (only if we are in MediaCenter, though)
                bool isMC = AppDomain.CurrentDomain.FriendlyName.Contains("ehExtHost");
                if (isMC && config.EnableDirectoryWatchers) //only do this inside of MediaCenter as we don't want to be trying to refresh things if MB isn't actually running
                {
                    Async.Queue("Create Filewatchers", () =>
                    {
                        foreach (BaseItem item in kernel.RootFolder.Children)
                        {
                            Folder folder = item as Folder;
                            if (folder != null)
                            {
                                folder.directoryWatcher = new MBDirectoryWatcher(folder, false);
                            }
                        }

                        // create a watcher for the startup folder too - and watch all changes there
                        kernel.RootFolder.directoryWatcher = new MBDirectoryWatcher(kernel.RootFolder, true);
                    });
                }


                // add the podcast home
                var podcastHome = kernel.GetItem <Folder>(kernel.ConfigData.PodcastHome);
                if (podcastHome != null && podcastHome.Children.Count > 0)
                {
                    kernel.RootFolder.AddVirtualChild(podcastHome);
                }
            }
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
 public static void Init(KernelLoadDirective directives)
 {
     Init(directives, ConfigData.FromFile(ApplicationPaths.ConfigFile));
 }