public BitmapImage this[TLChannel channel]
        {
            get
            {
                if (channel == null)
                {
                    return(null);
                }

                var key = (object)channel.Photo;
                if (key == null)
                {
                    key = channel.Title;
                }

                if (_context.TryGetValue(key, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    return(target);
                }

                var bitmap = new TLBitmapSource(channel);
                _context[key] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));
                return(bitmap.Image);
            }
        }
        public BitmapImage this[TLPhoto photo, bool thumbnail = true]
        {
            get
            {
                if (photo == null)
                {
                    return(null);
                }

                if (_context.TryGetValue(photo, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    if (thumbnail == false)
                    {
                        reference.Item1.Download();
                    }

                    return(target);
                }

                var bitmap = new TLBitmapSource(photo);
                _context[photo] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));

                if (thumbnail == false)
                {
                    bitmap.Download();
                }

                return(bitmap.Image);
            }
        }
        public BitmapImage this[TLUser user]
        {
            get
            {
                if (user == null)
                {
                    return(null);
                }

                var key = (object)user.Photo;
                if (key == null)
                {
                    key = user.FullName;
                }

                if (_context.TryGetValue(key, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    return(target);
                }

                var bitmap = new TLBitmapSource(user);
                _context[key] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));
                return(bitmap.Image);
            }
        }
示例#4
0
        public ImageSource this[TLDocument document, bool?thumbnail]
        {
            get
            {
                if (document == null)
                {
                    return(null);
                }

                var key = (object)document;
                if (thumbnail == true)
                {
                    key = document.Id + "_thumbnail";
                }

                if (_context.TryGetValue(key, out Tuple <TLBitmapSource, WeakReference <ImageSource> > reference) &&
                    reference.Item2.TryGetTarget(out ImageSource target))
                {
                    if (thumbnail == null)
                    {
                        reference.Item1.Download();
                    }

                    return(target);
                }

                var bitmap = new TLBitmapSource(document, thumbnail == true);
                _context[key] = new Tuple <TLBitmapSource, WeakReference <ImageSource> >(bitmap, new WeakReference <ImageSource>(bitmap.Image));

                if (thumbnail == null)
                {
                    bitmap.Download();
                }

                return(bitmap.Image);


                //var context = _context;
                //if (thumbnail)
                //{
                //    context = _contextThumb;
                //}

                //if (context.TryGetValue(document, out Tuple<TLBitmapSource, WeakReference<ImageSource>> reference) &&
                //    reference.Item2.TryGetTarget(out ImageSource target))
                //{
                //    return target;
                //}

                //var bitmap = new TLBitmapSource(document, thumbnail);
                //context[document] = new Tuple<TLBitmapSource, WeakReference<ImageSource>>(bitmap, new WeakReference<ImageSource>(bitmap.Image));
                //return bitmap.Image;
            }
        }
        public BitmapImage this[TLDocument document, bool thumbnail]
        {
            get
            {
                if (document == null)
                {
                    return(null);
                }

                if (_context.TryGetValue(document, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    if (!thumbnail)
                    {
                        reference.Item1.Download();
                    }

                    return(target);
                }

                var bitmap = new TLBitmapSource(document, thumbnail);
                _context[document] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));
                return(bitmap.Image);


                //var context = _context;
                //if (thumbnail)
                //{
                //    context = _contextThumb;
                //}

                //if (context.TryGetValue(document, out Tuple<TLBitmapSource, WeakReference<BitmapImage>> reference) &&
                //    reference.Item2.TryGetTarget(out BitmapImage target))
                //{
                //    return target;
                //}

                //var bitmap = new TLBitmapSource(document, thumbnail);
                //context[document] = new Tuple<TLBitmapSource, WeakReference<BitmapImage>>(bitmap, new WeakReference<BitmapImage>(bitmap.Image));
                //return bitmap.Image;
            }
        }
        public BitmapImage this[TLWebDocument document]
        {
            get
            {
                if (document == null)
                {
                    return(null);
                }

                if (_context.TryGetValue(document, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    return(target);
                }

                var bitmap = new TLBitmapSource(document);
                _context[document] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));
                return(bitmap.Image);
            }
        }
        public BitmapImage this[TLChatForbidden forbiddenChat]
        {
            get
            {
                if (forbiddenChat == null)
                {
                    return(null);
                }

                if (_context.TryGetValue(forbiddenChat.Title, out Tuple <TLBitmapSource, WeakReference <BitmapImage> > reference) &&
                    reference.Item2.TryGetTarget(out BitmapImage target))
                {
                    return(target);
                }

                var bitmap = new TLBitmapSource(forbiddenChat);
                _context[forbiddenChat.Title] = new Tuple <TLBitmapSource, WeakReference <BitmapImage> >(bitmap, new WeakReference <BitmapImage>(bitmap.Image));
                return(bitmap.Image);
            }
        }
示例#8
0
        public ImageSource this[TLChat chat]
        {
            get
            {
                if (chat == null)
                {
                    return(null);
                }

                if (_context.TryGetValue(chat.Photo, out Tuple <TLBitmapSource, WeakReference <ImageSource> > reference) &&
                    reference.Item2.TryGetTarget(out ImageSource target))
                {
                    return(target);
                }

                var bitmap = new TLBitmapSource(chat);
                _context[chat.Photo] = new Tuple <TLBitmapSource, WeakReference <ImageSource> >(bitmap, new WeakReference <ImageSource>(bitmap.Image));
                return(bitmap.Image);
            }
        }