本文整理汇总了C#中ResourcePath.TryCreateLocalResourceAccessor方法的典型用法代码示例。如果您正苦于以下问题:C# ResourcePath.TryCreateLocalResourceAccessor方法的具体用法?C# ResourcePath.TryCreateLocalResourceAccessor怎么用?C# ResourcePath.TryCreateLocalResourceAccessor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourcePath
的用法示例。
在下文中一共展示了ResourcePath.TryCreateLocalResourceAccessor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetChildDirectoriesData
protected override IEnumerable<ResourcePathMetadata> GetChildDirectoriesData(ResourcePath path)
{
IResourceAccessor ra;
if (path.TryCreateLocalResourceAccessor(out ra))
{
using (ra)
{
IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;
if (fsra == null)
yield break;
ICollection<IFileSystemResourceAccessor> res = FileSystemResourceNavigator.GetChildDirectories(fsra, false);
if (res != null)
foreach (IFileSystemResourceAccessor childAccessor in res)
using (childAccessor)
{
yield return new ResourcePathMetadata
{
ResourceName = childAccessor.ResourceName,
HumanReadablePath = childAccessor.ResourcePathName,
ResourcePath = childAccessor.CanonicalLocalResourcePath
};
}
}
}
else
ServiceRegistration.Get<ILogger>().Warn("LocalShares: Cannot access resource path '{0}' for getting child directories", path);
}
示例2: GetLocalResourcePathDisplayName
public static string GetLocalResourcePathDisplayName(ResourcePath path)
{
if (path == null)
return string.Empty;
IResourceAccessor ra;
if (path.TryCreateLocalResourceAccessor(out ra))
using (ra)
return ra.ResourcePathName;
ServiceRegistration.Get<ILogger>().Warn("LocalShares: Cannot access resource path '{0}' for updating display name", path);
return string.Empty;
}
示例3: GetResourceAccessor
protected IResourceAccessor GetResourceAccessor(ResourcePath resourcePath)
{
lock (_syncObj)
{
CachedResource resource;
string resourcePathStr = resourcePath.Serialize();
if (_resourceAccessorCache.TryGetValue(resourcePathStr, out resource))
return resource.ResourceAccessor;
// TODO: Security check. Only deliver resources which are located inside local shares.
ServiceRegistration.Get<ILogger>().Debug("ResourceAccessModule: Access of resource '{0}'", resourcePathStr);
IResourceAccessor result;
if(!resourcePath.TryCreateLocalResourceAccessor(out result))
ServiceRegistration.Get<ILogger>().Debug("ResourceAccessModule: Unable to access resource path '{0}'", resourcePathStr);
_resourceAccessorCache[resourcePathStr] = new CachedResource(result);
return result;
}
}
示例4: GetFilesData
protected IEnumerable<ResourcePathMetadata> GetFilesData(ResourcePath path)
{
IResourceAccessor ra;
if (path.TryCreateLocalResourceAccessor(out ra))
{
using (ra)
{
ICollection<IFileSystemResourceAccessor> res = FileSystemResourceNavigator.GetFiles(ra, ShowSystemResources);
if (res != null)
foreach (IFileSystemResourceAccessor fileAccessor in res)
using(fileAccessor)
{
yield return new ResourcePathMetadata
{
ResourceName = fileAccessor.ResourceName,
HumanReadablePath = fileAccessor.ResourcePathName,
ResourcePath = fileAccessor.CanonicalLocalResourcePath
};
}
}
}
else
{
ServiceRegistration.Get<ILogger>().Warn("FileBrowserModel: Cannot access resource path '{0}' for getting files", path);
yield break;
}
}
示例5: GetResourceAccessor
protected IFileSystemResourceAccessor GetResourceAccessor(ResourcePath resourcePath)
{
lock (_syncObj)
{
CachedResource resource;
string resourcePathStr = resourcePath.Serialize();
if (_resourceAccessorCache.TryGetValue(resourcePathStr, out resource))
return resource.ResourceAccessor;
// TODO: Security check. Only deliver resources which are located inside local shares.
ServiceRegistration.Get<ILogger>().Debug("ResourceAccessModule: Access of resource '{0}'", resourcePathStr);
IResourceAccessor ra;
if (!resourcePath.TryCreateLocalResourceAccessor(out ra))
throw new ArgumentException("Unable to access resource path '{0}'", resourcePathStr);
IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;
if (fsra == null)
{
ra.Dispose();
throw new ArgumentException("The given resource path '{0}' doesn't denote a file system resource", resourcePathStr);
}
_resourceAccessorCache[resourcePathStr] = new CachedResource(fsra);
return fsra;
}
}