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 static void CacheImageInitializationHelper(CacheImageDateType cacheImageDateType) { var af = new RenrenCodeFacader().GetServiceAbstractFactry(); var cacheFactory = af.CreateCacheServiceFactry(); var imageCache = cacheFactory.CreateImageCacheByServiceType(CacheImageDateManage.CacheTypeToString(cacheImageDateType)); }