Example #1
0
 private static void SetImage(LazyImage image, ImageSource source, Uri sourceFrom)
 {
     try
     {
         if (image.UriSource != sourceFrom)
         {
             return;
         }
         if (source == null)
         {
             // unset value
             image.Source = null;
             return;
         }
         if (!source.IsFrozen)
         {
             throw new ArgumentException("Image is not frozen.");
         }
         image.Source = source;
     }
     // ReSharper disable EmptyGeneralCatchClause
     catch
     // ReSharper restore EmptyGeneralCatchClause
     {
     }
 }
Example #2
0
 private static void PushDecodeTask(Uri uriSource, LazyImage targetImage,
                                    byte[] bytes, int dpw, int dph)
 {
     _decodeStack.Push(Tuple.Create(uriSource, targetImage, bytes, dpw, dph));
     if (Interlocked.Increment(ref _decodeThreadConcurrency) > MaxDecodeConcurrency)
     {
         Interlocked.Decrement(ref _decodeThreadConcurrency);
         return;
     }
     // run task
     RunNextDecodeTask();
 }
Example #3
0
 private static void ReloadImage(LazyImage img, Uri uri, int dpw, int dph)
 {
     try
     {
         img.Source = null;
         if (uri.Scheme == "pack")
         {
             // PACK image
             var bi = new BitmapImage(uri)
             {
                 CacheOption = BitmapCacheOption.OnLoad
             };
             bi.Freeze();
             SetImage(img, bi, uri);
         }
         else
         {
             byte[] cache;
             if (GetCache(uri, out cache))
             {
                 // decode image
                 PushDecodeTask(uri, img, cache, dpw, dph);
                 return;
             }
             IObservable <byte[]> observable;
             Subject <byte[]>     publisher = null;
             lock (_imageObservables)
             {
                 if (!_imageObservables.TryGetValue(uri, out observable))
                 {
                     observable = publisher = new Subject <byte[]>();
                     _imageObservables.Add(uri, publisher);
                 }
             }
             observable.Subscribe(b => PushDecodeTask(uri, img, b, dpw, dph), ex => { });
             if (publisher != null)
             {
                 PushLoadTask(uri, publisher);
             }
         }
     }
     // ReSharper disable EmptyGeneralCatchClause
     catch
     // ReSharper restore EmptyGeneralCatchClause
     {
     }
 }
Example #4
0
 private static void SetImage(LazyImage image, ImageSource source, Uri sourceFrom)
 {
     try
     {
         if (image.UriSource != sourceFrom) return;
         if (source == null)
         {
             // unset value
             image.Source = null;
             return;
         }
         if (!source.IsFrozen)
         {
             throw new ArgumentException("Image is not frozen.");
         }
         image.Source = source;
     }
     // ReSharper disable EmptyGeneralCatchClause
     catch
     // ReSharper restore EmptyGeneralCatchClause
     {
     }
 }
Example #5
0
 private static void ReloadImage(LazyImage img, Uri uri, int dpw, int dph)
 {
     try
     {
         img.Source = null;
         if (uri.Scheme == "pack")
         {
             // PACK image
             var bi = new BitmapImage(uri) { CacheOption = BitmapCacheOption.OnLoad };
             bi.Freeze();
             SetImage(img, bi, uri);
         }
         else
         {
             byte[] cache;
             if (GetCache(uri, out cache))
             {
                 // decode image
                 PushDecodeTask(uri, img, cache, dpw, dph);
                 return;
             }
             IObservable<byte[]> observable;
             Subject<byte[]> publisher = null;
             lock (_imageObservables)
             {
                 if (!_imageObservables.TryGetValue(uri, out observable))
                 {
                     observable = publisher = new Subject<byte[]>();
                     _imageObservables.Add(uri, publisher);
                 }
             }
             observable.Subscribe(b => PushDecodeTask(uri, img, b, dpw, dph), ex => { });
             if (publisher != null)
             {
                 PushLoadTask(uri, publisher);
             }
         }
     }
     // ReSharper disable EmptyGeneralCatchClause
     catch
     // ReSharper restore EmptyGeneralCatchClause
     {
     }
 }
Example #6
0
 private static void PushDecodeTask(Uri uriSource, LazyImage targetImage,
     byte[] bytes, int dpw, int dph)
 {
     _decodeStack.Push(Tuple.Create(uriSource, targetImage, bytes, dpw, dph));
     if (Interlocked.Increment(ref _decodeThreadConcurrency) > MaxDecodeConcurrency)
     {
         Interlocked.Decrement(ref _decodeThreadConcurrency);
         return;
     }
     // run task
     RunNextDecodeTask();
 }
Example #7
0
 private static void PushDecodeTask(Uri uriSource, LazyImage targetImage,
     byte[] bytes, int dpw, int dph)
 {
     _decodeStack.Push(Tuple.Create(uriSource, targetImage, bytes, dpw, dph));
     _decodeSignal.Set();
 }
Example #8
0
 private static void ReloadImage(LazyImage img, Uri uri, int dpw, int dph)
 {
     try
     {
         if (uri.Scheme == "pack")
         {
             // PACK image
             var bi = new BitmapImage(uri) { CacheOption = BitmapCacheOption.OnLoad };
             bi.Freeze();
             SetImage(img, bi, uri);
         }
         else
         {
             byte[] cache;
             if (GetCache(uri, out cache))
             {
                 _taskFactory.StartNew(() =>
                 {
                     var b = CreateImage(cache, dpw, dph);
                     DispatcherHolder.Enqueue(() => SetImage(img, b, uri), DispatcherPriority.Loaded);
                 });
                 return;
             }
             img.Source = null;
             Subject<byte[]> publisher = null;
             _imageStreamer.GetOrAdd(uri, _ => publisher = new Subject<byte[]>())
                           .Select(b => CreateImage(b, dpw, dph))
                           .Subscribe(b => DispatcherHolder.Enqueue(
                               () => SetImage(img, b, uri), DispatcherPriority.Loaded)
                                      , ex => { });
             if (publisher != null)
             {
                 _taskFactory.StartNew(() => LoadBytes(uri, publisher));
             }
         }
     }
     // ReSharper disable EmptyGeneralCatchClause
     catch
     // ReSharper restore EmptyGeneralCatchClause
     {
     }
 }
Example #9
0
 private static void SetImage(LazyImage image, ImageSource source, Uri sourceFrom)
 {
     try
     {
         if (source != null && image.UriSource == sourceFrom)
         {
             if (!source.IsFrozen)
                 throw new ArgumentException("Image is not frozen.");
             image.Source = source;
         }
     }
     // ReSharper disable EmptyGeneralCatchClause
     catch
     // ReSharper restore EmptyGeneralCatchClause
     {
     }
 }