ExportService is pseudo async now

pull/17/head
Alexey Golub 7 years ago
parent b7979d6d1f
commit d8db4fca90

@ -3,6 +3,7 @@ using System.Linq;
using System.Reflection;
using System.Resources;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DiscordChatExporter.Models;
using HtmlAgilityPack;
using Tyrrrz.Extensions;
@ -18,7 +19,9 @@ namespace DiscordChatExporter.Services
_settingsService = settingsService;
}
public void Export(string filePath, ChannelChatLog log, Theme theme)
public Task ExportAsync(string filePath, ChannelChatLog log, Theme theme)
{
return Task.Run(() =>
{
var doc = GetTemplate();
var style = GetStyle(theme);
@ -53,14 +56,16 @@ namespace DiscordChatExporter.Services
var messageHtml = logHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg\"></div>"));
// Left
var messageLeftHtml = messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-left\"></div>"));
var messageLeftHtml =
messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-left\"></div>"));
// Avatar
messageLeftHtml.AppendChild(
HtmlNode.CreateNode($"<img class=\"msg-avatar\" src=\"{messageGroup.Author.AvatarUrl}\" />"));
// Right
var messageRightHtml = messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-right\"></div>"));
var messageRightHtml =
messageHtml.AppendChild(HtmlNode.CreateNode("<div class=\"msg-right\"></div>"));
// Author
var authorName = HtmlDocument.HtmlEncode(messageGroup.Author.Name);
@ -116,6 +121,7 @@ namespace DiscordChatExporter.Services
}
doc.Save(filePath);
});
}
}

@ -1,9 +1,10 @@
using DiscordChatExporter.Models;
using System.Threading.Tasks;
using DiscordChatExporter.Models;
namespace DiscordChatExporter.Services
{
public interface IExportService
{
void Export(string filePath, ChannelChatLog log, Theme theme);
Task ExportAsync(string filePath, ChannelChatLog log, Theme theme);
}
}

@ -176,7 +176,7 @@ namespace DiscordChatExporter.ViewModels
var chatLog = new ChannelChatLog(SelectedGuild, channel, messageGroups);
// Export
_exportService.Export(sfd.FileName, chatLog, _settingsService.Theme);
await _exportService.ExportAsync(sfd.FileName, chatLog, _settingsService.Theme);
// Show dialog
MessengerInstance.Send(new ShowExportDoneMessage(sfd.FileName));

Loading…
Cancel
Save