示例#1
0
            public override async Task <bool> Download(Archive a, AbsolutePath destination)
            {
                var(uri, client) = await Utils.Log(await ManuallyDownloadFile.Create(this)).Task;

                var state = new HTTPDownloader.State(uri.ToString())
                {
                    Client = client
                };

                return(await state.Download(a, destination));
            }
        private async Task HandleManualDownload(WebBrowserVM vm, CancellationTokenSource cancel, ManuallyDownloadFile manuallyDownloadFile)
        {
            var browser = new CefSharpWrapper(vm.Browser);

            vm.Instructions = $"Please locate and download {manuallyDownloadFile.State.Url}";

            var result = new TaskCompletionSource <Uri>();

            browser.DownloadHandler = uri =>
            {
                //var client = Helpers.GetClient(browser.GetCookies("").Result, browser.Location);
                result.SetResult(uri);
            };

            await vm.Driver.WaitForInitialized();

            await browser.NavigateTo(new Uri(manuallyDownloadFile.State.Url));

            while (!cancel.IsCancellationRequested)
            {
                if (result.Task.IsCompleted)
                {
                    var cookies = await Helpers.GetCookies();

                    var referer = browser.Location;
                    var client  = Helpers.GetClient(cookies, referer);
                    manuallyDownloadFile.Resume(result.Task.Result, client);
                    break;
                }
                await Task.Delay(100);
            }
        }