本文整理汇总了C#中IFileSystemResourceAccessor类的典型用法代码示例。如果您正苦于以下问题:C# IFileSystemResourceAccessor类的具体用法?C# IFileSystemResourceAccessor怎么用?C# IFileSystemResourceAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IFileSystemResourceAccessor类属于命名空间,在下文中一共展示了IFileSystemResourceAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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(IFileSystemResourceAccessor resourceAccessor, RightAngledRotation rotation)
{
_key = resourceAccessor.CanonicalLocalResourcePath.Serialize();
_resourceAccessor = resourceAccessor;
_stream = _resourceAccessor.OpenRead();
_rotation = rotation;
}
示例2: Create
/// <summary>
/// Creates and initializes an new instance.
/// </summary>
/// <param name="resourceAccessor">The resource accessor to the media item to be handled by the instance.</param>
/// <returns>The new instance.</returns>
public static BassMODFileInputSource Create(IFileSystemResourceAccessor resourceAccessor)
{
resourceAccessor.PrepareStreamAccess();
BassMODFileInputSource inputSource = new BassMODFileInputSource(resourceAccessor);
inputSource.Initialize();
return inputSource;
}
示例3: MountingDataProxy
/// <summary>
/// Creates a new instance of this class which is based on the given <paramref name="baseAccessor"/>.
/// </summary>
/// <param name="key">Key which is used for this instance.</param>
/// <param name="baseAccessor">Filesystem resource to mound.</param>
public MountingDataProxy(string key, IFileSystemResourceAccessor baseAccessor)
{
_key = key;
_baseAccessor = baseAccessor;
if (!MountResource())
throw new EnvironmentException("Cannot mount resource '{0}' to local file system", baseAccessor);
}
示例4: TryMatchImdbId
/// <summary>
/// Tries to read a valid IMDB id from additional .nfo or .txt files.
/// </summary>
/// <param name="fsra">FileSystemResourceAccessor</param>
/// <param name="imdbId">Returns a valid IMDB or <c>null</c></param>
/// <returns>true if matched</returns>
public static bool TryMatchImdbId(IFileSystemResourceAccessor fsra, out string imdbId)
{
imdbId = null;
if (fsra == null)
return false;
// First try to find a nfo file that has the same name as our main movie.
if (fsra.IsFile)
foreach (string extension in NFO_EXTENSIONS)
{
string metaFilePath = ResourcePathHelper.ChangeExtension(fsra.CanonicalLocalResourcePath.ToString(), extension);
if (TryRead(metaFilePath, out imdbId))
return true;
}
// Prepare a list of paths to check: for chained resource path we will also check relative parent paths (like for DVD-ISO files)
List<string> pathsToCheck = new List<string> { fsra.CanonicalLocalResourcePath.ToString() };
if (fsra.CanonicalLocalResourcePath.PathSegments.Count > 1)
{
string canocialPath = fsra.CanonicalLocalResourcePath.ToString();
pathsToCheck.Add(canocialPath.Substring(0, canocialPath.LastIndexOf('>')));
}
// Then test for special named files, like "movie.nfo"
foreach (string path in pathsToCheck)
foreach (string fileName in NFO_FILENAMES)
{
string metaFilePath = ResourcePathHelper.GetDirectoryName(path);
metaFilePath = ResourcePathHelper.Combine(metaFilePath, fileName);
if (TryRead(metaFilePath, out imdbId))
return true;
}
// Now check siblings of movie for any IMDB id containing filename.
// Morpheus_xx, 2014-01-04: disabled code because it leads to false detections if there are multiple video files in same folder. In this case the first
// video with TT-number is wrongly used.
// TODO: this part could be reworked based on different ideas:
// - Exclude known video extensions from file name matching (this would require a reference to VideoMDE's settings for extension list)
// - Only use folder lookup for chained resources, i.e. for a DVD-ISO, where any "TT000000.bla" is located next to it
//IFileSystemResourceAccessor directoryFsra = null;
//if (!fsra.IsFile)
// directoryFsra = fsra.Clone() as IFileSystemResourceAccessor;
//if (fsra.IsFile)
// directoryFsra = GetContainingDirectory(fsra);
//if (directoryFsra == null)
// return false;
//using (directoryFsra)
// foreach (IFileSystemResourceAccessor file in directoryFsra.GetFiles())
// using (file)
// if (ImdbIdMatcher.TryMatchImdbId(file.ResourceName, out imdbId))
// return true;
return false;
}
示例5: TryMatchImdbId
/// <summary>
/// Tries to read a valid IMDB id from additional .nfo or .txt files.
/// </summary>
/// <param name="fsra">FileSystemResourceAccessor</param>
/// <param name="imdbId">Returns a valid IMDB or <c>null</c></param>
/// <returns>true if matched</returns>
public static bool TryMatchImdbId(IFileSystemResourceAccessor fsra, out string imdbId)
{
imdbId = null;
if (fsra == null)
return false;
// First try to find a nfo file that has the same name as our main movie.
if (fsra.IsFile)
foreach (string extension in NFO_EXTENSIONS)
{
string metaFilePath = ResourcePathHelper.ChangeExtension(fsra.CanonicalLocalResourcePath.ToString(), extension);
if (TryRead(metaFilePath, out imdbId))
return true;
}
// Prepare a list of paths to check: for chained resource path we will also check relative parent paths (like for DVD-ISO files)
List<string> pathsToCheck = new List<string> { fsra.CanonicalLocalResourcePath.ToString() };
if (fsra.CanonicalLocalResourcePath.PathSegments.Count > 1)
{
string canocialPath = fsra.CanonicalLocalResourcePath.ToString();
pathsToCheck.Add(canocialPath.Substring(0, canocialPath.LastIndexOf('>')));
}
// Then test for special named files, like "movie.nfo"
foreach (string path in pathsToCheck)
foreach (string fileName in NFO_FILENAMES)
{
string metaFilePath = ResourcePathHelper.GetDirectoryName(path);
metaFilePath = ResourcePathHelper.Combine(metaFilePath, fileName);
if (TryRead(metaFilePath, out imdbId))
return true;
}
// Now check siblings of movie for any IMDB id containing filename.
IFileSystemResourceAccessor directoryFsra = null;
if (!fsra.IsFile)
directoryFsra = fsra.Clone() as IFileSystemResourceAccessor;
if (fsra.IsFile)
directoryFsra = GetContainingDirectory(fsra);
if (directoryFsra == null)
return false;
using (directoryFsra)
foreach (IFileSystemResourceAccessor file in directoryFsra.GetFiles())
using (file)
if (ImdbIdMatcher.TryMatchImdbId(file.ResourceName, out imdbId))
return true;
return false;
}
示例6: PendingImportResourceNewGen
private DateTime _dateOfLastImport; // only valid for refresh imports
#endregion
#region Constructor
public PendingImportResourceNewGen(ResourcePath parentDirectory, IFileSystemResourceAccessor resourceAccessor, String currentBlock, ImportJobController parentImportJobController, Guid? parentDirectoryId = null, Guid? mediaItemId = null)
{
_parentDirectoryId = parentDirectoryId;
_mediaItemId = mediaItemId;
_parentDirectoryResourcePathString = (parentDirectory == null) ? "" : parentDirectory.Serialize();
_resourceAccessor = resourceAccessor;
_currentBlock = currentBlock;
_parentImportJobController = parentImportJobController;
_pendingImportResourceNumber = _parentImportJobController.GetNumberOfNextPendingImportResource();
_isValid = (_resourceAccessor != null);
_parentImportJobController.RegisterPendingImportResource(this);
}
示例7: GetChildDirectories
/// <summary>
/// Returns all child directories of the given directory.
/// </summary>
/// <remarks>
/// This will return all native child directories of the given directory together with all virtual child
/// directories. The native child directories are taken directly from the given <paramref name="directoryAccessor"/>,
/// the virtual child directories are obtained by taking the root directories of each chained resource provider applied
/// to the child files of the given directory.
/// If, for example, the given <paramref name="directoryAccessor"/> contains a child directory "A" and a child
/// archive file "B" which can work as input for an installed archive provider, providing the root directory "C"
/// of that archive, this method will return the resource accessors for directories "A" and "C".
/// </remarks>
/// <param name="directoryAccessor">Directory resource accessor to get all child directories for.</param>
/// <param name="showSystemResources">If set to <c>true</c>, system resources like the virtual drives and directories of the
/// <see cref="IResourceMountingService"/> will also be returned, else removed from the result value.</param>
/// <returns>Collection of directory accessors for all native and virtual child directories or <c>null</c>,
/// if the given <paramref name="directoryAccessor"/> does not point to a directory and
/// if there is no chained resource provider to unfold the given file.</returns>
public static ICollection<IFileSystemResourceAccessor> GetChildDirectories(IFileSystemResourceAccessor directoryAccessor, bool showSystemResources)
{
IResourceMountingService resourceMountingService = ServiceRegistration.Get<IResourceMountingService>();
IFileSystemResourceAccessor chainedResourceAccesor; // Needed in multiple source locations, that's why we declare it here
// If directoryAccessor points to a directory, we return all actual subdirectories and the virtual subdirectories
// we can create by using all available ChainedResourceProviders on all contained files.
if (!directoryAccessor.IsFile)
{
ICollection<IFileSystemResourceAccessor> childDirectories = directoryAccessor.GetChildDirectories();
ICollection<IFileSystemResourceAccessor> result = new List<IFileSystemResourceAccessor>();
if (childDirectories != null)
// Directories are maybe filtered and then just added
foreach (IFileSystemResourceAccessor childDirectoryAccessor in childDirectories)
{
if (!showSystemResources && resourceMountingService.IsVirtualResource(childDirectoryAccessor.CanonicalLocalResourcePath))
{
childDirectoryAccessor.Dispose();
continue;
}
result.Add(childDirectoryAccessor);
}
ICollection<IFileSystemResourceAccessor> files = directoryAccessor.GetFiles();
if (files != null)
// For files, we try to chain up chained resource providers
foreach (IFileSystemResourceAccessor fileAccessor in files)
using (fileAccessor)
{
if (!showSystemResources && resourceMountingService.IsVirtualResource(fileAccessor.CanonicalLocalResourcePath))
continue;
if (TryUnfold(fileAccessor, out chainedResourceAccesor))
if (!chainedResourceAccesor.IsFile)
result.Add(chainedResourceAccesor);
else
chainedResourceAccesor.Dispose();
// Simply ignore files because we only want to return directories
}
return result;
}
// Try to unfold file resource
if (TryUnfold(directoryAccessor, out chainedResourceAccesor))
{
if (!chainedResourceAccesor.IsFile)
return new List<IFileSystemResourceAccessor>(new IFileSystemResourceAccessor[] {chainedResourceAccesor});
chainedResourceAccesor.Dispose();
return new List<IFileSystemResourceAccessor>();
}
return null;
}
示例8: ZipResourceProxy
public ZipResourceProxy(string key, IFileSystemResourceAccessor 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;
}
}
示例9: IsoResourceProxy
public IsoResourceProxy(string key, IFileSystemResourceAccessor isoFileResourceAccessor)
{
_key = key;
_isoFileResourceAccessor = isoFileResourceAccessor;
_underlayingStream = _isoFileResourceAccessor.OpenRead();
try
{
_diskFileSystem = GetFileSystem(_underlayingStream);
}
catch
{
_underlayingStream.Dispose();
throw;
}
}
示例10: ConnectFileSystem
public static bool ConnectFileSystem(string nativeSystemId, ResourcePath nativeResourcePath, out IFileSystemResourceAccessor result)
{
IRemoteResourceInformationService rris = ServiceRegistration.Get<IRemoteResourceInformationService>();
result = null;
bool isFileSystemResource;
bool isFile;
string resourcePathName;
string resourceName;
long size;
DateTime lastChanged;
if (!rris.GetResourceInformation(nativeSystemId, nativeResourcePath, out isFileSystemResource, out isFile,
out resourcePathName, out resourceName, out lastChanged, out size) || !isFileSystemResource)
return false;
result = new RemoteFileSystemResourceAccessor(nativeSystemId, nativeResourcePath, isFile,
resourcePathName, resourceName, size, lastChanged);
return true;
}
示例11: VirtualFileSystemResource
protected VirtualFileSystemResource(string name, IFileSystemResourceAccessor resourceAccessor)
{
_name = name;
_resourceAccessor = resourceAccessor;
_creationTime = DateTime.Now;
}
示例12: GetLocalFsResourceAccessor
/// <summary>
/// Returns a resource accessor instance of interface <see cref="ILocalFsResourceAccessor"/>. This instance will return the
/// given <paramref name="baseResourceAccessor"/>, casted to <see cref="ILocalFsResourceAccessor"/> if possible, or
/// a new instance of <see cref="StreamedResourceToLocalFsAccessBridge"/> to provide the <see cref="ILocalFsResourceAccessor"/>
/// instance.
/// </summary>
/// <remarks>
/// The ownership of the given <paramref name="baseResourceAccessor"/> is transferred from the caller to the returned
/// result value. That means, if this method succeeds, the caller must dispose the result value, it must not dispose
/// the given <paramref name="baseResourceAccessor"/> any more.
/// </remarks>
/// <param name="baseResourceAccessor">Resource accessor which is used to provide the resource contents.</param>
/// <param name="path">Relative path based on the given baseResourceAccessor.</param>
/// <returns>Resource accessor which implements <see cref="ILocalFsResourceAccessor"/>.</returns>
public static ILocalFsResourceAccessor GetLocalFsResourceAccessor(IFileSystemResourceAccessor baseResourceAccessor, string path)
{
// Try to get an ILocalFsResourceAccessor
ILocalFsResourceAccessor result = baseResourceAccessor as ILocalFsResourceAccessor;
if (result != null)
// Simple case: The media item is located in the local file system or the resource provider returns
// an ILocalFsResourceAccessor from elsewhere - simply return it
return result;
// Set up a resource bridge mapping the remote or complex resource to a local file or directory
string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize();
MountingDataProxy md;
bool dispose = false;
lock (_syncObj)
{
if (_activeMounts.TryGetValue(key, out md))
// Base accessor not needed - we use our cached accessor
dispose = true;
else
_activeMounts.Add(key, md = CreateMountingDataProxy(key, baseResourceAccessor));
}
if (dispose)
baseResourceAccessor.Dispose();
return new StreamedResourceToLocalFsAccessBridge(md, path);
}
示例13: NavigateCreateViewSpecification
protected override ViewSpecification NavigateCreateViewSpecification(string systemId, IFileSystemResourceAccessor viewRA)
{
IServerConnectionManager serverConnectionManager = ServiceRegistration.Get<IServerConnectionManager>();
IContentDirectory cd = serverConnectionManager.ContentDirectory;
if (cd == null)
return null;
ResourcePath directoryPath = viewRA.CanonicalLocalResourcePath;
MediaItem directoryItem = cd.LoadItem(systemId, directoryPath,
SystemSharesViewSpecification.DIRECTORY_MIA_ID_ENUMERATION, SystemSharesViewSpecification.EMPTY_ID_ENUMERATION);
if (directoryItem == null)
return null;
return new MediaLibraryBrowseViewSpecification(viewRA.ResourceName, directoryItem.MediaItemId, systemId,
directoryPath, _necessaryMIATypeIds, _optionalMIATypeIds);
}
示例14: TryUnfold
/// <summary>
/// Tries to unfold the given <paramref name="fileAccessor"/> to a virtual directory.
/// </summary>
/// <param name="fileAccessor">File resource accessor to be used as input for a potential chained provider.
/// The ownership of this resource accessor remains at the caller.</param>
/// <param name="resultResourceAccessor">Chained resource accessor which was chained upon the given file resource.</param>
public static bool TryUnfold(IFileSystemResourceAccessor fileAccessor, out IFileSystemResourceAccessor resultResourceAccessor)
{
IMediaAccessor mediaAccessor = ServiceRegistration.Get<IMediaAccessor>();
foreach (IChainedResourceProvider cmp in mediaAccessor.LocalChainedResourceProviders)
if (cmp.TryChainUp(fileAccessor, "/", out resultResourceAccessor))
return true;
resultResourceAccessor = null;
return false;
}
示例15: AddLocalMediaItemsRecursive
/// <summary>
/// Adds all media items which are found in the directory to the given <paramref name="directoryRA"/> or in any sub directory to
/// the <paramref name="mediaItems"/> collection.
/// </summary>
/// <param name="directoryRA">Directory resource to be recursively examined.</param>
/// <param name="mediaItems">Collection where the found media items are added.</param>
/// <param name="metadataExtractorIds">Ids of the metadata extractors to be applied to the resources.
/// See <see cref="IMediaAccessor.LocalMetadataExtractors"/>.</param>
/// <param name="mediaAccessor">The media accessor of the system.</param>
public static void AddLocalMediaItemsRecursive(IFileSystemResourceAccessor directoryRA, ICollection<MediaItem> mediaItems,
IEnumerable<Guid> metadataExtractorIds, IMediaAccessor mediaAccessor)
{
ICollection<IFileSystemResourceAccessor> directoryRAs = FileSystemResourceNavigator.GetChildDirectories(directoryRA, false);
if (directoryRAs != null)
foreach (IFileSystemResourceAccessor subDirectoryRA in directoryRAs)
using (subDirectoryRA)
AddLocalMediaItemsRecursive(subDirectoryRA, mediaItems, metadataExtractorIds, mediaAccessor);
ICollection<IFileSystemResourceAccessor> fileRAs = FileSystemResourceNavigator.GetFiles(directoryRA, false);
if (fileRAs != null)
foreach (IFileSystemResourceAccessor fileRA in fileRAs)
using (fileRA)
{
MediaItem item = mediaAccessor.CreateLocalMediaItem(fileRA, metadataExtractorIds);
if (item != null)
mediaItems.Add(item);
}
}