コード例 #1
0
ファイル: Kernel.cs プロジェクト: AreebaAroosh/Media-Browser
        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);
                }
            }
        }
コード例 #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.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);
                }
            }
        }