public void SyncUnmappedFolders() { Logger.Info("Starting Series folder scan"); try { using (_seriesSyncNotification = new ProgressNotification("Series Scan")) { _notificationProvider.Register(_seriesSyncNotification); _seriesSyncNotification.CurrentStatus = "Analysing Folder"; Thread.Sleep(20000); var unmappedFolders = _seriesProvider.GetUnmappedFolders(); _seriesSyncNotification.ProgressMax = unmappedFolders.Count; foreach (string seriesFolder in unmappedFolders) { try { _seriesSyncNotification.CurrentStatus = String.Format("Analysing Folder: {0}", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(new DirectoryInfo(seriesFolder).Name)); Logger.Info("Folder '{0}' isn't mapped in the database. Trying to map it.'", seriesFolder); var mappedSeries = _seriesProvider.MapPathToSeries(seriesFolder); if (mappedSeries == null) { Logger.Warn("Unable to find a matching series for '{0}'", seriesFolder); } else { //Check if series is mapped to another folder if (_seriesProvider.GetSeries(mappedSeries.Id) == null) { _seriesSyncNotification.CurrentStatus = String.Format("Downloading Info for '{0}'", mappedSeries.SeriesName); _seriesProvider.AddSeries(seriesFolder, mappedSeries); _episodeProvider.RefreshEpisodeInfo(mappedSeries.Id); } else { Logger.Warn("Folder '{0}' mapped to '{1}' which is already another folder assigned to it.'", seriesFolder, mappedSeries.SeriesName); } } } catch (Exception e) { Logger.ErrorException("", e); } _seriesSyncNotification.ProgressValue++; } _seriesSyncNotification.CurrentStatus = "Series Scan Completed"; Logger.Info("Series folders scan has successfully completed."); Thread.Sleep(3000); _seriesSyncNotification.Status = NotificationStatus.Completed; } } catch (Exception e) { Logger.ErrorException("", e); } }
public void Register(ProgressNotification notification) { _progressNotification.Add(notification.Id, notification); }
public void SyncSeriesWithDisk() { if (_progress != null && _progress.Status == NotificationStatus.InProgress) throw new InvalidOperationException("Another Task is already in progress. " + _progress.Title); if (String.IsNullOrEmpty(_config.SeriesRoot)) throw new InvalidOperationException("TV Series folder is not configured yet."); using (_progress = new ProgressNotification("Updating Series From Disk")) { _notificationProvider.Register(_progress); var unmappedFolders = GetUnmappedFolders(); _progress.ProgressMax = unmappedFolders.Count; foreach (string seriesFolder in unmappedFolders) { _progress.CurrentStatus = String.Format("Mapping folder {0}", seriesFolder); Logger.Info("Folder '{0}' isn't mapped to a series in the database. Trying to map it.'", seriesFolder); var mappedSeries = MapPathToSeries(seriesFolder); if (mappedSeries == null) { Logger.Warn("Unable to find a matching series for '{0}'", seriesFolder); } else { if (!_sonioRepo.Exists<Series>(s => s.SeriesId == mappedSeries.Id)) { RegisterSeries(seriesFolder, mappedSeries); } else { Logger.Warn("Folder '{0}' mapped to '{1}' which is already another folder assigned to it.'", seriesFolder, mappedSeries.SeriesName); } } _progress.ProgressValue++; } _progress.Status = NotificationStatus.Completed; } }