protected override async Task <RenrenAyncRespArgs <FeedListEntity> > DoOfflineDataRequest(params object[] args)
        {
            int uid      = (int)args[0];
            int page     = (int)args[1];
            int pageSize = (int)args[2];

            // TODO:
            // 创建相应的缓存片段
            // 查看缓存是否有效
            // 进行缓存逻辑
            var      hashKey = generateHashKey(uid, page, pageSize);
            DateTime expTime = DateTime.Now.AddDays(ExpirationTimeDay);
            ICacheChip <FeedListEntity> chip = _cacheImpl.CreateCacheChip(hashKey, expTime);
            var valid = _cacheImpl.IsValid(chip);

            if (valid && !this.ForceDataRequest)
            {
                FeedListEntity content = await _cacheImpl.Pick(chip);

                return(new RenrenAyncRespArgs <FeedListEntity>(content));
            }
            else
            {
                var resp = await Renren3GApiWrapper.GetFeedList(this.LoginInfo.LoginInfo.Session_key, this.LoginInfo.LoginInfo.Secret_key, page, pageSize, uid);

                if (resp.Result != null)
                {
                    await _cacheImpl.Add(chip, resp.Result);
                }
                return(resp);
            }
        }
        public async Task <BitmapImage> Pick(ICacheChip <BitmapImage> chip)
        {
            BitmapImage result = null;

            {
                result = chip.PickCacheData().Result;
            }
            return(result);
        }
        public async Task <bool> Remove(ICacheChip <BitmapImage> chip)
        {
            if (this._cacheIndexs.ContainsKey(chip.HashKey))
            {
                await chip.Reset();

                _cacheIndexs.Remove(chip.HashKey);
            }
            return(true);
        }
 public bool IsValid(ICacheChip <BitmapImage> chip)
 {
     if (_cacheIndexs.ContainsKey(chip.HashKey) && (_cacheIndexs[chip.HashKey] as ImageCacheChip).ImageReady)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#5
0
        async void clipImageBrushCache_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            if (this.IsCacheImage)
            {
                RetryCount++;
                if (RetryCount < 4)
                {
                    var image    = sender as ImageBrush;
                    var imageUri = this.Source;
                    await image.Dispatcher.RunIdleAsync((p) =>
                    {
                        var unused = Task.Factory.StartNew(async() =>
                        {
                            ICacheChip <BitmapImage> chip = clipImageBrushCacheSerivce.CreateCacheChip(hashKey, null);
                            (chip as ImageCacheChip).AddImageUpdate(image);
                            await clipImageBrushCacheSerivce.Add(chip, imageUri);
                        });
                    });
                }

                if (RetryCount == 4)
                {
                    IsOnlineImage = true;
                    BitmapImage bi = new BitmapImage(new Uri(this.Source, UriKind.RelativeOrAbsolute));
                    bi.DownloadProgress += (ss, ee) =>
                    {
                        if (this.ImageDownLoadProgress != null)
                        {
                            this.ImageDownLoadProgress(ee.Progress);
                        }
                    };
                    bi.ImageOpened += (s1, e1) =>
                    {
                        clipImageBrushCache.ImageSource = bi;
                    };
                }

                if (RetryCount > 4)
                {
                    if (this.ImageFailed != null)
                    {
                        this.ImageFailed(sender, e);
                    }
                    return;
                }
            }
            else
            {
                if (this.ImageFailed != null)
                {
                    this.ImageFailed(sender, e);
                }
            }
        }
示例#6
0
        public async Task <bool> Add(ICacheChip <T> chip, params object[] contents)
        {
            T content = (T)contents[0];

            if (_cacheIndexs.ContainsKey(chip.HashKey))
            {
                _cacheIndexs[chip.HashKey] = chip;
            }
            else
            {
                _cacheIndexs.Add(chip.HashKey, chip);
                await chip.SaveCacheData(content);
            }
            return(true);
        }
示例#7
0
 public bool IsValid(ICacheChip <T> chip)
 {
     if (!_cacheIndexs.ContainsKey(chip.HashKey))
     {
         return(false);
     }
     else if (_cacheIndexs.ContainsKey(chip.HashKey) && DateTime.Now > _cacheIndexs[chip.HashKey].ExpirationTime)
     {
         chip.Reset();
         _cacheIndexs.Remove(chip.HashKey);
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public async Task <bool> Add(ICacheChip <BitmapImage> chip, params object[] contents)
        {
            //lock (this)
            {
                string url = (string)contents[0];
                if (_cacheIndexs.ContainsKey(chip.HashKey))
                {
                    _cacheIndexs[chip.HashKey] = chip;
                }
                else
                {
                    _cacheIndexs.Add(chip.HashKey, chip);
                }

                await chip.SaveCacheData(url);
            }

            return(true);
        }
        public async Task <bool> Replace(ICacheChip <BitmapImage> chip, params object[] contents)
        {
            if (contents.Length < 2)
            {
                throw new ArgumentException();
            }

            if (this._cacheIndexs.ContainsKey(chip.HashKey))
            {
                _cacheIndexs.Remove(chip.HashKey);
            }

            ICacheChip <BitmapImage> newchip = contents[0] as ICacheChip <BitmapImage>;
            string url = contents[1] as string;

            _cacheIndexs.Add(chip.HashKey, newchip);

            await newchip.SaveCacheData(url);

            return(true);
        }
示例#10
0
        public async Task <bool> Replace(ICacheChip <T> chip, params object[] contents)
        {
            if (contents.Length < 2)
            {
                throw new ArgumentException();
            }

            if (this._cacheIndexs.ContainsKey(chip.HashKey))
            {
                _cacheIndexs.Remove(chip.HashKey);
            }

            ICacheChip <T> newchip = contents[0] as ICacheChip <T>;
            T content = (T)contents[0];

            _cacheIndexs.Add(chip.HashKey, newchip);

            await newchip.SaveCacheData(content);

            return(true);
        }
 public bool IsValid(ICacheChip <T> chip)
 {
     return((this._target as ICacheSerivce <T>).IsValid(chip));
 }
示例#12
0
        private async void imageCache_ImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            if (this.IsCacheImage)
            {
                RetryCount++;
                if (RetryCount < 4)
                {
                    var image    = sender as Image;
                    var imageUri = this.Source;
                    await image.Dispatcher.RunIdleAsync((p) =>
                    {
                        var unused = Task.Factory.StartNew(async() =>
                        {
                            ICacheChip <BitmapImage> chip = imageCacheSerivce.CreateCacheChip(hashKey, null);
                            (chip as ImageCacheChip).AddImageUpdate(image);
                            await imageCacheSerivce.Add(chip, imageUri);
                        });
                    });
                }

                if (RetryCount == 4)
                {
                    IsOnlineImage = true;
                    BitmapImage bi = new BitmapImage(new Uri(this.Source, UriKind.RelativeOrAbsolute));
                    bi.DownloadProgress += (ss, ee) =>
                    {
                        if (this.ImageDownLoadProgress != null)
                        {
                            this.ImageDownLoadProgress(ee.Progress);
                        }
                    };
                    bi.ImageOpened += (s1, e1) =>
                    {
                        imageCache.Source = bi;
                    };

                    //var rass = RandomAccessStreamReference.CreateFromUri(new Uri(this.Source, UriKind.RelativeOrAbsolute));
                    //IRandomAccessStreamWithContentType streamRandom = await rass.OpenReadAsync();
                    //bi.SetSource(streamRandom);

                    //WriteableBitmap wb = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);
                    //wb.SetSource(streamRandom);
                    //IBuffer iBuffer = wb.PixelBuffer;
                }

                if (RetryCount > 4)
                {
                    if (this.ImageFailed != null)
                    {
                        this.ImageFailed(sender, e);
                    }
                    return;
                }
            }
            else
            {
                if (this.ImageFailed != null)
                {
                    this.ImageFailed(sender, e);
                }
            }
        }
示例#13
0
        private void ChangeSourceAndCacheType()
        {
            //20140120
            this.IsImageComplete = false;
            if (this.IsAnimation)
            {
                if (this.AnimationType == ControlLibrary.AnimationType.AanimationFadeOut)
                {
                    this.imageCache.Opacity = 0;
                }
                else
                {
                    this.planeProjection.RotationX = 90;
                }
                CreateAnimationBegin();
            }
            else
            {
                this.imageCache.Opacity        = 1.0;
                this.planeProjection.RotationX = 0;
            }

            BitmapImage bi = new BitmapImage();

            if (this.IsDisplayOldImage)
            {
                this.imageCache.Source = bi;
            }
            var   reg   = @"http(s)?://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?";
            Regex regex = new Regex(reg, RegexOptions.IgnoreCase);

            if (regex.IsMatch(this.Source))
            {
                if (this.IsCacheImage)
                {
                    var af           = new RenrenCodeFacader().GetServiceAbstractFactry();
                    var cacheFactory = af.CreateCacheServiceFactry();
                    //var imageCache = cacheFactory.CreateImageCacheByServiceType(ServiceType.AlbumListServiceType);
                    /*var imageCache = cacheFactory.CreateImageCacheByServiceType(this.CacheType);*/
                    var imageCache = cacheFactory.CreateImageCacheByServiceType(CacheImageDateManage.CacheTypeToString(this.CacheType));

                    hashKey = ApiHelper.ComputeMD5(this.Source);
                    //DateTime expTime = CacheImageDateManage.CacheTypeToDate((ServiceType)parameter);
                    //DateTime expTime = CacheImageDateManage.CacheTypeToDate(parameter.ToString());
                    imageCacheSerivce = (imageCache as ICacheSerivce <BitmapImage>);

                    IProgress <int> progress = new Progress <int>((p) =>
                    {
                        if (this.ImageDownLoadProgress != null)
                        {
                            this.ImageDownLoadProgress(p);
                        }
                    });
                    chip = imageCacheSerivce.CreateCacheChip(hashKey, DateTime.Now, progress);
                    this.IsImageComplete = imageCacheSerivce.IsValid(chip);
                    bi            = imageCacheSerivce.Pick(chip).Result;
                    IsOnlineImage = false;
                }
                else
                {
                    bi.UriSource = new Uri(this.Source, UriKind.RelativeOrAbsolute);
                    //bi.DownloadProgress += (ss, ee) =>
                    //    {
                    //        if (this.ImageDownLoadProgress != null)
                    //        {
                    //            this.ImageDownLoadProgress(ee.Progress);
                    //        }
                    //    };
                    bi.DownloadProgress -= bi_DownloadProgress;
                    bi.DownloadProgress += bi_DownloadProgress;
                    IsOnlineImage        = true;
                }
            }
            else
            {
                bi.UriSource = new Uri(this.BaseUri, this.Source);
                //if (this.ImageDownLoadProgress != null)
                //{
                //    this.ImageDownLoadProgress(100);
                //}
                bi.DownloadProgress -= bi_DownloadProgress;
                bi.DownloadProgress += bi_DownloadProgress;
            }
            if (!this.IsDisplayOldImage)
            {
                this.imageCache.Source = bi;
            }
        }
 public Task <bool> Replace(ICacheChip <T> chip, params object[] contents)
 {
     return((this._target as ICacheSerivce <T>).Replace(chip, contents));
 }
 public Task <T> Pick(ICacheChip <T> chip)
 {
     return((this._target as ICacheSerivce <T>).Pick(chip));
 }
 public Task <IStorageFile> PickFile(ICacheChip <BitmapImage> chip)
 {
     return(chip.PickCacheFile());
 }
 public Task <bool> Remove(ICacheChip <T> chip)
 {
     return((this._target as ICacheSerivce <T>).Remove(chip));
 }
示例#18
0
 public async Task <T> Pick(ICacheChip <T> chip)
 {
     return(await chip.PickCacheData());
 }
 public Task <Windows.Storage.IStorageFile> PickFile(ICacheChip <T> chip)
 {
     return((this._target as ICacheSerivce <T>).PickFile(chip));
 }