Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MultimediaItem.cs
1using System.IO;
2using System.Xml;
4
6{
11 {
12 private readonly MarkdownDocument doc;
13 private readonly string url;
14 private readonly string title;
15 private string extension;
16 private string contentType;
17 private readonly int? width;
18 private readonly int? height;
19
28 public MultimediaItem(MarkdownDocument Doc, string Url, string Title, int? Width, int? Height)
29 {
30 this.doc = Doc;
31 this.url = Url;
32 this.title = Title;
33 this.width = Width;
34 this.height = Height;
35 }
36
40 public MarkdownDocument Document => this.doc;
41
45 public string Url => this.url;
46
50 public string Title => this.title;
51
55 public int? Width => this.width;
56
60 public int? Height => this.height;
61
65 public string Extension
66 {
67 get
68 {
69 if (this.extension is null)
70 {
71 int i = this.url.IndexOfAny(questionOrHash);
72 if (i > 0)
73 {
74 this.extension = Path.GetExtension(this.url.Substring(0, i));
75
76 if (string.IsNullOrEmpty(this.extension))
77 {
78 int j = this.url.IndexOf('?', i + 1);
79 if (j > i)
80 this.extension = Path.GetExtension(this.url.Substring(0, j));
81 else
82 this.extension = Path.GetExtension(this.url);
83 }
84 }
85 else
86 this.extension = Path.GetExtension(this.url);
87 }
88
89 return this.extension;
90 }
91 }
92
93 private static readonly char[] questionOrHash = new char[] { '?', '#' };
94
98 public string ContentType
99 {
100 get
101 {
102 if (this.contentType is null)
103 this.contentType = InternetContent.GetContentType(this.Extension);
104
105 return this.contentType;
106 }
107 }
108
113 public void Export(XmlWriter Output)
114 {
115 Output.WriteStartElement("MultimediaItem");
116 Output.WriteAttributeString("url", this.url);
117 Output.WriteAttributeString("title", this.title);
118 Output.WriteAttributeString("extension", this.extension);
119 Output.WriteAttributeString("contentType", this.contentType);
120
121 if (this.width.HasValue)
122 Output.WriteAttributeString("width", this.width.Value.ToString());
123
124 if (this.height.HasValue)
125 Output.WriteAttributeString("height", this.height.Value.ToString());
126
127 Output.WriteEndElement();
128 }
129
135 public override bool Equals(object obj)
136 {
137 return obj is MultimediaItem Obj &&
138 this.url == Obj.url &&
139 this.title == Obj.title &&
140 this.extension == Obj.extension &&
141 this.contentType == Obj.contentType &&
142 this.width == Obj.width &&
143 this.height == Obj.height;
144 }
145
150 public override int GetHashCode()
151 {
152 int h1 = this.url?.GetHashCode() ?? 0;
153 int h2 = this.title?.GetHashCode() ?? 0;
154
155 h1 = ((h1 << 5) + h1) ^ h2;
156
157 h2 = this.extension?.GetHashCode() ?? 0;
158 h1 = ((h1 << 5) + h1) ^ h2;
159
160 h2 = this.contentType?.GetHashCode() ?? 0;
161 h1 = ((h1 << 5) + h1) ^ h2;
162
163 h2 = this.width?.GetHashCode() ?? 0;
164 h1 = ((h1 << 5) + h1) ^ h2;
165
166 h2 = this.height?.GetHashCode() ?? 0;
167 h1 = ((h1 << 5) + h1) ^ h2;
168
169 return h1;
170 }
171
172 }
173}
Static class managing encoding and decoding of internet content.
static string GetContentType(string FileExtension)
Gets the content type of an item, given its file extension. It uses the TryGetContentType to see if a...
Contains a markdown document. This markdown document class supports original markdown,...
override int GetHashCode()
Serves as the default hash function.
MultimediaItem(MarkdownDocument Doc, string Url, string Title, int? Width, int? Height)
Multimedia item.
MarkdownDocument Document
Markdown document
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
int? Height
Height of media item, if available.
void Export(XmlWriter Output)
Exports the element to XML.
int? Width
Width of media item, if available.
Contains information about an emoji image.
Definition: IImageSource.cs:7