protected Guid GetOrAddDirectory(ImportJob importJob, IFileSystemResourceAccessor directoryAccessor, Guid parentDirectoryId,
                                         IMediaBrowsing mediaBrowsing, IImportResultHandler resultHandler)
        {
            ResourcePath directoryPath = directoryAccessor.CanonicalLocalResourcePath;
            MediaItem    directoryItem = mediaBrowsing.LoadLocalItemAsync(directoryPath, EMPTY_MIA_ID_ENUMERATION, DIRECTORY_MIA_ID_ENUMERATION).Result;

            if (directoryItem != null)
            {
                SingleMediaItemAspect da;
                if (!MediaItemAspect.TryGetAspect(directoryItem.Aspects, DirectoryAspect.Metadata, out da))
                { // This is the case if the path was formerly imported as a non-directory media item; we cannot reuse it
                    resultHandler.DeleteMediaItemAsync(directoryPath);
                    directoryItem = null;
                }
            }
            if (directoryItem == null)
            { // Add directory item to ML
                MediaItemAspect mia = new SingleMediaItemAspect(MediaAspect.Metadata);
                mia.SetAttribute(MediaAspect.ATTR_TITLE, directoryAccessor.ResourceName);
                mia.SetAttribute(MediaAspect.ATTR_SORT_TITLE, directoryAccessor.ResourceName);
                mia.SetAttribute(MediaAspect.ATTR_ISVIRTUAL, false);
                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 SingleMediaItemAspect(DirectoryAspect.Metadata);
                IList <MediaItemAspect> aspects = new List <MediaItemAspect>(new[]
                {
                    mia,
                    da,
                });
                return(resultHandler.UpdateMediaItemAsync(parentDirectoryId, directoryPath, aspects, importJob.JobType == ImportJobType.Refresh, importJob.BasePath).Result);
            }
            return(directoryItem.MediaItemId);
        }
Example #2
0
        protected async Task <MediaItem> LoadLocalItem(ResourcePath path, IEnumerable <Guid> necessaryRequestedMiaTypeIds, IEnumerable <Guid> optionalRequestedMiaTypeIds)
        {
            while (true)
            {
                try
                {
                    await Activated.WaitAsync().ConfigureAwait(false);

                    // ReSharper disable PossibleMultipleEnumeration
                    return(await _mediaBrowsingCallback.LoadLocalItemAsync(path, necessaryRequestedMiaTypeIds, optionalRequestedMiaTypeIds).ConfigureAwait(false));

                    // ReSharper restore PossibleMultipleEnumeration
                }
                catch (DisconnectedException)
                {
                    await MedialibraryDisconnectedSuspend();
                }
            }
        }