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


C# IResourceLoader.DownloadAsync方法代码示例

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


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

示例1: LoadAsync

        public override Task LoadAsync(IConfiguration configuration, IResourceLoader loader)
        {
            var link = Link;
            var request = link.CreateRequestFor(Url);
            var download = loader.DownloadAsync(request);
            SetDownload(download);

            return link.ProcessResponse(download, response =>
            {
                var type = link.Type ?? MimeTypeNames.Css;
                var engine = configuration.GetStyleEngine(type);

                if (engine != null)
                {
                    var options = new StyleOptions
                    {
                        Element = link,
                        IsDisabled = link.IsDisabled,
                        IsAlternate = link.RelationList.Contains(Keywords.Alternate),
                        Configuration = configuration
                    };

                    _sheet = engine.ParseStylesheet(response, options);
                    _sheet.Media.MediaText = link.Media ?? String.Empty;
                }
            });
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:27,代码来源:StyleSheetLinkRelation.cs

示例2: LoadAsync

        /// <summary>
        /// See http://www.w3.org/TR/html-imports/#dfn-import-request.
        /// </summary>
        public override async Task LoadAsync(IConfiguration configuration, IResourceLoader loader)
        {
            var link = Link;
            var document = link.Owner;
            var list = ImportLists.GetOrCreateValue(document);
            var location = Url;
            var request = link.CreateRequestFor(location);
            var item = new ImportEntry 
            { 
                Relation = this,
                IsCycle = CheckCycle(document, location)
            };
            _isasync = link.HasAttribute(AttributeNames.Async);
            list.Add(item);
            
            if (!item.IsCycle)
            {
                var nestedStatus = new TaskCompletionSource<Boolean>();
                var download = loader.DownloadAsync(request);
                SetDownload(download);

                await link.ProcessResponse(download, async response =>
                {
                    var context = new BrowsingContext(document.Context, Sandboxes.None);
                    var options = new CreateDocumentOptions(response, configuration)
                    {
                        ImportAncestor = document
                    };
                    _import = await context.OpenAsync(options, CancellationToken.None).ConfigureAwait(false);
                    nestedStatus.SetResult(true);
                }).ConfigureAwait(false);
                await nestedStatus.Task.ConfigureAwait(false);
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:37,代码来源:ImportLinkRelation.cs


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