QuickImage – Blame information for rev 7
?pathlinks?
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 | |||
28 | if (value is { Image: { } } && value.Image.Count != 0) |
||
29 | { |
||
30 | supportedImages.UnionWith(value.Image); |
||
31 | } |
||
32 | OnPropertyChanged(); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | [XmlElement(ElementName = "Videos")] |
||
37 | public Videos Videos |
||
38 | { |
||
39 | get => _videos; |
||
40 | set |
||
41 | { |
||
42 | if (Equals(value, _videos)) |
||
43 | { |
||
44 | return; |
||
45 | } |
||
46 | |||
47 | _videos = value; |
||
48 | if(value is { Video: { }} && value.Video.Count != 0) |
||
49 | { |
||
50 | supportedVideos.UnionWith(value.Video); |
||
51 | } |
||
52 | OnPropertyChanged(); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | public SupportedFormats() |
||
57 | { |
||
58 | } |
||
59 | |||
60 | public event PropertyChangedEventHandler PropertyChanged; |
||
2 | office | 61 | private readonly HashSet<string> supportedImages = new HashSet<string>(StringComparer.OrdinalIgnoreCase); |
62 | private readonly HashSet<string> supportedVideos = new HashSet<string>(StringComparer.OrdinalIgnoreCase); |
||
1 | office | 63 | |
64 | public bool IsSupported(string mime) |
||
65 | { |
||
7 | office | 66 | if (string.IsNullOrEmpty(mime)) |
67 | { |
||
68 | return false; |
||
69 | } |
||
70 | |||
1 | office | 71 | return supportedImages.Contains(mime) || supportedVideos.Contains(mime); |
72 | } |
||
73 | |||
74 | public bool IsSupportedImage(string mime) |
||
75 | { |
||
7 | office | 76 | if(string.IsNullOrEmpty(mime)) |
77 | { |
||
78 | return false; |
||
79 | } |
||
80 | |||
1 | office | 81 | return supportedImages.Contains(mime); |
82 | } |
||
83 | |||
84 | public bool IsSupportedVideo(string mime) |
||
85 | { |
||
7 | office | 86 | if (string.IsNullOrEmpty(mime)) |
87 | { |
||
88 | return false; |
||
89 | } |
||
90 | |||
1 | office | 91 | return supportedVideos.Contains(mime); |
92 | } |
||
93 | |||
94 | protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
||
95 | { |
||
96 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
||
97 | } |
||
98 | |||
99 | protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null) |
||
100 | { |
||
101 | if (EqualityComparer<T>.Default.Equals(field, value)) return false; |
||
102 | field = value; |
||
103 | OnPropertyChanged(propertyName); |
||
104 | return true; |
||
105 | } |
||
106 | |||
107 | public void Add(Images images) |
||
108 | { |
||
109 | foreach (var image in images.Image) |
||
110 | { |
||
111 | if (!_images.Image.Contains(image)) |
||
112 | { |
||
113 | _images.Image.Add(image); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | supportedImages.UnionWith(images.Image); |
||
118 | } |
||
119 | |||
120 | public void Add(Videos videos) |
||
121 | { |
||
122 | foreach (var video in videos.Video) |
||
123 | { |
||
124 | if (!_videos.Video.Contains(video)) |
||
125 | { |
||
126 | _videos.Video.Add(video); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | supportedVideos.UnionWith(videos.Video); |
||
131 | } |
||
132 | } |
||
133 | } |