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;
2using System.IO;
3using System.Xml;
5
7{
12 {
13 private readonly MarkdownDocument doc;
14 private readonly string url;
15 private readonly string title;
16 private string extension;
17 private string contentType;
18 private readonly int? width;
19 private readonly int? height;
20
29 public MultimediaItem(MarkdownDocument Doc, string Url, string Title, int? Width, int? Height)
30 {
31 this.doc = Doc;
32 this.url = Url;
33 this.title = Title;
34 this.width = Width;
35 this.height = Height;
36 }
37
41 public MarkdownDocument Document => this.doc;
42
46 public string Url => this.url;
47
51 public string Title => this.title;
52
56 public int? Width => this.width;
57
61 public int? Height => this.height;
62
66 public string Extension
67 {
68 get
69 {
70 if (this.extension is null)
71 {
72 int i = this.url.IndexOfAny(questionOrHash);
73 if (i > 0)
74 {
75 this.extension = Path.GetExtension(this.url.Substring(0, i));
76
77 if (string.IsNullOrEmpty(this.extension))
78 {
79 int j = this.url.IndexOf('?', i + 1);
80 if (j > i)
81 this.extension = Path.GetExtension(this.url.Substring(0, j));
82 else
83 this.extension = Path.GetExtension(this.url);
84 }
85 }
86 else
87 this.extension = Path.GetExtension(this.url);
88 }
89
90 return this.extension;
91 }
92 }
93
94 private static readonly char[] questionOrHash = new char[] { '?', '#' };
95
99 public string ContentType
100 {
101 get
102 {
103 if (this.contentType is null)
104 this.contentType = InternetContent.GetContentType(this.Extension);
105
106 return this.contentType;
107 }
108 }
109
114 public void Export(XmlWriter Output)
115 {
116 Output.WriteStartElement("MultimediaItem");
117 Output.WriteAttributeString("url", this.url);
118 Output.WriteAttributeString("title", this.title);
119 Output.WriteAttributeString("extension", this.extension);
120 Output.WriteAttributeString("contentType", this.contentType);
121
122 if (this.width.HasValue)
123 Output.WriteAttributeString("width", this.width.Value.ToString());
124
125 if (this.height.HasValue)
126 Output.WriteAttributeString("height", this.height.Value.ToString());
127
128 Output.WriteEndElement();
129 }
130
136 public override bool Equals(object obj)
137 {
138 return obj is MultimediaItem Obj &&
139 this.url == Obj.url &&
140 this.title == Obj.title &&
141 this.extension == Obj.extension &&
142 this.contentType == Obj.contentType &&
143 this.width == Obj.width &&
144 this.height == Obj.height;
145 }
146
151 public override int GetHashCode()
152 {
153 int h1 = this.url?.GetHashCode() ?? 0;
154 int h2 = this.title?.GetHashCode() ?? 0;
155
156 h1 = ((h1 << 5) + h1) ^ h2;
157
158 h2 = this.extension?.GetHashCode() ?? 0;
159 h1 = ((h1 << 5) + h1) ^ h2;
160
161 h2 = this.contentType?.GetHashCode() ?? 0;
162 h1 = ((h1 << 5) + h1) ^ h2;
163
164 h2 = this.width?.GetHashCode() ?? 0;
165 h1 = ((h1 << 5) + h1) ^ h2;
166
167 h2 = this.height?.GetHashCode() ?? 0;
168 h1 = ((h1 << 5) + h1) ^ h2;
169
170 return h1;
171 }
172
173 }
174}
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:9