protected Guid GetOrAddDirectory(IFileSystemResourceAccessor directoryAccessor, Guid parentDirectoryId, IMediaBrowsing mediaBrowsing, IImportResultHandler resultHandler) { ResourcePath directoryPath = directoryAccessor.CanonicalLocalResourcePath; MediaItem directoryItem = mediaBrowsing.LoadLocalItem(directoryPath, EMPTY_MIA_ID_ENUMERATION, DIRECTORY_MIA_ID_ENUMERATION); if (directoryItem != null) { MediaItemAspect da; if (!directoryItem.Aspects.TryGetValue(DirectoryAspect.ASPECT_ID, out da)) { // This is the case if the path was formerly imported as a non-directory media item; we cannot reuse it resultHandler.DeleteMediaItem(directoryPath); directoryItem = null; } } if (directoryItem == null) { // Add directory item to ML MediaItemAspect mia = new MediaItemAspect(MediaAspect.Metadata); mia.SetAttribute(MediaAspect.ATTR_TITLE, directoryAccessor.ResourceName); mia.SetAttribute(MediaAspect.ATTR_MIME_TYPE, null); mia.SetAttribute(MediaAspect.ATTR_RECORDINGTIME, DateTime.MinValue); mia.SetAttribute(MediaAspect.ATTR_RATING, 0); mia.SetAttribute(MediaAspect.ATTR_COMMENT, null); mia.SetAttribute(MediaAspect.ATTR_LASTPLAYED, DateTime.MinValue); MediaItemAspect da = new MediaItemAspect(DirectoryAspect.Metadata); IList <MediaItemAspect> aspects = new List <MediaItemAspect>(new[] { mia, da, }); return(resultHandler.UpdateMediaItem(parentDirectoryId, directoryPath, aspects)); } return(directoryItem.MediaItemId); }
/// <summary> /// Imports or refreshes a single file without a parent directory with the specified <paramref name="fileAccessor"/>. /// </summary> /// <param name="importJob">The import job being processed.</param> /// <param name="fileAccessor">Resource accessor for the file to import.</param> /// <param name="metadataExtractors">Metadata extractors to apply on the resource.</param> /// <param name="mediaBrowsing">Callback interface to the media library for the refresh import type.</param> /// <param name="resultHandler">Callback to notify the import result.</param> /// <param name="mediaAccessor">Convenience reference to the media accessor.</param> protected void ImportSingleFile(ImportJob importJob, IResourceAccessor fileAccessor, ICollection <IMetadataExtractor> metadataExtractors, IMediaBrowsing mediaBrowsing, IImportResultHandler resultHandler, IMediaAccessor mediaAccessor) { ResourcePath currentFilePath = fileAccessor.CanonicalLocalResourcePath; try { if (importJob.JobType == ImportJobType.Refresh) { MediaItem mediaItem = mediaBrowsing.LoadLocalItem(currentFilePath, IMPORTER_MIA_ID_ENUMERATION, EMPTY_MIA_ID_ENUMERATION); MediaItemAspect importerAspect; if (mediaItem != null && mediaItem.Aspects.TryGetValue(ImporterAspect.ASPECT_ID, out importerAspect) && (DateTime)importerAspect[ImporterAspect.ATTR_LAST_IMPORT_DATE] > fileAccessor.LastChanged) { return; } } ImportResource(fileAccessor, Guid.Empty, metadataExtractors, resultHandler, mediaAccessor); } catch (Exception e) { CheckSuspended(e); // Throw ImportAbortException if suspended - will skip warning and tagging job as erroneous ServiceRegistration.Get <ILogger>().Warn("ImporterWorker: Problem while importing resource '{0}'", e, currentFilePath); importJob.State = ImportJobState.Erroneous; } }
protected async Task <MediaItem> LoadLocalItem(ResourcePath path, IEnumerable <Guid> necessaryRequestedMiaTypeIds, IEnumerable <Guid> optionalRequestedMiaTypeIds) { while (true) { try { await Activated.WaitAsync(); // ReSharper disable PossibleMultipleEnumeration return(_mediaBrowsingCallback.LoadLocalItem(path, necessaryRequestedMiaTypeIds, optionalRequestedMiaTypeIds)); // ReSharper restore PossibleMultipleEnumeration } catch (DisconnectedException) { ServiceRegistration.Get <ILogger>().Info("ImporterWorker.{0}.{1}: MediaLibrary disconnected. Requesting suspension...", ParentImportJobController, _blockName); ParentImportJobController.ParentImporterWorker.RequestAction(new ImporterWorkerAction(ImporterWorkerAction.ActionType.Suspend)).Wait(); } } }
protected Guid GetOrAddDirectory(IFileSystemResourceAccessor directoryAccessor, Guid parentDirectoryId, IMediaBrowsing mediaBrowsing, IImportResultHandler resultHandler) { ResourcePath directoryPath = directoryAccessor.CanonicalLocalResourcePath; MediaItem directoryItem = mediaBrowsing.LoadLocalItem(directoryPath, EMPTY_MIA_ID_ENUMERATION, DIRECTORY_MIA_ID_ENUMERATION); if (directoryItem != null) { MediaItemAspect da; if (!directoryItem.Aspects.TryGetValue(DirectoryAspect.ASPECT_ID, out da)) { // This is the case if the path was formerly imported as a non-directory media item; we cannot reuse it resultHandler.DeleteMediaItem(directoryPath); directoryItem = null; } } if (directoryItem == null) { // Add directory item to ML MediaItemAspect mia = new MediaItemAspect(MediaAspect.Metadata); mia.SetAttribute(MediaAspect.ATTR_TITLE, directoryAccessor.ResourceName); mia.SetAttribute(MediaAspect.ATTR_MIME_TYPE, null); mia.SetAttribute(MediaAspect.ATTR_RECORDINGTIME, DateTime.MinValue); mia.SetAttribute(MediaAspect.ATTR_RATING, 0); mia.SetAttribute(MediaAspect.ATTR_COMMENT, null); mia.SetAttribute(MediaAspect.ATTR_LASTPLAYED, DateTime.MinValue); MediaItemAspect da = new MediaItemAspect(DirectoryAspect.Metadata); IList<MediaItemAspect> aspects = new List<MediaItemAspect>(new[] { mia, da, }); return resultHandler.UpdateMediaItem(parentDirectoryId, directoryPath, aspects); } return directoryItem.MediaItemId; }
/// <summary> /// Imports or refreshes a single file without a parent directory with the specified <paramref name="fileAccessor"/>. /// </summary> /// <param name="importJob">The import job being processed.</param> /// <param name="fileAccessor">Resource accessor for the file to import.</param> /// <param name="metadataExtractors">Metadata extractors to apply on the resource.</param> /// <param name="mediaBrowsing">Callback interface to the media library for the refresh import type.</param> /// <param name="resultHandler">Callback to notify the import result.</param> /// <param name="mediaAccessor">Convenience reference to the media accessor.</param> protected void ImportSingleFile(ImportJob importJob, IResourceAccessor fileAccessor, ICollection<IMetadataExtractor> metadataExtractors, IMediaBrowsing mediaBrowsing, IImportResultHandler resultHandler, IMediaAccessor mediaAccessor) { ResourcePath currentFilePath = fileAccessor.CanonicalLocalResourcePath; try { if (importJob.JobType == ImportJobType.Refresh) { MediaItem mediaItem = mediaBrowsing.LoadLocalItem(currentFilePath, IMPORTER_MIA_ID_ENUMERATION, EMPTY_MIA_ID_ENUMERATION); MediaItemAspect importerAspect; if (mediaItem != null && mediaItem.Aspects.TryGetValue(ImporterAspect.ASPECT_ID, out importerAspect) && (DateTime) importerAspect[ImporterAspect.ATTR_LAST_IMPORT_DATE] > fileAccessor.LastChanged) return; } ImportResource(fileAccessor, Guid.Empty, metadataExtractors, resultHandler, mediaAccessor); } catch (Exception e) { CheckSuspended(e); // Throw ImportAbortException if suspended - will skip warning and tagging job as erroneous ServiceRegistration.Get<ILogger>().Warn("ImporterWorker: Problem while importing resource '{0}'", e, currentFilePath); importJob.State = ImportJobState.Erroneous; } }