QuickImage – Blame information for rev 11

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 office 1 using System;
2 using System.Collections.Generic;
1 office 3 using System.ComponentModel;
4 using System.Runtime.CompilerServices;
5 using System.Xml.Serialization;
6  
7 namespace Configuration
8 {
9 [XmlRoot(ElementName = "SupportedFormats")]
10 public class SupportedFormats : INotifyPropertyChanged
11 {
12 private Images _images = new Images(new[] { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/webp", "image/tga" });
13 private Videos _videos = new Videos(new[] { "video/mp4", "video/x-m4v", "video/webm" });
14  
15 [XmlElement(ElementName = "Images")]
16 public Images Images
17 {
18 get => _images;
19 set
20 {
21 if (Equals(value, _images))
22 {
23 return;
24 }
25  
26 _images = value;
27  
11 office 28 supportedImages.Clear();
1 office 29 if (value is { Image: { } } && value.Image.Count != 0)
30 {
31 supportedImages.UnionWith(value.Image);
32 }
33 OnPropertyChanged();
34 }
35 }
36  
37 [XmlElement(ElementName = "Videos")]
38 public Videos Videos
39 {
40 get => _videos;
41 set
42 {
43 if (Equals(value, _videos))
44 {
45 return;
46 }
47  
48 _videos = value;
11 office 49  
50 supportedVideos.Clear();
1 office 51 if(value is { Video: { }} && value.Video.Count != 0)
52 {
53 supportedVideos.UnionWith(value.Video);
54 }
55 OnPropertyChanged();
56 }
57 }
58  
59 public SupportedFormats()
60 {
61 }
62  
63 public event PropertyChangedEventHandler PropertyChanged;
11 office 64 private readonly HashSet<string> supportedImages = new HashSet<string>(new[] { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/webp", "image/tga" }, StringComparer.OrdinalIgnoreCase);
65 private readonly HashSet<string> supportedVideos = new HashSet<string>(new[] { "video/mp4", "video/x-m4v", "video/webm" }, StringComparer.OrdinalIgnoreCase);
1 office 66  
67 public bool IsSupported(string mime)
68 {
7 office 69 if (string.IsNullOrEmpty(mime))
70 {
71 return false;
72 }
73  
1 office 74 return supportedImages.Contains(mime) || supportedVideos.Contains(mime);
75 }
76  
77 public bool IsSupportedImage(string mime)
78 {
7 office 79 if(string.IsNullOrEmpty(mime))
80 {
81 return false;
82 }
83  
1 office 84 return supportedImages.Contains(mime);
85 }
86  
87 public bool IsSupportedVideo(string mime)
88 {
7 office 89 if (string.IsNullOrEmpty(mime))
90 {
91 return false;
92 }
93  
1 office 94 return supportedVideos.Contains(mime);
95 }
96  
97 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
98 {
99 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
100 }
101  
102 protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
103 {
104 if (EqualityComparer<T>.Default.Equals(field, value)) return false;
105 field = value;
106 OnPropertyChanged(propertyName);
107 return true;
108 }
109  
110 public void Add(Images images)
111 {
112 foreach (var image in images.Image)
113 {
114 if (!_images.Image.Contains(image))
115 {
116 _images.Image.Add(image);
117 }
118 }
119  
120 supportedImages.UnionWith(images.Image);
121 }
122  
123 public void Add(Videos videos)
124 {
125 foreach (var video in videos.Video)
126 {
127 if (!_videos.Video.Contains(video))
128 {
129 _videos.Video.Add(video);
130 }
131 }
132  
133 supportedVideos.UnionWith(videos.Video);
134 }
135 }
136 }