Exemplo n.º 1
0
        public static void Load()
        {
            //Declared here so it's not serialised into file
            string defaultConfigFilePath = AppDomain.CurrentDomain.BaseDirectory + "config.json";

            try
            {
                SimpleLogging.WriteToLog("Opening config file: " + defaultConfigFilePath);
                string configJson = File.ReadAllText(defaultConfigFilePath);
                serviceConfigData = JsonConvert.DeserializeObject <ServiceConfigData>(configJson);
            }
            catch
            {
                string message = "Issue opening config file; please put config.json file in same directory as .exe service";
                SimpleLogging.WriteToLog(message);
                throw new Exception(message);
            }

            if (!serviceConfigData.BasicValidate())
            {
                string message = "Invalid parameter in config.json file";
                SimpleLogging.WriteToLog(message);
                throw new Exception(message);
            }
        }
Exemplo n.º 2
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);
        }