コード例 #1
0
ファイル: Podcast.cs プロジェクト: yoavfr/podcatcher
        private async Task LoadImage(string imageUri)
        {
            Uri validUri;

            if (!System.Uri.TryCreate(imageUri, UriKind.Absolute, out validUri))
            {
                return;
            }

            string imageExtension = Path.GetExtension(validUri.AbsolutePath);
            string localImagePath = string.Format("{0}{1}", FileName, imageExtension);
            ulong  oldFileSize    = await GetCachedFileSize(localImagePath);

            // the image we have is from the cache
            IDownloader downloader = m_DownloadService.CreateDownloader(validUri, ApplicationData.Current.LocalFolder, localImagePath, null);

            try
            {
                // Don't try to download if all we have is the local file
                if (!validUri.IsFile)
                {
                    Tracer.TraceInformation("Podcast.LoadImage(): Downloading {0} -> {1}", validUri, localImagePath);
                    StorageFile localImageFile = await downloader.Download();

                    Tracer.TraceInformation("Podcast.LoadImage(): Finished downloading {0} -> {1}", validUri, localImageFile.Path);
                    Image = localImageFile.Path;

                    ulong newFileSize = await GetCachedFileSize(localImagePath);

                    if (newFileSize != oldFileSize)
                    {
                        NotifyPropertyChanged(() => Image);
                    }
                }

                TouchedFiles.Instance.Add(Image);
            }
            catch (Exception e)
            {
                Tracer.TraceInformation("Podcast.LoadImage(): Failed downloading {0} -> {1}. {2}", validUri, localImagePath, e);
            }
        }