Exemplo n.º 1
0
        private async Task <Stream> GetNetworkStreamAsync(System.Uri uri, CancellationToken cancellationToken)
        {
            string cacheFileName = UriLoader.GetCacheFileName(uri);

            if (await UriLoader.OpenTempFileStreamAsync(cacheFileName) == null)
            {
                await this.DownloadToCacheFileAsync(uri, cacheFileName, cancellationToken);
            }
            return(await UriLoader.OpenTempFileStreamAsync(cacheFileName));
        }
Exemplo n.º 2
0
 internal static async Task<Animator> CreateAsync(Image image, Uri sourceUri, RepeatBehavior repeatBehavior = default(RepeatBehavior))
 {
     var loader = new UriLoader();
     var stream = await loader.GetStreamFromUriAsync(sourceUri);
     try
     {
         return await CreateAsync(stream, sourceUri, repeatBehavior, image);
     }
     catch
     {
         stream?.Dispose();
         throw;
     }
 }
Exemplo n.º 3
0
 internal static async Task<Animator> CreateAsync(Image image, Uri sourceUri, RepeatBehavior repeatBehavior = default(RepeatBehavior))
 {
     var loader = new UriLoader();
     var stream = await loader.GetStreamFromUriAsync(sourceUri);
     try
     {
         return await CreateAsync(stream, sourceUri, repeatBehavior, image);
     }
     catch
     {
         stream?.Dispose();
         throw;
     }
 }
Exemplo n.º 4
0
        private static async Task SetStaticImageAsync(Image image, Uri sourceUri)
        {
            try
            {
                var progress = new Progress <int>(percentage => OnDownloadProgress(image, percentage));
                var stream   = await UriLoader.GetStreamFromUriAsync(sourceUri, progress);

                SetStaticImageCore(image, stream);
            }
            catch (Exception ex)
            {
                OnError(image, ex, AnimationErrorKind.Loading);
            }
        }
Exemplo n.º 5
0
        internal static async Task <TAnimator> CreateAsyncCore <TAnimator>(
            Uri sourceUri,
            IProgress <int> progress,
            Func <Stream, GifDataStream, TAnimator> create)
            where TAnimator : Animator
        {
            var stream = await UriLoader.GetStreamFromUriAsync(sourceUri, progress);

            try
            {
                // ReSharper disable once AccessToDisposedClosure
                return(await CreateAsyncCore(stream, metadata => create(stream, metadata)));
            }
            catch
            {
                stream?.Dispose();
                throw;
            }
        }
Exemplo n.º 6
0
        private async Task DownloadToCacheFileAsync(Uri uri, string fileName, CancellationToken cancellationToken)
        {
            Exception obj = null;
            int       num = 0;

            try
            {
                HttpClient httpClient = new HttpClient();
                try
                {
                    IBuffer source = await httpClient.GetBufferAsync(uri).AsTask(cancellationToken, new Progress <HttpProgress>(delegate(HttpProgress progress)
                    {
                        ulong?totalBytesToReceive = progress.TotalBytesToReceive;
                        if (totalBytesToReceive.HasValue)
                        {
                            double percentage = Math.Round(progress.BytesReceived * 100.0 / totalBytesToReceive.Value, 2);
                            EventHandler <DownloadProgressChangedArgs> expr_3E = this.DownloadProgressChanged;
                            if (expr_3E == null)
                            {
                                return;
                            }
                            expr_3E.Invoke(this, new DownloadProgressChangedArgs(uri, percentage));
                        }
                    }));

                    Stream stream = source.AsStream();
                    try
                    {
                        Stream stream2 = await UriLoader.CreateTempFileStreamAsync(fileName);

                        try
                        {
                            await stream.CopyToAsync(stream2);
                        }
                        finally
                        {
                            if (stream2 != null)
                            {
                                stream2.Dispose();
                            }
                        }
                        stream2 = null;
                    }
                    finally
                    {
                        if (stream != null)
                        {
                            stream.Dispose();
                        }
                    }
                    stream = null;
                }
                finally
                {
                    if (httpClient != null)
                    {
                        httpClient.Dispose();
                    }
                }
                httpClient = null;
            }
            catch (Exception obj_0)
            {
                num = 1;
                obj = obj_0;
            }

            if (num == 1)
            {
                await UriLoader.DeleteTempFileAsync(fileName);

                Exception expr_2FC = obj as Exception;
                if (expr_2FC == null)
                {
                    throw obj;
                }
                ExceptionDispatchInfo.Capture(expr_2FC).Throw();
            }
            obj = null;
        }
Exemplo n.º 7
0
 public async Task ClearCache()
 {
     await UriLoader.ClearCacheFolderAsync();
 }