QuickImage – Blame information for rev 2

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  
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 {
66 return supportedImages.Contains(mime) || supportedVideos.Contains(mime);
67 }
68  
69 public bool IsSupportedImage(string mime)
70 {
71 return supportedImages.Contains(mime);
72 }
73  
74 public bool IsSupportedVideo(string mime)
75 {
76 return supportedVideos.Contains(mime);
77 }
78  
79 protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
80 {
81 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
82 }
83  
84 protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
85 {
86 if (EqualityComparer<T>.Default.Equals(field, value)) return false;
87 field = value;
88 OnPropertyChanged(propertyName);
89 return true;
90 }
91  
92 public void Add(Images images)
93 {
94 foreach (var image in images.Image)
95 {
96 if (!_images.Image.Contains(image))
97 {
98 _images.Image.Add(image);
99 }
100 }
101  
102 supportedImages.UnionWith(images.Image);
103 }
104  
105 public void Add(Videos videos)
106 {
107 foreach (var video in videos.Video)
108 {
109 if (!_videos.Video.Contains(video))
110 {
111 _videos.Video.Add(video);
112 }
113 }
114  
115 supportedVideos.UnionWith(videos.Video);
116 }
117 }
118 }