/// <summary> /// Schedule saving of all settings in the near future /// </summary> public static void Save() { IThreadPool tp = GlobalServiceProvider.Get <IThreadPool>(); if (_delaySave == null) { _delaySave = tp.Add(LazySave, "Wait for saving SkinSettings"); } else if (_delaySave.State != WorkState.INPROGRESS && _delaySave.State != WorkState.INQUEUE) { _delaySave = tp.Add(LazySave, "Wait for saving SkinSettings"); } }
public ThreadingTests() { _threadPool = new Threading.ThreadPool(); SystemThread _systemThread = new SystemThread { Name = "Process 1", Id = Guid.NewGuid() }; _systemThread.Resources.Add(_resourceA); _threadPool.Add(_systemThread); _systemThread = new SystemThread { Name = "Process 2", Id = Guid.NewGuid() }; _systemThread.Resources.Add(_resourceB); _threadPool.Add(_systemThread); _systemThread = new SystemThread { Name = "Process 3", Id = Guid.NewGuid() }; _systemThread.Resources.Add(_resourceA); _systemThread.Resources.Add(_resourceB); _threadPool.Add(_systemThread); _systemThread = new SystemThread { Name = "Process 4", Id = Guid.NewGuid() }; _systemThread.Resources.Add(_resourceC); _threadPool.Add(_systemThread); _systemThread = new SystemThread { Name = "Process 5", Id = Guid.NewGuid() }; _systemThread.Resources.Add(_resourceB); _threadPool.Add(_systemThread); _threadPool.RunAll(); Thread.Sleep(6000); }
/// <summary> /// Check if the memory cache should be cleared and starts an online update of (file-) cached series information. /// </summary> private void CheckCacheAndRefresh() { if (DateTime.Now - _memoryCacheInvalidated <= MAX_MEMCACHE_DURATION) { return; } _memoryCache.Clear(); _memoryCacheInvalidated = DateTime.Now; if (DateTime.Now - _lastRefresh <= MIN_REFRESH_INTERVAL) { return; } IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(false); if (threadPool != null) { ServiceRegistration.Get <ILogger>().Debug("SeriesTvDbMatcher: Refreshing local cache"); threadPool.Add(() => { if (Init()) { _tv.UpdateCache(); } }); } _lastRefresh = DateTime.Now; }
protected void CheckResumeMenuInternal(MediaItem item) { IResumeState resumeState = null; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement.IsValidUser) { string resumeStateString; if (userProfileDataManagement.UserProfileDataManagement.GetUserMediaItemData(userProfileDataManagement.CurrentUser.ProfileId, item.MediaItemId, PlayerContext.KEY_RESUME_STATE, out resumeStateString)) { resumeState = ResumeStateBase.Deserialize(resumeStateString); } } if (resumeState == null) { // Asynchronously leave the current workflow state because we're called from a workflow model method IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => { LeaveCheckResumePlaybackSingleItemState(); PlayItem(item); }); return; } _playMenuItems = new ItemsList(); ListItem resumeItem = new ListItem { Command = new MethodDelegateCommand(() => { LeaveCheckResumePlaybackSingleItemState(); PlayItem(item, resumeState); }) }; PositionResumeState positionResume = resumeState as PositionResumeState; if (positionResume != null) { string playbackResume = LocalizationHelper.Translate(Consts.RES_PLAYBACK_RESUME_TIME, positionResume.ResumePosition.ToString(@"hh\:mm\:ss")); resumeItem.SetLabel(Consts.KEY_NAME, playbackResume); } else { resumeItem.SetLabel(Consts.KEY_NAME, Consts.RES_PLAYBACK_RESUME); } _playMenuItems.Add(resumeItem); ListItem playItem = new ListItem(Consts.KEY_NAME, Consts.RES_PLAYBACK_FROMSTART) { Command = new MethodDelegateCommand(() => { LeaveCheckResumePlaybackSingleItemState(); PlayItem(item); }) }; _playMenuItems.Add(playItem); IScreenManager screenManager = ServiceRegistration.Get <IScreenManager>(); screenManager.ShowDialog(Consts.DIALOG_PLAY_MENU, (dialogName, dialogInstanceId) => LeaveCheckResumePlaybackSingleItemState()); }
static void LazySave() { System.Threading.Thread.Sleep(100); // This combines quick calls to Save into one Save operation IThreadPool tp = GlobalServiceProvider.Get <IThreadPool>(); tp.Add(_Save); // Add the save operation to the thread pool }
//Asynchronously performs a query using the specified filter protected void UpdateAsync() { //Avoid recursive calls, this can happen if the call to BeginUpdate //updates one of our properties, triggering another update if (_isUpdating) { return; } _isUpdating = true; try { OnBeginUpdate(); } finally { _isUpdating = false; } //Check state is valid before invoking a thread pool thread if (Filter == null) { //Set target property to null if invalid to remove any previously assigned media items UpdateTargetProperty(null, QueryMode); return; } //Update using the thread pool IThreadPool tp = ServiceRegistration.Get <IThreadPool>(); tp.Add(Update); }
public void ImportPlaylist() { ILogger logger = ServiceRegistration.Get <ILogger>(); SaveSettings(); string importFile = ImportFile; if (!File.Exists(importFile)) { logger.Warn("PlaylistImportModel: Cannot import playlist, playlist file '{0}' does not exist", importFile); return; } logger.Info("PlaylistImportModel: Importing playlist '{0}'", importFile); IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>(); IContentDirectory cd = scm.ContentDirectory; if (cd == null) { logger.Warn("PlaylistImportModel: Cannot import playlist, the server is not connected"); return; } IList <string> mediaFiles = M3U.ExtractFileNamesFromPlaylist(importFile); IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => RunImportOperationAsync(cd, mediaFiles)); }
public void SyncMediaToTrakt() { if (!IsSynchronizing) { IsSynchronizing = true; IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(SyncMediaToTrakt_Async, ThreadPriority.BelowNormal); } }
protected BaseMatcher() { // Use own thread to avoid delay during startup IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(false); if (threadPool != null) { threadPool.Add(ResumeDownloads, "ResumeDownloads", QueuePriority.Normal, ThreadPriority.BelowNormal); } }
protected void PlayOrEnqueueItemsInternal(GetMediaItemsDlgt getMediaItemsFunction, AVType avType, bool play, PlayerContextConcurrencyMode concurrencyMode) { IPlayerContext pc = PreparePlayerContext(avType, play, concurrencyMode); if (pc == null) { return; } // Adding items to playlist must be executed asynchronously - we will show a progress dialog where we aren't allowed // to block the input thread. IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => AsyncAddToPlaylist(pc, getMediaItemsFunction, play)); }
protected void Download_Async() { if (!_asyncStarted) { IFanArtService fanArtService = ServiceRegistration.Get <IFanArtService>(false); if (fanArtService == null) { return; } IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => { IList <FanArtImage> possibleSources = fanArtService.GetFanArt(FanArtMediaType, FanArtType, FanArtName, MaxWidth, MaxHeight, true); lock (_syncObj) _possibleSources = possibleSources; }); _asyncStarted = true; } }
protected void GetNowAndNextProgramsList(ChannelProgramListItem channelItem, IChannel channel) { IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => { IProgram currentProgram; IProgram nextProgram; // We do not check return code here. Results for currentProgram or nextProgram can be null, this is ok here, as Program will be filled with placeholder. if (_tvHandler.ProgramInfo == null) { return; } _tvHandler.ProgramInfo.GetNowNextProgram(channel, out currentProgram, out nextProgram); CreateProgramListItem(currentProgram, channelItem.Programs[0]); CreateProgramListItem(nextProgram, channelItem.Programs[1], currentProgram); }, QueuePriority.Low ); }
/// <summary> /// Saves watched movies and series episodes to a file. /// This is a command and it is called from the backup dialog view. /// </summary> public void BackupLibrary() { try { IThreadPool threadPool = _mediaPortalServices.GetThreadPool(); threadPool.Add(() => { Status = "[Backup.Movies]"; _moverOperations.BackupMovies(_selectedPath); Status = "[Backup.Series]"; _moverOperations.BackupSeries(_selectedPath); Status = "[Backup.Finished]"; }, ThreadPriority.BelowNormal); } catch (Exception ex) { Status = "[Backup.Failed]"; _mediaPortalServices.GetLogger().Error(ex.Message); } }
public void BackupLibrary() { try { IThreadPool threadPool = _mediaPortalServices.GetThreadPool(); threadPool.Add(() => { TestStatus = "[Trakt.BackupMovies]"; _librarySynchronization.BackupMovies(); TestStatus = "[Trakt.BackupSeries]"; _librarySynchronization.BackupSeries(); IsSynchronizing = false; TestStatus = "[Trakt.BackupFinished]"; }, ThreadPriority.BelowNormal); } catch (Exception ex) { TestStatus = "[Trakt.BackupFailed]"; _mediaPortalServices.GetLogger().Error(ex.Message); } }
protected virtual void RefreshCache() { if (CacheRefreshable && Enabled) { if (!_lastCacheRefresh.HasValue) { if (string.IsNullOrEmpty(_config.LastRefresh)) { _config.LastRefresh = DateTime.Now.ToString(CONFIG_DATE_FORMAT); } _lastCacheRefresh = DateTime.ParseExact(_config.LastRefresh, CONFIG_DATE_FORMAT, CultureInfo.InvariantCulture); } if (DateTime.Now - _lastCacheCheck <= CACHE_CHECK_INTERVAL) { return; } _lastCacheCheck = DateTime.Now; IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(false); if (threadPool != null) { Logger.Debug(_id + ": Checking local cache"); threadPool.Add(() => { if (_wrapper != null) { if (_wrapper.RefreshCache(_lastCacheRefresh.Value)) { _lastCacheRefresh = DateTime.Now; _config.LastRefresh = _lastCacheRefresh.Value.ToString(CONFIG_DATE_FORMAT, CultureInfo.InvariantCulture); } } }); } SaveConfig(); } }
public virtual bool Init() { if (_storage == null) { _storage = new MatchStorage <TMatch, TId>(MatchesSettingsFile); } if (!_inited) { // Use own thread to avoid delay during startup IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(false); if (threadPool != null) { threadPool.Add(ResumeDownloads, "ResumeDownloads", QueuePriority.Normal, ThreadPriority.BelowNormal); } _inited = true; } if (!NetworkConnectionTracker.IsNetworkConnected) { return(false); } return(true); }
public void SyncMediaToTrakt() { if (!IsSynchronizing) { try { IsSynchronizing = true; IThreadPool threadPool = _mediaPortalServices.GetThreadPool(); threadPool.Add(() => { if (_mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncOnlyMovies || _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncSeriesAndMovies) { TestStatus = "[Trakt.SyncMovies]"; _librarySynchronization.SyncMovies(); } if (_mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncOnlySeries || _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.SyncSeriesAndMovies) { TestStatus = "[Trakt.SyncSeries]"; _librarySynchronization.SyncSeries(); } IsSynchronizing = false; TestStatus = "[Trakt.SyncFinished]"; }, ThreadPriority.BelowNormal); } catch (MediaLibraryNotConnectedException ex) { TestStatus = "[Trakt.MediaLibraryNotConnected]"; _mediaPortalServices.GetLogger().Error(ex.Message); } catch (Exception ex) { TestStatus = "[Trakt.SyncingFailed]"; _mediaPortalServices.GetLogger().Error(ex.Message); } } }
public void SyncMediaToTrakt() { if (!IsSynchronizing) { ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>(); TraktSettings settings = settingsManager.Load <TraktSettings>(); if (!settings.IsAuthorized) { TestStatus = "[Trakt.NotAuthorized]"; TraktLogger.Error("Trakt.tv not authorized"); return; } if (!TraktCache.RefreshData()) { return; } IsSynchronizing = true; IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(SyncMediaToTrakt_Async, ThreadPriority.BelowNormal); } }
protected void CheckPlayMenuInternal(MediaItem item) { IPlayerContextManager pcm = ServiceRegistration.Get <IPlayerContextManager>(); int numOpen = pcm.NumActivePlayerContexts; if (numOpen == 0) { // Asynchronously leave the current workflow state because we're called from a workflow model method IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => { LeaveCheckQueryPlayActionSingleItemState(); CheckEdition(item); //CheckResumeAction(item); }); return; } _playMenuItems = new ItemsList(); AVType avType = pcm.GetTypeOfMediaItem(item); int numAudio = pcm.GetPlayerContextsByAVType(AVType.Audio).Count(); int numVideo = pcm.GetPlayerContextsByAVType(AVType.Video).Count(); switch (avType) { case AVType.Audio: { ListItem playItem = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_AUDIO_ITEM) { Command = new MethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); CheckEdition(item); //CheckResumeAction(item); }) }; _playMenuItems.Add(playItem); if (numAudio > 0) { ListItem enqueueItem = new ListItem(Consts.KEY_NAME, Consts.RES_ENQUEUE_AUDIO_ITEM) { Command = new AsyncMethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); return(PlayOrEnqueueItem(item, false, PlayerContextConcurrencyMode.None)); }) }; _playMenuItems.Add(enqueueItem); } if (numVideo > 0) { ListItem playItemConcurrently = new ListItem(Consts.KEY_NAME, Consts.RES_MUTE_VIDEO_PLAY_AUDIO_ITEM) { Command = new AsyncMethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); return(PlayOrEnqueueItem(item, true, PlayerContextConcurrencyMode.ConcurrentVideo)); }) }; _playMenuItems.Add(playItemConcurrently); } } break; case AVType.Video: { ListItem playItem = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_VIDEO_IMAGE_ITEM) { Command = new MethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); CheckEdition(item); //CheckResumeAction(item); }) }; _playMenuItems.Add(playItem); if (numVideo > 0) { ListItem enqueueItem = new ListItem(Consts.KEY_NAME, Consts.RES_ENQUEUE_VIDEO_IMAGE_ITEM) { Command = new AsyncMethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); return(PlayOrEnqueueItem(item, false, PlayerContextConcurrencyMode.None)); }) }; _playMenuItems.Add(enqueueItem); } if (numAudio > 0) { ListItem playItem_A = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_VIDEO_IMAGE_ITEM_MUTED_CONCURRENT_AUDIO) { Command = new AsyncMethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); return(PlayOrEnqueueItem(item, true, PlayerContextConcurrencyMode.ConcurrentAudio)); }) }; _playMenuItems.Add(playItem_A); } if (numVideo > 0) { ListItem playItem_V = new ListItem(Consts.KEY_NAME, Consts.RES_PLAY_VIDEO_IMAGE_ITEM_PIP) { Command = new AsyncMethodDelegateCommand(() => { LeaveCheckQueryPlayActionSingleItemState(); return(PlayOrEnqueueItem(item, true, PlayerContextConcurrencyMode.ConcurrentVideo)); }) }; _playMenuItems.Add(playItem_V); } } break; default: { IDialogManager dialogManager = ServiceRegistration.Get <IDialogManager>(); Guid dialogHandleId = dialogManager.ShowDialog(Consts.RES_SYSTEM_INFORMATION, Consts.RES_CANNOT_PLAY_ITEM_DIALOG_TEXT, DialogType.OkDialog, false, DialogButtonType.Ok); _dialogCloseWatcher = new DialogCloseWatcher(this, dialogHandleId, dialogResult => LeaveCheckQueryPlayActionSingleItemState()); } break; } IScreenManager screenManager = ServiceRegistration.Get <IScreenManager>(); screenManager.ShowDialog(Consts.DIALOG_PLAY_MENU, (dialogName, dialogInstanceId) => LeaveCheckQueryPlayActionSingleItemState()); }
protected void GetNowAndNextProgramsList_Async() { IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(GetNowAndNextProgramsList); }
protected void FillList_Async(IContentDirectory contentDirectory, Guid[] necessaryMIAs, ItemsList list, MediaItemToListItemAction converterAction) { IThreadPool threadPool = ServiceRegistration.Get <IThreadPool>(); threadPool.Add(() => FillList(contentDirectory, necessaryMIAs, list, converterAction)); }