Beispiel #1
0
        public Func <CancellationToken, Task <List <Uri> > > CreateGetHtmlFunc()
        {
            var reTryFunc = CreateReTryFunc <List <Uri> >();

            var timeOutFunc = CreateTimeOutReTryFunc <List <Uri> >(m_timeSpan, 9);

            var endFunc = CreateHtmlLoadEndFunc();



            return((tokan) =>
            {
                return endFunc((tokan) =>
                {
                    Uri uri = GetUri();

                    Func <CancellationToken, Task <List <Uri> > > func = async(tokan) =>
                    {
                        string html = await m_htmlClient.GetStringAsync(uri, tokan).ConfigureAwait(false);

                        return ParseUris(html);
                    };

                    return reTryFunc((tokan) => timeOutFunc(func, tokan), tokan);
                }, tokan);
            });
        }
        async Task LoadData(ChannelWriter <DateBind> writer, MHttpClient load, Func <Uri> func)
        {
            async Task AddDate(string html)
            {
                foreach (var item in CreateHtmlPageData(html))
                {
                    try
                    {
                        byte[] buffer = await load.GetByteArrayAsync(item.ImgUri, item.Uri, default).ConfigureAwait(false);

                        await writer.WriteAsync(new DateBind(
                                                    ImageSource.FromStream(() => new MemoryStream(buffer)),
                                                    item.Title,
                                                    item.Uri)).ConfigureAwait(false);
                    }
                    catch (MHttpClientException)
                    {
                    }
                }
            }

            while (true)
            {
                try
                {
                    string html = await load.GetStringAsync(func(), default).ConfigureAwait(false);

                    await AddDate(html).ConfigureAwait(false);
                }
                catch (MHttpClientException)
                {
                }
                catch (ChannelClosedException)
                {
                    return;
                }
            }
        }