/// <summary> /// Constructs a <see cref="ResourceAccessorTextureImageSource"/> for the given data. /// </summary> /// <param name="resourceAccessor">The resource accessor to load the texture data from.</param> /// <param name="rotation">Desired rotation for the given image.</param> public ResourceAccessorTextureImageSource(IResourceAccessor resourceAccessor, RightAngledRotation rotation) { _key = resourceAccessor.CanonicalLocalResourcePath.Serialize(); _resourceAccessor = resourceAccessor; _stream = _resourceAccessor.OpenRead(); _rotation = rotation; }
public bool IsResource(IResourceAccessor baseResourceAccessor, string path) { string entryPath = ZipResourceAccessor.ToEntryPath(path); lock (_syncObj) { string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { ZipResourceProxy proxy; if (_zipUsages.TryGetValue(key, out proxy)) { return(path.Equals("/") || ZipResourceAccessor.IsResource(proxy.ZipFile, entryPath)); } } catch (Exception) { return(false); } } using (Stream resourceStream = baseResourceAccessor.OpenRead()) // Not sure if the ZipFile will close the stream so we dispose it here try { using (ZipFile zFile = new ZipFile(resourceStream)) return(path.Equals("/") || ZipResourceAccessor.IsResource(zFile, entryPath)); } catch (Exception) { return(false); } }
/// <summary> /// Gets a stream for the resource which is described by this file handle if the stream is already open or opens a new stream for it. /// </summary> /// <returns> /// This method returns the same stream for the same thread; it returns a new stream for a new thread. /// </returns> public Stream GetOrOpenStream() { Thread currentThread = Thread.CurrentThread; Stream stream; lock (_syncObj) if (_threadStreams.TryGetValue(currentThread, out stream)) { return(stream); } IResourceAccessor resourceAccessor = _resource.ResourceAccessor; try { if (resourceAccessor != null) { resourceAccessor.PrepareStreamAccess(); lock (_syncObj) return(_threadStreams[currentThread] = resourceAccessor.OpenRead()); } } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("Dokan FileHandle: Error creating stream for resource '{0}'", e, resourceAccessor); } return(null); }
/// <summary> /// Method that processes the Uri. /// </summary> /// <param name="request">Information sent by the browser about the request.</param> /// <param name="response">Information that is being sent back to the client.</param> /// <param name="session">Session object used during the client connection.</param> /// <returns><c>true</c> if this module is able to handle the request, else <c>false</c>.</returns> /// <exception cref="InternalServerException">If an exception occured in the server.</exception> /// <exception cref="ForbiddenException">If the file path is forbidden.</exception> public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session) { ResourcePath resourcePath; Uri uri = request.Uri; if (!uri.AbsolutePath.StartsWith(ResourceHttpAccessUrlUtils.RESOURCE_ACCESS_PATH)) { return(false); } if (!ResourceHttpAccessUrlUtils.ParseResourceURI(uri, out resourcePath)) { throw new BadRequestException(string.Format("Illegal request syntax. Correct syntax is '{0}'", ResourceHttpAccessUrlUtils.SYNTAX)); } if (!IsAllowedToAccess(resourcePath)) { ServiceRegistration.Get <ILogger>().Warn("ResourceAccessModule: Client tries to access forbidden resource '{0}'", resourcePath); throw new ForbiddenException(string.Format("Access of resource '{0}' not allowed", resourcePath)); } try { IResourceAccessor ra = GetResourceAccessor(resourcePath); using (Stream resourceStream = ra.OpenRead()) { response.ContentType = GuessMimeType(resourceStream, resourcePath.FileName); if (!string.IsNullOrEmpty(request.Headers["If-Modified-Since"])) { DateTime lastRequest = DateTime.Parse(request.Headers["If-Modified-Since"]); if (lastRequest.CompareTo(ra.LastChanged) <= 0) { response.Status = HttpStatusCode.NotModified; } } response.AddHeader("Last-Modified", ra.LastChanged.ToUniversalTime().ToString("r")); string byteRangesSpecifier = request.Headers["Range"]; IList <Range> ranges = ParseRanges(byteRangesSpecifier, resourceStream.Length); bool onlyHeaders = request.Method == "Headers" || response.Status == HttpStatusCode.NotModified; if (ranges != null && ranges.Count == 1) { // We only support one range SendRange(response, resourceStream, ranges[0], onlyHeaders); } else { SendWholeFile(response, resourceStream, onlyHeaders); } } } catch (FileNotFoundException ex) { throw new InternalServerException(string.Format("Failed to proccess resource '{0}'", resourcePath), ex); } return(true); }
/// <summary> /// Sets the data of the new image to be played. /// </summary> /// <param name="locator">Resource locator of the image item.</param> /// <param name="mediaItemTitle">Title of the image item.</param> /// <param name="rotation">Rotation of the image.</param> /// <param name="flipX">Flipping in horizontal direction.</param> /// <param name="flipY">Flipping in vertical direction.</param> public void SetMediaItemData(IResourceLocator locator, string mediaItemTitle, RightAngledRotation rotation, bool flipX, bool flipY) { if (locator == null) { lock (_syncObj) { DisposeTexture(); _currentLocator = null; return; } } Texture texture; ImageInformation imageInformation; using (IResourceAccessor ra = locator.CreateAccessor()) using (Stream stream = ra.OpenRead()) texture = Texture.FromStream(SkinContext.Device, stream, (int)stream.Length, 0, 0, 1, Usage.None, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0, out imageInformation); lock (_syncObj) { ReloadSettings(); _state = PlayerState.Active; DisposeTexture(); _currentLocator = locator; _mediaItemTitle = mediaItemTitle; _texture = texture; _rotation = rotation; _flipX = flipX; _flipY = flipY; SurfaceDescription desc = _texture.GetLevelDescription(0); _textureMaxUV = new SizeF(imageInformation.Width / (float)desc.Width, imageInformation.Height / (float)desc.Height); // Reset animation _animator.Initialize(); if (_slideShowTimer != null) { _slideShowTimer.Change(_slideShowImageDuration, TS_INFINITE); } else { CheckTimer(); } _playbackStartTime = DateTime.Now; if (_pauseTime.HasValue) { _pauseTime = _playbackStartTime; } } }
public ZipResourceProxy(string key, IResourceAccessor zipFileAccessor) { _key = key; _zipFileResourceAccessor = zipFileAccessor; _zipFileStream = _zipFileResourceAccessor.OpenRead(); // Not sure if the ZipFile closes the stream appropriately, so we keep a reference to it try { _zipFile = new ZipFile(_zipFileStream); } catch { _zipFileStream.Dispose(); throw; } }
public IsoResourceProxy(string key, IResourceAccessor isoFileResourceAccessor) { _key = key; _isoFileResourceAccessor = isoFileResourceAccessor; _underlayingStream = _isoFileResourceAccessor.OpenRead(); try { _diskFileSystem = GetFileSystem(_underlayingStream); } catch { _underlayingStream.Dispose(); throw; } }
public bool IsResource(IResourceAccessor baseResourceAccessor, string path) { string resourceName = baseResourceAccessor.ResourceName; if (string.IsNullOrEmpty(resourceName) || !baseResourceAccessor.IsFile) { return(false); } // Test if we have already an ISO proxy for that ISO file... lock (_syncObj) { string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { IsoResourceProxy proxy; if (_isoUsages.TryGetValue(key, out proxy)) { return(IsoResourceAccessor.IsResource(proxy.DiskFileSystem, path)); } } catch (Exception) { return(false); } } // ... if not, test the resource in a new disk file system instance using (Stream underlayingStream = baseResourceAccessor.OpenRead()) { try { IFileSystem diskFileSystem = IsoResourceProxy.GetFileSystem(underlayingStream); using (diskFileSystem as IDisposable) return(IsoResourceAccessor.IsResource(diskFileSystem, path)); } catch { return(false); } } }
protected MediaInfoWrapper ReadMediaInfo(IResourceAccessor mediaItemAccessor) { MediaInfoWrapper result = new MediaInfoWrapper(); Stream stream = null; try { stream = mediaItemAccessor.OpenRead(); if (stream != null) { result.Open(stream); } } finally { if (stream != null) { stream.Close(); } } return(result); }
public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode) { string fileName = mediaItemAccessor.ResourceName; if (!HasImageExtension(fileName)) { return(false); } MediaItemAspect mediaAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MediaAspect.Metadata); MediaItemAspect imageAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ImageAspect.Metadata); MediaItemAspect thumbnailSmallAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ThumbnailSmallAspect.Metadata); MediaItemAspect thumbnailLargeAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ThumbnailLargeAspect.Metadata); try { // Open a stream for media item to detect mimeType. using (Stream mediaStream = mediaItemAccessor.OpenRead()) { string mimeType = MimeTypeDetector.GetMimeType(mediaStream); if (mimeType != null) { mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, mimeType); } } // Extract EXIF information from media item. using (ExifMetaInfo.ExifMetaInfo exif = new ExifMetaInfo.ExifMetaInfo(mediaItemAccessor)) { mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, ProviderPathHelper.GetFileNameWithoutExtension(fileName)); mediaAspect.SetAttribute(MediaAspect.ATTR_RECORDINGTIME, exif.OriginalDate != DateTime.MinValue ? exif.OriginalDate : mediaItemAccessor.LastChanged); mediaAspect.SetAttribute(MediaAspect.ATTR_COMMENT, StringUtils.TrimToNull(exif.ImageDescription)); imageAspect.SetAttribute(ImageAspect.ATTR_WIDTH, (int)exif.PixXDim); imageAspect.SetAttribute(ImageAspect.ATTR_HEIGHT, (int)exif.PixYDim); imageAspect.SetAttribute(ImageAspect.ATTR_MAKE, StringUtils.TrimToNull(exif.EquipMake)); imageAspect.SetAttribute(ImageAspect.ATTR_MODEL, StringUtils.TrimToNull(exif.EquipModel)); imageAspect.SetAttribute(ImageAspect.ATTR_EXPOSURE_BIAS, ((double)exif.ExposureBias).ToString()); imageAspect.SetAttribute(ImageAspect.ATTR_EXPOSURE_TIME, exif.ExposureTime.ToString()); imageAspect.SetAttribute(ImageAspect.ATTR_FLASH_MODE, StringUtils.TrimToNull(exif.FlashMode)); imageAspect.SetAttribute(ImageAspect.ATTR_FNUMBER, string.Format("F {0}", (double)exif.FNumber)); imageAspect.SetAttribute(ImageAspect.ATTR_ISO_SPEED, StringUtils.TrimToNull(exif.ISOSpeed)); imageAspect.SetAttribute(ImageAspect.ATTR_ORIENTATION, (Int32)exif.Orientation); imageAspect.SetAttribute(ImageAspect.ATTR_METERING_MODE, exif.MeteringMode.ToString()); IResourceAccessor ra = mediaItemAccessor.Clone(); ILocalFsResourceAccessor lfsra; try { lfsra = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra); } catch { ra.Dispose(); throw; } using (lfsra) { string localFsResourcePath = lfsra.LocalFileSystemPath; if (localFsResourcePath != null) { // In quick mode only allow thumbs taken from cache. bool cachedOnly = forceQuickMode; // Thumbnail extraction IThumbnailGenerator generator = ServiceRegistration.Get <IThumbnailGenerator>(); byte[] thumbData; ImageType imageType; if (generator.GetThumbnail(localFsResourcePath, 96, 96, cachedOnly, out thumbData, out imageType)) { thumbnailSmallAspect.SetAttribute(ThumbnailSmallAspect.ATTR_THUMBNAIL, thumbData); } if (generator.GetThumbnail(localFsResourcePath, 256, 256, cachedOnly, out thumbData, out imageType)) { thumbnailLargeAspect.SetAttribute(ThumbnailLargeAspect.ATTR_THUMBNAIL, thumbData); } } } } return(true); } catch (Exception e) { // Only log at the info level here - And simply return false. This makes the importer know that we // couldn't perform our task here. ServiceRegistration.Get <ILogger>().Info("ImageMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message); } return(false); }
public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary <Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode) { try { VideoResult result = null; IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor; if (fsra != null && fsra.IsDirectory && fsra.ResourceExists("VIDEO_TS")) { IFileSystemResourceAccessor fsraVideoTs = fsra.GetResource("VIDEO_TS"); if (fsraVideoTs != null && fsraVideoTs.ResourceExists("VIDEO_TS.IFO")) { // Video DVD using (MediaInfoWrapper videoTsInfo = ReadMediaInfo(fsraVideoTs.GetResource("VIDEO_TS.IFO"))) { if (!videoTsInfo.IsValid || videoTsInfo.GetVideoCount() == 0) { return(false); // Invalid video_ts.ifo file } result = VideoResult.CreateDVDInfo(fsra.ResourceName, videoTsInfo); } // Iterate over all video files; MediaInfo finds different audio/video metadata for each .ifo file ICollection <IFileSystemResourceAccessor> files = fsraVideoTs.GetFiles(); if (files != null) { foreach (IFileSystemResourceAccessor file in files) { string lowerPath = (file.ResourcePathName ?? string.Empty).ToLowerInvariant(); if (!lowerPath.EndsWith(".ifo") || lowerPath.EndsWith("video_ts.ifo")) { continue; } using (MediaInfoWrapper mediaInfo = ReadMediaInfo(file)) { // Before we start evaluating the file, check if it is a video at all if (mediaInfo.IsValid && mediaInfo.GetVideoCount() == 0) { continue; } result.AddMediaInfo(mediaInfo); } } } } } else if (mediaItemAccessor.IsFile) { string filePath = mediaItemAccessor.ResourcePathName; if (!HasVideoExtension(filePath)) { return(false); } using (MediaInfoWrapper fileInfo = ReadMediaInfo(mediaItemAccessor)) { // Before we start evaluating the file, check if it is a video at all if (!fileInfo.IsValid || (fileInfo.GetVideoCount() == 0 && !IsWorkaroundRequired(filePath))) { return(false); } string mediaTitle = DosPathHelper.GetFileNameWithoutExtension(mediaItemAccessor.ResourceName); result = VideoResult.CreateFileInfo(mediaTitle, fileInfo); } using (Stream stream = mediaItemAccessor.OpenRead()) result.MimeType = MimeTypeDetector.GetMimeType(stream); } if (result != null) { result.UpdateMetadata(extractedAspectData); ILocalFsResourceAccessor disposeLfsra = null; try { ILocalFsResourceAccessor lfsra = mediaItemAccessor as ILocalFsResourceAccessor; if (lfsra == null && !forceQuickMode) { // In case forceQuickMode, we only want local browsing IResourceAccessor ra = mediaItemAccessor.Clone(); try { lfsra = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra); disposeLfsra = lfsra; // Remember to dispose the extra resource accessor instance } catch (Exception) { ra.Dispose(); } } if (lfsra != null) { string localFsPath = lfsra.LocalFileSystemPath; ExtractMatroskaTags(localFsPath, extractedAspectData, forceQuickMode); ExtractThumbnailData(localFsPath, extractedAspectData, forceQuickMode); } } finally { if (disposeLfsra != null) { disposeLfsra.Dispose(); } } return(true); } } catch (Exception e) { // Only log at the info level here - And simply return false. This lets the caller know that we // couldn't perform our task here. ServiceRegistration.Get <ILogger>().Info("VideoMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message); } return(false); }
public bool IsResource(IResourceAccessor baseResourceAccessor, string path) { string resourceName = baseResourceAccessor.ResourceName; if (string.IsNullOrEmpty(resourceName) || !baseResourceAccessor.IsFile) return false; // Test if we have already an ISO proxy for that ISO file... lock (_syncObj) { string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { IsoResourceProxy proxy; if (_isoUsages.TryGetValue(key, out proxy)) return IsoResourceAccessor.IsResource(proxy.DiskFileSystem, path); } catch (Exception) { return false; } } // ... if not, test the resource in a new disk file system instance using (Stream underlayingStream = baseResourceAccessor.OpenRead()) { try { IFileSystem diskFileSystem = IsoResourceProxy.GetFileSystem(underlayingStream); using (diskFileSystem as IDisposable) return IsoResourceAccessor.IsResource(diskFileSystem, path); } catch { return false; } } }
public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary<Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode) { try { VideoResult result = null; IFileSystemResourceAccessor fsra = mediaItemAccessor as IFileSystemResourceAccessor; if (fsra != null && fsra.IsDirectory && fsra.ResourceExists("VIDEO_TS")) { IFileSystemResourceAccessor fsraVideoTs = fsra.GetResource("VIDEO_TS"); if (fsraVideoTs != null && fsraVideoTs.ResourceExists("VIDEO_TS.IFO")) { // Video DVD using (MediaInfoWrapper videoTsInfo = ReadMediaInfo(fsraVideoTs.GetResource("VIDEO_TS.IFO"))) { if (!videoTsInfo.IsValid || videoTsInfo.GetVideoCount() == 0) return false; // Invalid video_ts.ifo file result = VideoResult.CreateDVDInfo(fsra.ResourceName, videoTsInfo); } // Iterate over all video files; MediaInfo finds different audio/video metadata for each .ifo file ICollection<IFileSystemResourceAccessor> files = fsraVideoTs.GetFiles(); if (files != null) foreach (IFileSystemResourceAccessor file in files) { string lowerPath = (file.ResourcePathName ?? string.Empty).ToLowerInvariant(); if (!lowerPath.EndsWith(".ifo") || lowerPath.EndsWith("video_ts.ifo")) continue; using (MediaInfoWrapper mediaInfo = ReadMediaInfo(file)) { // Before we start evaluating the file, check if it is a video at all if (mediaInfo.IsValid && mediaInfo.GetVideoCount() == 0) continue; result.AddMediaInfo(mediaInfo); } } } } else if (mediaItemAccessor.IsFile) { string filePath = mediaItemAccessor.ResourcePathName; if (!HasVideoExtension(filePath)) return false; using (MediaInfoWrapper fileInfo = ReadMediaInfo(mediaItemAccessor)) { // Before we start evaluating the file, check if it is a video at all if (!fileInfo.IsValid || (fileInfo.GetVideoCount() == 0 && !IsWorkaroundRequired(filePath))) return false; string mediaTitle = DosPathHelper.GetFileNameWithoutExtension(mediaItemAccessor.ResourceName); result = VideoResult.CreateFileInfo(mediaTitle, fileInfo); } using (Stream stream = mediaItemAccessor.OpenRead()) result.MimeType = MimeTypeDetector.GetMimeType(stream); } if (result != null) { result.UpdateMetadata(extractedAspectData); ILocalFsResourceAccessor disposeLfsra = null; try { ILocalFsResourceAccessor lfsra = mediaItemAccessor as ILocalFsResourceAccessor; if (lfsra == null && !forceQuickMode) { // In case forceQuickMode, we only want local browsing IResourceAccessor ra = mediaItemAccessor.Clone(); try { lfsra = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra); disposeLfsra = lfsra; // Remember to dispose the extra resource accessor instance } catch (Exception) { ra.Dispose(); } } if (lfsra != null) { string localFsPath = lfsra.LocalFileSystemPath; ExtractMatroskaTags(localFsPath, extractedAspectData, forceQuickMode); ExtractThumbnailData(localFsPath, extractedAspectData, forceQuickMode); } } finally { if (disposeLfsra != null) disposeLfsra.Dispose(); } return true; } } catch (Exception e) { // Only log at the info level here - And simply return false. This lets the caller know that we // couldn't perform our task here. ServiceRegistration.Get<ILogger>().Info("VideoMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message); } return false; }
protected MediaInfoWrapper ReadMediaInfo(IResourceAccessor mediaItemAccessor) { MediaInfoWrapper result = new MediaInfoWrapper(); Stream stream = null; try { stream = mediaItemAccessor.OpenRead(); if (stream != null) result.Open(stream); } finally { if (stream != null) stream.Close(); } return result; }
private void ReadMetaInfo(IResourceAccessor mediaItemAccessor) { using (Stream mediaStream = mediaItemAccessor.OpenRead()) ReadMetaInfo(mediaStream); }
public bool TryExtractMetadata(IResourceAccessor mediaItemAccessor, IDictionary<Guid, MediaItemAspect> extractedAspectData, bool forceQuickMode) { string fileName = mediaItemAccessor.ResourceName; if (!HasImageExtension(fileName)) return false; MediaItemAspect mediaAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, MediaAspect.Metadata); MediaItemAspect imageAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ImageAspect.Metadata); MediaItemAspect thumbnailSmallAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ThumbnailSmallAspect.Metadata); MediaItemAspect thumbnailLargeAspect = MediaItemAspect.GetOrCreateAspect(extractedAspectData, ThumbnailLargeAspect.Metadata); try { // Open a stream for media item to detect mimeType. using (Stream mediaStream = mediaItemAccessor.OpenRead()) { string mimeType = MimeTypeDetector.GetMimeType(mediaStream); if (mimeType != null) mediaAspect.SetAttribute(MediaAspect.ATTR_MIME_TYPE, mimeType); } // Extract EXIF information from media item. using (ExifMetaInfo.ExifMetaInfo exif = new ExifMetaInfo.ExifMetaInfo(mediaItemAccessor)) { mediaAspect.SetAttribute(MediaAspect.ATTR_TITLE, ProviderPathHelper.GetFileNameWithoutExtension(fileName)); mediaAspect.SetAttribute(MediaAspect.ATTR_RECORDINGTIME, exif.OriginalDate != DateTime.MinValue ? exif.OriginalDate : mediaItemAccessor.LastChanged); mediaAspect.SetAttribute(MediaAspect.ATTR_COMMENT, StringUtils.TrimToNull(exif.ImageDescription)); imageAspect.SetAttribute(ImageAspect.ATTR_WIDTH, (int) exif.PixXDim); imageAspect.SetAttribute(ImageAspect.ATTR_HEIGHT, (int) exif.PixYDim); imageAspect.SetAttribute(ImageAspect.ATTR_MAKE, StringUtils.TrimToNull(exif.EquipMake)); imageAspect.SetAttribute(ImageAspect.ATTR_MODEL, StringUtils.TrimToNull(exif.EquipModel)); imageAspect.SetAttribute(ImageAspect.ATTR_EXPOSURE_BIAS, ((double) exif.ExposureBias).ToString()); imageAspect.SetAttribute(ImageAspect.ATTR_EXPOSURE_TIME, exif.ExposureTime.ToString()); imageAspect.SetAttribute(ImageAspect.ATTR_FLASH_MODE, StringUtils.TrimToNull(exif.FlashMode)); imageAspect.SetAttribute(ImageAspect.ATTR_FNUMBER, string.Format("F {0}", (double) exif.FNumber)); imageAspect.SetAttribute(ImageAspect.ATTR_ISO_SPEED, StringUtils.TrimToNull(exif.ISOSpeed)); imageAspect.SetAttribute(ImageAspect.ATTR_ORIENTATION, (Int32) exif.Orientation); imageAspect.SetAttribute(ImageAspect.ATTR_METERING_MODE, exif.MeteringMode.ToString()); IResourceAccessor ra = mediaItemAccessor.Clone(); ILocalFsResourceAccessor lfsra; try { lfsra = StreamedResourceToLocalFsAccessBridge.GetLocalFsResourceAccessor(ra); } catch { ra.Dispose(); throw; } using (lfsra) { string localFsResourcePath = lfsra.LocalFileSystemPath; if (localFsResourcePath != null) { // In quick mode only allow thumbs taken from cache. bool cachedOnly = forceQuickMode; // Thumbnail extraction IThumbnailGenerator generator = ServiceRegistration.Get<IThumbnailGenerator>(); byte[] thumbData; ImageType imageType; if (generator.GetThumbnail(localFsResourcePath, 96, 96, cachedOnly, out thumbData, out imageType)) thumbnailSmallAspect.SetAttribute(ThumbnailSmallAspect.ATTR_THUMBNAIL, thumbData); if (generator.GetThumbnail(localFsResourcePath, 256, 256, cachedOnly, out thumbData, out imageType)) thumbnailLargeAspect.SetAttribute(ThumbnailLargeAspect.ATTR_THUMBNAIL, thumbData); } } } return true; } catch (Exception e) { // Only log at the info level here - And simply return false. This makes the importer know that we // couldn't perform our task here. ServiceRegistration.Get<ILogger>().Info("ImageMetadataExtractor: Exception reading resource '{0}' (Text: '{1}')", mediaItemAccessor.CanonicalLocalResourcePath, e.Message); } return false; }
public bool IsResource(IResourceAccessor baseResourceAccessor, string path) { string entryPath = ZipResourceAccessor.ToEntryPath(path); lock (_syncObj) { string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { ZipResourceProxy proxy; if (_zipUsages.TryGetValue(key, out proxy)) return path.Equals("/") || ZipResourceAccessor.IsResource(proxy.ZipFile, entryPath); } catch (Exception) { return false; } } using (Stream resourceStream = baseResourceAccessor.OpenRead()) // Not sure if the ZipFile will close the stream so we dispose it here try { using (ZipFile zFile = new ZipFile(resourceStream)) return path.Equals("/") || ZipResourceAccessor.IsResource(zFile, entryPath); } catch (Exception) { return false; } }