Пример #1
0
        public bool Init()
        {
            ServiceRegistration.Get <IMessageBroker>().RegisterMessageReceiver(SystemMessaging.CHANNEL, this);
            ServiceRegistration.Get <IMessageBroker>().RegisterMessageReceiver(ClientManagerMessaging.CHANNEL, this);

            _settingWatcher = new SettingsChangeWatcher <SlimTvGenreColorSettings>();
            _settingWatcher.SettingsChanged += SettingsChanged;
            _settingWatcher.Refresh();
            return(true);
        }
        static BaseScriptableMovieMetadataExtractor()
        {
            ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>();
            var settings = settingsManager.Load <ScriptableMetadataExtractorSettings>();

            if (settings.CustomSettings.Count == 0 && settings.DefaultUserAgent == null)
            {
                settings.DefaultUserAgent = "";
                settings.CustomSettings.Add($"{SAMPLE_KEY}={SAMPLE_VALUE}");
                settingsManager.Save(settings); //Save sample settings so they can be edited
            }

            _scriptableSettingWatcher = new SettingsChangeWatcher <ScriptableMetadataExtractorSettings>();
            _scriptableSettingWatcher.SettingsChanged += (sender, args) =>
            {
                Dictionary <string, string> customSettings = new Dictionary <string, string>();
                foreach (var settingPair in _scriptableSettingWatcher.Settings.CustomSettings)
                {
                    var split = settingPair.Split('=');
                    if (split.Length == 2)
                    {
                        if (string.IsNullOrWhiteSpace(split[0]) || split[0] == SAMPLE_KEY)
                        {
                            continue; //Ignore empty or sample entry
                        }
                        customSettings.Add(split[0], split[1]);
                    }
                }

                //Add update custom settings
                foreach (var setting in customSettings)
                {
                    _customSettings.AddOrUpdate(setting.Key, setting.Value, (k, v) => setting.Value);
                }

                //Delete removed custom settings
                foreach (var settingKey in _customSettings.Keys.Except(customSettings.Keys))
                {
                    _customSettings.TryRemove(settingKey, out _);
                }

                //Update custom user agent
                if (!string.IsNullOrWhiteSpace(_scriptableSettingWatcher.Settings.DefaultUserAgent))
                {
                    _defaultUserAgent = _scriptableSettingWatcher.Settings.DefaultUserAgent;
                }
            };
            _scriptableSettingWatcher.Refresh();

            LoadScripts();
        }
        public TranscodingServicePlugin()
        {
            _profileManager = new TranscodeProfileManager();
            ServiceRegistration.Set <ITranscodeProfileManager>(_profileManager);
            Logger.Debug("TranscodingService: Registered TranscodeProfileManager.");

            _analysisLibraryManager = new AnalysisLibraryManager();

            _settings = new SettingsChangeWatcher <TranscodingServiceSettings>();
            _settings.SettingsChanged = OnSettingsChanged;
            _settings.Refresh();

            _tidyUpCacheWork = new IntervalWork(TidyUpCache, CACHE_CLEANUP_INTERVAL);
            IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>();

            threadPool.AddIntervalWork(_tidyUpCacheWork, false);
        }