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


C# WebMediaType.ToProviderType方法代码示例

本文整理汇总了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)
            };
        }
开发者ID:cpriebe,项目名称:MPExtended,代码行数:56,代码来源:MediaAccessService.cs


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