Beispiel #1
0
 private void AssertThread(ImageCacheInfo cacheInfo, int taskId)
 {
     if (cacheInfo.GetCurrentTaskId() != taskId)
     {
         throw new TaskCanceledException();
     }
 }
Beispiel #2
0
        /// <summary>キャッシュ情報から画像データを取得する</summary>
        /// <param name="cacheInfo">キャッシュ情報</param>
        /// <param name="userInfo">ユーザ情報</param>
        /// <returns>画像データ</returns>
        private BitmapImage LoadImage(ImageCacheInfo cacheInfo, IUserInfo userInfo)
        {
            int taskId = cacheInfo.GetCurrentTaskId();

            this.AssertThread(cacheInfo, taskId);
            var imageUrl = userInfo.ProfileImageUrl;

            if (string.IsNullOrEmpty(imageUrl))
            {
                return(null);
            }

            var imageFileName = Path.GetFileName(imageUrl);
            var @params       = CreateParameter(userInfo);

            this.AssertThread(cacheInfo, taskId);
            if (this.TryFindCache(@params, imageFileName, out var imageData))
            {
                this.AssertThread(cacheInfo, taskId);
                return(ImageUtil.CreateBitmapImage(new MemoryStream(imageData)));
            }

            this.AssertThread(cacheInfo, taskId);
            if (this.TryDownloadImage(userInfo, out var imageStream))
            {
                this.AssertThread(cacheInfo, taskId);
                //@params.Add("filename", imageFileName);
                //@params.Add("image_data", imageStream.ToArray());

                //this.WriteCache(@params);

                this.AssertThread(cacheInfo, taskId);

                return(ImageUtil.CreateBitmapImage(imageStream));
            }

            this.AssertThread(cacheInfo, taskId);

            return(null);
        }