/// <summary> /// Deletes the created task. /// </summary> private void EndRefreshTask() { if (_refreshIntervalWork == null) { return; } ServiceRegistration.Get <IThreadPool>().RemoveIntervalWork(_refreshIntervalWork); _refreshIntervalWork = null; }
/// <summary> /// Run the given <paramref name="intervalWork"/>. /// </summary> /// <param name="intervalWork">IIntervalWork to run.</param> protected void RunIntervalBasedWork(IIntervalWork intervalWork) { // ServiceRegistration.Get<ILogger>().Debug("ThreadPool.RunIntervalBasedWork(): Running interval based work '{0}' (interval: {1})", // intervalWork.Work.Description, intervalWork.WorkInterval); intervalWork.ResetWorkState(); intervalWork.LastRun = DateTime.Now; intervalWork.Running = true; Add(intervalWork.Work, QueuePriority.Low); }
public void RemoveIntervalWork(IIntervalWork intervalWork) { lock (_intervalBasedWork) { if (_intervalBasedWork.Contains(intervalWork)) { _intervalBasedWork.Remove(intervalWork); } } }
private void OnlineVideosSettingsChanged(object sender, EventArgs e) { bool rebuildUtils = false; bool rebuildList = false; var settings = (sender as SettingsChangeWatcher <Configuration.Settings>).Settings; // a download dir was now configured or removed if ((string.IsNullOrEmpty(OnlineVideoSettings.Instance.DownloadDir) && !string.IsNullOrEmpty(settings.DownloadFolder)) || (!string.IsNullOrEmpty(OnlineVideoSettings.Instance.DownloadDir) && string.IsNullOrEmpty(settings.DownloadFolder))) { rebuildUtils = true; rebuildList = true; } // usage of age confirmation has changed if (settings.UseAgeConfirmation != OnlineVideoSettings.Instance.UseAgeConfirmation) { rebuildList = true; } settings.SetValuesToApi(); if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt()) { if (rebuildUtils) { OnlineVideoSettings.Instance.BuildSiteUtilsList(); } if (rebuildList) { ServiceRegistration.Get <IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, new SystemMessage(OnlineVideosMessaging.MessageType.RebuildSites)); } } // check if automatic update is now enabled / disabled and start / stop or change interval to run var threadPool = ServiceRegistration.Get <IThreadPool>(); if (_autoUpdateTask != null) { // if automatic update no longer requested or different update interval -> delete the current task if (!settings.AutomaticUpdate || (int)_autoUpdateTask.WorkInterval.TotalHours != settings.AutomaticUpdateInterval) { threadPool.RemoveIntervalWork(_autoUpdateTask); _autoUpdateTask = null; } } if (settings.AutomaticUpdate && _autoUpdateTask == null) { // create the task _autoUpdateTask = new IntervalWork(PeriodicSitesUpdate, TimeSpan.FromHours(settings.AutomaticUpdateInterval)); threadPool.AddIntervalWork(_autoUpdateTask, false); } }
public void Startup() { if (_checkTimeoutIntervalWork != null) { return; } IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); _checkTimeoutIntervalWork = new IntervalWork(CheckTimeouts, TIMESPAN_CHECK_NOTIFICATION_TIMEOUTS); threadPool.AddIntervalWork(_checkTimeoutIntervalWork, true); }
/// <summary> /// Creates a task for background refresh that gets executed every n seconds (refresh interval). /// </summary> private void StartRefreshTask() { if (_refreshIntervalSec == null) { return; } if (_refreshIntervalWork != null) { return; } _refreshIntervalWork = new IntervalWork(Refresh, TimeSpan.FromSeconds((int)_refreshIntervalSec)); ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_refreshIntervalWork, false); }
private void AfterInitialLoad(WorkEventArgs args) { var ovMP2Settings = ServiceRegistration.Get <ISettingsManager>().Load <Configuration.Settings>(); if (Sites.Updater.VersionCompatible && ovMP2Settings.AutomaticUpdate) { _autoUpdateTask = new IntervalWork(PeriodicSitesUpdate, TimeSpan.FromHours(ovMP2Settings.AutomaticUpdateInterval)); ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_autoUpdateTask, false); } // start listening to changes of the OnlineVideos configuration settings _settingsWatcher = new SettingsChangeWatcher <Configuration.Settings>(); _settingsWatcher.SettingsChanged += OnlineVideosSettingsChanged; }
/// <summary> /// Creates a scheduled task that will run a analysis cleanup periodically. /// </summary> public void UpdateAnalysisCleanupIntervalWork(TranscodingServiceSettings settings) { _enableAnalysisOfImportedMedia = settings.EnableAnalysisOfImportedMedia; if (_analysisCleanupIntervalWork != null) { if (settings.EnableCleanupOrphanedAnalysis && settings.CleanupOrphanedAnalysisIntervalHours == _analysisCleanupIntervalWork.WorkInterval.TotalHours) { return; //Nothing has changed } ServiceRegistration.Get <IThreadPool>().RemoveIntervalWork(_analysisCleanupIntervalWork); } if (settings.EnableCleanupOrphanedAnalysis && settings.CleanupOrphanedAnalysisIntervalHours > 0) { _analysisCleanupIntervalWork = new IntervalWork(ScheduleAnalysisCleanup, TimeSpan.FromHours(settings.CleanupOrphanedAnalysisIntervalHours)); ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_analysisCleanupIntervalWork, false); } }
/// <summary> /// Creates a scheduled task that will run a fanart cleanup periodically. /// </summary> protected void UpdateFanArtCleanupIntervalWork() { FanArtServiceSettings settings = _settings.Settings; if (_fanArtCleanupIntervalWork != null) { if (settings.EnableCleanupOrphanedFanArt && settings.CleanupOrphanedFanArtIntervalHours == _fanArtCleanupIntervalWork.WorkInterval.TotalHours) { return; //Nothing has changed } ServiceRegistration.Get <IThreadPool>().RemoveIntervalWork(_fanArtCleanupIntervalWork); } if (settings.EnableCleanupOrphanedFanArt && settings.CleanupOrphanedFanArtIntervalHours > 0) { _fanArtCleanupIntervalWork = new IntervalWork(ScheduleFanArtCleanup, TimeSpan.FromHours(_settings.Settings.CleanupOrphanedFanArtIntervalHours)); ServiceRegistration.Get <IThreadPool>().AddIntervalWork(_fanArtCleanupIntervalWork, false); } }
public void AddIntervalWork(IIntervalWork intervalWork, bool runNow) { if (_startInfo.DelayedInit) { _startInfo.DelayedInit = false; Init(); } if (intervalWork == null) { throw new ArgumentNullException("intervalWork", "cannot be null"); } lock (_intervalBasedWork) { _intervalBasedWork.Add(intervalWork); if (runNow) { RunIntervalBasedWork(intervalWork); } } }
/// <summary> /// Deletes the created task. /// </summary> private void EndRefreshTask() { if (_refreshIntervalWork == null) return; ServiceRegistration.Get<IThreadPool>().RemoveIntervalWork(_refreshIntervalWork); _refreshIntervalWork = null; }
/// <summary> /// Creates a task for background refresh that gets executed every n seconds (refresh interval). /// </summary> private void StartRefreshTask() { if (_refreshIntervalSec == null) return; if (_refreshIntervalWork != null) return; _refreshIntervalWork = new IntervalWork(Refresh, TimeSpan.FromSeconds((int) _refreshIntervalSec)); ServiceRegistration.Get<IThreadPool>().AddIntervalWork(_refreshIntervalWork, false); }
public void RemoveIntervalWork(IIntervalWork intervalWork) { lock (_intervalBasedWork) { if (_intervalBasedWork.Contains(intervalWork)) _intervalBasedWork.Remove(intervalWork); } }
private void OnlineVideosSettingsChanged(object sender, EventArgs e) { bool rebuildUtils = false; bool rebuildList = false; var settings = (sender as SettingsChangeWatcher<Configuration.Settings>).Settings; // a download dir was now configured or removed if ((string.IsNullOrEmpty(OnlineVideoSettings.Instance.DownloadDir) && !string.IsNullOrEmpty(settings.DownloadFolder)) || (!string.IsNullOrEmpty(OnlineVideoSettings.Instance.DownloadDir) && string.IsNullOrEmpty(settings.DownloadFolder))) { rebuildUtils = true; rebuildList = true; } // usage of age confirmation has changed if (settings.UseAgeConfirmation != OnlineVideoSettings.Instance.UseAgeConfirmation) { rebuildList = true; } settings.SetValuesToApi(); if (OnlineVideoSettings.Instance.IsSiteUtilsListBuilt()) { if (rebuildUtils) OnlineVideoSettings.Instance.BuildSiteUtilsList(); if (rebuildList) { ServiceRegistration.Get<IMessageBroker>().Send(OnlineVideosMessaging.CHANNEL, new SystemMessage(OnlineVideosMessaging.MessageType.RebuildSites)); } } // check if automatic update is now enabled / disabled and start / stop or change interval to run var threadPool = ServiceRegistration.Get<IThreadPool>(); if (_autoUpdateTask != null) { // if automatic update no longer requested or different update interval -> delete the current task if (!settings.AutomaticUpdate || (int)_autoUpdateTask.WorkInterval.TotalHours != settings.AutomaticUpdateInterval) { threadPool.RemoveIntervalWork(_autoUpdateTask); _autoUpdateTask = null; } } if (settings.AutomaticUpdate && _autoUpdateTask == null) { // create the task _autoUpdateTask = new IntervalWork(PeriodicSitesUpdate, TimeSpan.FromHours(settings.AutomaticUpdateInterval)); threadPool.AddIntervalWork(_autoUpdateTask, false); } }
private void AfterInitialLoad(WorkEventArgs args) { var ovMP2Settings = ServiceRegistration.Get<ISettingsManager>().Load<Configuration.Settings>(); if (Sites.Updater.VersionCompatible && ovMP2Settings.AutomaticUpdate) { _autoUpdateTask = new IntervalWork(PeriodicSitesUpdate, TimeSpan.FromHours(ovMP2Settings.AutomaticUpdateInterval)); ServiceRegistration.Get<IThreadPool>().AddIntervalWork(_autoUpdateTask, false); } // start listening to changes of the OnlineVideos configuration settings _settingsWatcher = new SettingsChangeWatcher<Configuration.Settings>(); _settingsWatcher.SettingsChanged += OnlineVideosSettingsChanged; }
public void AddIntervalWork(IIntervalWork intervalWork, bool runNow) { if (_startInfo.DelayedInit) { _startInfo.DelayedInit = false; Init(); } if (intervalWork == null) throw new ArgumentNullException("intervalWork", "cannot be null"); lock (_intervalBasedWork) { _intervalBasedWork.Add(intervalWork); if (runNow) RunIntervalBasedWork(intervalWork); } }
public void Startup() { if (_checkTimeoutIntervalWork != null) return; IThreadPool threadPool = ServiceRegistration.Get<IThreadPool>(); _checkTimeoutIntervalWork = new IntervalWork(CheckTimeouts, TIMESPAN_CHECK_NOTIFICATION_TIMEOUTS); threadPool.AddIntervalWork(_checkTimeoutIntervalWork, true); }