public async void InitFromUrl(string imageUrl)
        {
            ProgressAction(true);

            if (await StorageHelper.FileExistsAsync(imageUrl))
            {
                this.sourcefile = await StorageHelper.TryGetFileFromPathAsync(imageUrl);

                await InitDrawArea();

                ProgressAction(false);

                return;
            }

            var tcs            = new TaskCompletionSource <PictureEditor>();
            var storageManager = await LocalCacheManager.InitializeAsync(StorageFolderType.Pictures);

            DownloadHelper.DownloadAsync(imageUrl, storageManager.CurrentFolder, async(path, url) =>
            {
                if (imageUrl == url)
                {
                    this.sourcefile = await StorageHelper.TryGetFileFromPathAsync(path);

                    await InitDrawArea();
                }
                else
                {
                }

                ProgressAction(false);
            });
        }
Exemplo n.º 2
0
        public async void DownloadAsync_downloads()
        {
            // set-up
            IWebClient webClient = A.Fake <IWebClient>();

            DownloadHelper.WebClientFactory = () => webClient;
            IDownloadable download = CreateDownload();

            // call
            await DownloadHelper.DownloadAsync(download);

            // assert
            download.Status.MustBe(DownloadStatus.Success);
            download.Exception.MustBeNull();
        }
Exemplo n.º 3
0
        public async void DownloadAsync_sets_exception()
        {
            // set-up
            IDownloadable download  = CreateDownload();
            Exception     exception = new Exception("foo");
            IWebClient    webClient = A.Fake <IWebClient>();

            DownloadHelper.WebClientFactory = () => webClient;
            A.CallTo(() => webClient.OpenReadTaskAsync(_sampleUri))
            .Throws(exception);

            // call
            try
            {
                await DownloadHelper.DownloadAsync(download);
            }
            catch { }

            // assert
            download.Status.MustBe(DownloadStatus.Failed);
            download.Exception.MustBe(exception);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Downloads a PHP version asynchronously
        /// </summary>
        /// <param name="version"></param>
        public static async Task DownloadVersionAsync(Version version)
        {
            var query = _VersionCache.Where(o => o.VersionNumber == version);

            if (!query.Any())
            {
                throw new ArgumentException("The specified PHP version was not found", nameof(version));
            }

            PhpVersion ver = query.Single();

            if (File.Exists("php.zip"))
            {
                File.Delete("php.zip");
            }

            var downloader = new DownloadHelper(ver.DownloadURL, "php.zip");

            downloader.DownloadProgressChanged += (a, b) => DownloadProgressChanged(a, b);

            await downloader.DownloadAsync();

            await ExtractPackage(ver.VersionNumber);
        }