当前位置: 首页>>代码示例>>C#>>正文


C# IResourceAccessor.OpenRead方法代码示例

本文整理汇总了C#中IResourceAccessor.OpenRead方法的典型用法代码示例。如果您正苦于以下问题:C# IResourceAccessor.OpenRead方法的具体用法?C# IResourceAccessor.OpenRead怎么用?C# IResourceAccessor.OpenRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IResourceAccessor的用法示例。


在下文中一共展示了IResourceAccessor.OpenRead方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResourceAccessorTextureImageSource

 /// <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;
 }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:12,代码来源:ResourceAccessorTextureImageSource.cs

示例2: ZipResourceProxy

 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;
   }
 }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:15,代码来源:ZipResourceProxy.cs

示例3: IsoResourceProxy

    public IsoResourceProxy(string key, IResourceAccessor isoFileResourceAccessor)
    {
      _key = key;
      _isoFileResourceAccessor = isoFileResourceAccessor;

      _underlayingStream = _isoFileResourceAccessor.OpenRead();
      try
      {
        _diskFileSystem = GetFileSystem(_underlayingStream);
      }
      catch
      {
        _underlayingStream.Dispose();
        throw;
      }
    }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:16,代码来源:IsoResourceProxy.cs

示例4: IsResource

    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;
        }
      }
    }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:37,代码来源:IsoResourceProvider.cs

示例5: TryExtractMetadata

    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;
    }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:97,代码来源:VideoMetadataExtractor.cs

示例6: ReadMediaInfo

 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;
 }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:17,代码来源:VideoMetadataExtractor.cs

示例7: TryExtractMetadata

    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;
    }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:79,代码来源:ImageMetadataExtractor.cs

示例8: ReadMetaInfo

 private void ReadMetaInfo(IResourceAccessor mediaItemAccessor)
 {
   using (Stream mediaStream = mediaItemAccessor.OpenRead())
     ReadMetaInfo(mediaStream);
 }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:5,代码来源:ExifMetaInfo.cs

示例9: IsResource

    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;
        }
    }
开发者ID:joconno4,项目名称:MediaPortal-2,代码行数:30,代码来源:ZipResourceProvider.cs


注:本文中的IResourceAccessor.OpenRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。