public void ScheduleRefresh(ResourcePath path, IEnumerable <string> mediaCategories, bool includeSubDirectories) { ICollection <ImportJob> importJobs; lock (_syncObj) importJobs = new List <ImportJob>(_importJobs); ICollection <ImportJob> removeImportJobs = new List <ImportJob>(); foreach (ImportJob checkJob in importJobs) { if (checkJob.BasePath.IsSameOrParentOf(path)) { // The new job is included in an already existing job - re-schedule existing job path = checkJob.BasePath; checkJob.Cancel(); removeImportJobs.Add(checkJob); } if (path.IsParentOf(checkJob.BasePath)) { // The new job will include the old job checkJob.Cancel(); removeImportJobs.Add(checkJob); } } lock (_syncObj) foreach (ImportJob removeJob in removeImportJobs) { _importJobs.Remove(removeJob); } ICollection <Guid> metadataExtractorIds = GetMetadataExtractorIdsForMediaCategories(mediaCategories); ImportJob job = new ImportJob(ImportJobType.Refresh, path, metadataExtractorIds, includeSubDirectories); EnqueueImportJob(job); ImporterWorkerMessaging.SendImportMessage(ImporterWorkerMessaging.MessageType.ImportScheduled, path, ImportJobType.Refresh); }
/// <summary> /// Checks whether an ImportJob is contained in another ImportJob /// (a >= b means a contains b) /// </summary> /// <param name="other">ImportJobInformation to compare with</param> /// <returns></returns> public int CompareTo(ImportJobInformation other) { // both are equal if (Equals(other)) { return(0); } // the current ImportJobInformation contains other if (_basePath.IsParentOf(other._basePath) && _jobType == other._jobType && _includeSubDirectories && _metadataExtractorIds.IsSupersetOf(other._metadataExtractorIds)) { return(1); } return(-1); }
public void ScheduleRefresh(ResourcePath path, IEnumerable<string> mediaCategories, bool includeSubDirectories) { ICollection<ImportJob> importJobs; lock (_syncObj) importJobs = new List<ImportJob>(_importJobs); ICollection<ImportJob> removeImportJobs = new List<ImportJob>(); foreach (ImportJob checkJob in importJobs) { if (checkJob.BasePath.IsSameOrParentOf(path)) { // The new job is included in an already existing job - re-schedule existing job path = checkJob.BasePath; checkJob.Cancel(); removeImportJobs.Add(checkJob); } if (path.IsParentOf(checkJob.BasePath)) { // The new job will include the old job checkJob.Cancel(); removeImportJobs.Add(checkJob); } } lock (_syncObj) foreach (ImportJob removeJob in removeImportJobs) _importJobs.Remove(removeJob); ICollection<Guid> metadataExtractorIds = GetMetadataExtractorIdsForMediaCategories(mediaCategories); ImportJob job = new ImportJob(ImportJobType.Refresh, path, metadataExtractorIds, includeSubDirectories); EnqueueImportJob(job); ImporterWorkerMessaging.SendImportMessage(ImporterWorkerMessaging.MessageType.ImportScheduled, path, ImportJobType.Refresh); }