Exemple #1
0
        public void Register(string type, ImageQuality quality, string image)
        {
            Debug.Assert(quality != ImageQuality.BestAvailable, "Must use a specific size when registering");

            var typeName    = type.ToUpper();
            var imageRecord = Get(typeName, quality, false);

            var updated = false;

            if (imageRecord != null)
            {
                if (imageRecord.Image != image)
                {
                    imageRecord.Image = image;
                    updated           = true;
                }
            }
            else
            {
                ImageMappings.Add(new ImageTypeRecord(typeName, quality, image));
                updated = true;
            }

            if (updated)
            {
                OnPropertyChanged("ImageMappings");
            }
        }
Exemple #2
0
        public ImageTypeRecord Get(string type, ImageQuality quality = ImageQuality.BestAvailable, bool acceptLower = true, bool mustHaveImage = false)
        {
            var typeName = type.ToUpper();
            var sorted   = ImageMappings.Where(r => r.Name == typeName).OrderByDescending(r => r.Quality);

            if (quality == ImageQuality.BestAvailable)
            {
                return(sorted.FirstOrDefault());
            }

            var exactMatch = sorted.SingleOrDefault(r => r.Quality == quality);

            if (exactMatch != null)
            {
                return(exactMatch);
            }

            // Don't have explicit size or have not asked for best available.
            if (acceptLower)
            {
                Debug.Assert(quality != ImageQuality.BestAvailable, "Must be an explicit quality");
                var newQuality = quality == ImageQuality.Large ? ImageQuality.Medium : ImageQuality.Small;
                if (newQuality != quality)
                {
                    return(Get(type, newQuality));
                }
            }

            return(mustHaveImage ? Get("Unknown", quality) : null);
        }
Exemple #3
0
        private void EditMapping(object obj)
        {
            var typeImageRecord = ImageMappings.ElementAt(SelectedIndex);

            if (typeImageRecord != null)
            {
                EditImage.Edit(typeImageRecord);
            }
        }
Exemple #4
0
        public ImageTypeRecord Get(
            string type,
            ImageOptions options)
        {
            type.ThrowIfNullOrWhiteSpace(nameof(type));
            options.ThrowIfNull(nameof(options));

            var quality = options.Quality;

            var typeName = type.ToUpper();
            var sorted   = ImageMappings.Where(r => r.Name == typeName).OrderByDescending(r => r.Quality);

            if (quality == ImageQuality.BestAvailable)
            {
                return(sorted.FirstOrDefault());
            }

            var exactMatch = sorted.SingleOrDefault(r => r.Quality == quality);

            if (exactMatch != null)
            {
                return(exactMatch);
            }

            // Don't have explicit size or have not asked for best available.
            if (options.AcceptLowerQuality)
            {
                Debug.Assert(quality != ImageQuality.BestAvailable, "Must be an explicit Quality");
                var newQuality = quality == ImageQuality.Large ? ImageQuality.Medium : ImageQuality.Small;
                if (newQuality != quality)
                {
                    // Update options
                    // TODO: ideally this should clone
                    var newOptions = new ImageOptions
                    {
                        Quality            = newQuality,
                        AcceptLowerQuality = options.AcceptLowerQuality,
                        ImageMustExist     = options.ImageMustExist
                    };

                    // Recursive
                    return(Get(type, newOptions));
                }
            }

            return(options.ImageMustExist ? Get("Unknown", options) : null);
        }
Exemple #5
0
        private void RemoveMapping(object obj)
        {
            var typeImageRecord = ImageMappings.ElementAt(SelectedIndex);

            RemoveImage.Remove(typeImageRecord);
        }