本文整理汇总了C#中WebMediaType.ToProviderType方法的典型用法代码示例。如果您正苦于以下问题:C# WebMediaType.ToProviderType方法的具体用法?C# WebMediaType.ToProviderType怎么用?C# WebMediaType.ToProviderType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebMediaType
的用法示例。
在下文中一共展示了WebMediaType.ToProviderType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileInfo
public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset)
{
string path = "";
try
{
path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset);
WebFileInfo retVal = null;
bool tryImpersonation = false;
try
{
// first try it the usual way
retVal = GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype);
tryImpersonation = retVal == null || !retVal.Exists;
}
catch (UnauthorizedAccessException)
{
// access denied, try impersonation
tryImpersonation = true;
}
if (tryImpersonation && new Uri(path).IsUnc && !FileUtil.IsAccessible(path))
{
using (var impersonator = new NetworkShareImpersonator())
{
retVal = new WebFileInfo(path);
retVal.IsLocalFile = Configuration.Services.NetworkImpersonation.ReadInStreamingService;
retVal.OnNetworkDrive = true;
}
}
// Make sure to always the path property, even if the file doesn't exist. This makes debugging a lot easier, as you get actual paths in your logs now.
retVal.Path = PathUtil.StripFileProtocolPrefix(path);
retVal.PID = ProviderHandler.GetProviderId(mediatype.ToProviderType(), provider);
return retVal;
}
catch (ArgumentOutOfRangeException)
{
Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset);
}
catch (FileNotFoundException)
{
Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider);
}
catch (Exception ex)
{
Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex);
}
return new WebFileInfo()
{
Exists = false,
PID = ProviderHandler.GetProviderId(mediatype.ToProviderType(), provider),
Path = String.IsNullOrWhiteSpace(path) ? null : PathUtil.StripFileProtocolPrefix(path)
};
}