コード例 #1
0
        public void printExercices()
        {
            RScache cache = new RScache();

            foreach (RSapiExercice apiEx in apiExercices)
            {
                RSexercice    exercice     = new RSexercice(apiEx);
                RSapiResource thumbnailRes = exercice.getThumbnailResource();
                if (thumbnailRes != null)
                {
                    string thumbnailLocalPath = cache.getLocalPathForURL(thumbnailRes.url, thumbnailRes.name);
                    if (thumbnailLocalPath == null)
                    {
                        thumbnailLocalPath = cache.downloadThumbnailAsync(thumbnailRes);
                    }
                    exercice.ThumbnailLocalPath = thumbnailLocalPath;
                }
                Application.Current.Dispatcher.BeginInvoke(new Action(() => this.exercices.Add(exercice)));
            }
        }
コード例 #2
0
        // Demande de téléchargement d'une image
        public string downloadThumbnailAsync(RSapiResource thumbnail)
        {
            string thumbnailLocalPath = Path.Combine(specificFolder, thumbnail.name);

            using (WebClient wbClient = new WebClient())
            {
                Uri ur = new Uri(thumbnail.url);
                while (true)
                {
                    try {
                        wbClient.DownloadFileAsync(ur, thumbnailLocalPath);
                        Task.Delay(2500).Wait();
                        break;
                    }
                    catch (Exception e) {
                        MessageBox.Show(e.Message);
                    }
                }
            }
            return(thumbnailLocalPath);
        }