3using System.IO.Compression;
7using System.Threading.Tasks;
46 private ManualResetEvent initialized =
new ManualResetEvent(
false);
47 private readonly
string zipFileName;
48 private readonly
string programDataFolder;
49 private readonly
string imageUrl;
50 private readonly
int width;
51 private readonly
int height;
62 string ZipFileName,
string ProgramDataFolder)
78 string ZipFileName,
string ProgramDataFolder)
83 this.imageUrl = ImageURL;
84 this.zipFileName = ZipFileName;
85 this.programDataFolder = ProgramDataFolder;
89 DateTime TP = File.GetLastWriteTimeUtc(this.zipFileName);
91 if (File.Exists(
this.zipFileName) &&
RuntimeSettings.
Get(
this.zipFileName, DateTime.MinValue) != TP)
93 if (!Directory.Exists(ProgramDataFolder))
94 Directory.CreateDirectory(ProgramDataFolder);
97 string Folder = Path.Combine(ProgramDataFolder,
"Emoji1");
99 if (Directory.Exists(Folder))
100 Directory.Delete(Folder,
true);
103 this.initialized =
new ManualResetEvent(
false);
105 Task.Run(this.Unpack);
108 this.initialized =
new ManualResetEvent(
true);
116 private async Task Unpack()
121 new KeyValuePair<string, object>(
"FileName", this.zipFileName),
122 new KeyValuePair<string, object>(
"Destination", this.programDataFolder));
124 ZipFile.ExtractToDirectory(this.zipFileName, this.programDataFolder);
126 DateTime TP = File.GetLastWriteTimeUtc(this.zipFileName);
131 File.Delete(this.zipFileName);
132 Log.
Informational(
"File unpacked and deleted.",
new KeyValuePair<string, object>(
"FileName", this.zipFileName));
136 Log.
Informational(
"File unpacked.",
new KeyValuePair<string, object>(
"FileName", this.zipFileName));
145 this.initialized.Set();
156 return this.initialized.WaitOne(TimeoutMilliseconds);
182 return File.Exists(FileName);
192 switch (this.sourceFileType)
227 Output.Append(
"<img alt=\":");
229 Output.Append(
":\" title=\"");
231 Output.Append(
"\" width=\"");
233 Output.Append(
"\" height=\"");
235 Output.Append(
"\" src=\"");
236 Output.Append(Encode(await this.
GetUrl(Emoji, EmbedImage)));
237 Output.Append(
"\"/>");
250 OrgSize = (OrgSize * 4) / 3;
254 OrgSize = (OrgSize * 3) / 2;
261 private static string Encode(
string s)
263 if (s is
null || s.IndexOfAny(specialCharacters) < 0)
267 Replace(
"&",
"&").
268 Replace(
"<",
"<").
269 Replace(
">",
">").
270 Replace(
"\"",
""").
271 Replace(
"'",
"'");
274 private static readonly
char[] specialCharacters =
new char[] {
'<',
'>',
'&',
'"',
'\'' };
284 if (Embed ||
string.IsNullOrEmpty(this.imageUrl))
286 StringBuilder Output =
new StringBuilder();
288 Output.Append(
"data:");
295 Output.Append(
";base64,");
298 byte[] Data = await Runtime.IO.Files.ReadAllBytesAsync(FileName);
300 Output.Append(Convert.ToBase64String(Data));
302 return Output.ToString();
310 return this.imageUrl.Replace(
"%FILENAME%", s);
334 Url = await this.
GetUrl(Emoji,
false),
345 this.initialized?.Dispose();
346 this.initialized =
null;
Provides emojis from Emoji One (http://emojione.com/) stored as local files.
Emoji1LocalFiles(Emoji1SourceFileType SourceFileType, int Width, int Height, string ImageURL, string ZipFileName, string ProgramDataFolder)
Provides emojis from Emoji One (http://emojione.com/) stored as local files.
void Dispose()
IDisposable
Emoji1LocalFiles(Emoji1SourceFileType SourceFileType, int Width, int Height, string ZipFileName, string ProgramDataFolder)
Provides emojis from Emoji One (http://emojione.com/) stored as local files.
Task GenerateHTML(StringBuilder Output, EmojiInfo Emoji, bool EmbedImage)
Generates HTML for a given Emoji.
string GetFileName(EmojiInfo Emoji)
Gets the local file name for a given emoji.
Task< IImageSource > GetImageSource(EmojiInfo Emoji)
Gets the image source of an emoji.
bool WaitUntilInitialized(int TimeoutMilliseconds)
Waits until initialization is completed.
async Task< IImageSource > GetImageSource(EmojiInfo Emoji, int Level)
Gets the image source of an emoji.
bool EmojiSupported(EmojiInfo Emoji)
If the emoji is supported by the emoji source.
int Width
Desired width of emojis.
Emoji1SourceFileType SourceFileType
Type of files to use.
async Task GenerateHTML(StringBuilder Output, EmojiInfo Emoji, int Level, bool EmbedImage)
Generates HTML for a given Emoji.
async Task< string > GetUrl(EmojiInfo Emoji, bool Embed)
Gets an URL for the emoji.
int CalcSize(int OrgSize, int Level)
Calculates the size of an emoji.
int Height
Desired height of emojis.
Contains information about an emoji.
string FileName
Emoji file name.
string ShortName
Emoji short name.
string Description
Short description of emoji.
Contains information about an emoji image.
const string FileExtensionPng
png
const string ContentTypePng
image/png
const string FileExtensionSvg
svg
const string ContentTypeSvg
image/svg+xml
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Static class managing persistent settings.
static string Get(string Key, string DefaultValue)
Gets a string-valued setting.
static async Task< bool > SetAsync(string Key, string Value)
Sets a string-valued setting.
Interface for Emoji sources. Emoji sources provide emojis to content providers.
Emoji1SourceFileType
What source files to use when displaying emoji.
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.