QuickImage – Blame information for rev 1

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