Update nuget packages

pull/162/head
Alexey Golub 5 years ago
parent 6d1cfef729
commit 889446fff7

@ -48,7 +48,7 @@ namespace DiscordChatExporter.Cli.Verbs
} }
// Export // Export
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); await exportService.ExportChatLogAsync(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit);
} }
} }
} }

@ -57,7 +57,8 @@ namespace DiscordChatExporter.Cli.Verbs
var filePath = Path.Combine(Options.OutputPath ?? "", fileName); var filePath = Path.Combine(Options.OutputPath ?? "", fileName);
// Export // Export
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); await exportService.ExportChatLogAsync(chatLog, filePath, Options.ExportFormat,
Options.PartitionLimit);
} }
} }
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden) catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)

@ -58,7 +58,8 @@ namespace DiscordChatExporter.Cli.Verbs
var filePath = Path.Combine(Options.OutputPath ?? "", fileName); var filePath = Path.Combine(Options.OutputPath ?? "", fileName);
// Export // Export
exportService.ExportChatLog(chatLog, filePath, Options.ExportFormat, Options.PartitionLimit); await exportService.ExportChatLogAsync(chatLog, filePath, Options.ExportFormat,
Options.PartitionLimit);
} }
} }
catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden) catch (HttpErrorStatusCodeException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)

@ -24,9 +24,9 @@
<PackageReference Include="Failsafe" Version="1.1.0" /> <PackageReference Include="Failsafe" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Onova" Version="2.4.2" /> <PackageReference Include="Onova" Version="2.4.2" />
<PackageReference Include="Scriban" Version="1.2.9" /> <PackageReference Include="Scriban" Version="2.0.0" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.5.1" /> <PackageReference Include="Tyrrrz.Extensions" Version="1.5.1" />
<PackageReference Include="Tyrrrz.Settings" Version="1.3.3" /> <PackageReference Include="Tyrrrz.Settings" Version="1.3.4" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

@ -1,4 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Threading.Tasks;
using DiscordChatExporter.Core.Models; using DiscordChatExporter.Core.Models;
using Scriban; using Scriban;
using Scriban.Parsing; using Scriban.Parsing;
@ -28,6 +29,11 @@ namespace DiscordChatExporter.Core.Services
return Assembly.GetExecutingAssembly().GetManifestResourceString(templatePath); return Assembly.GetExecutingAssembly().GetManifestResourceString(templatePath);
} }
public ValueTask<string> LoadAsync(TemplateContext context, SourceSpan callerSpan, string templatePath)
{
return new ValueTask<string>(Load(context, callerSpan, templatePath));
}
public string Load(ExportFormat format) public string Load(ExportFormat format)
{ {
return Assembly.GetExecutingAssembly().GetManifestResourceString(GetPath(format)); return Assembly.GetExecutingAssembly().GetManifestResourceString(GetPath(format));

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using DiscordChatExporter.Core.Internal; using DiscordChatExporter.Core.Internal;
using DiscordChatExporter.Core.Models; using DiscordChatExporter.Core.Models;
using Scriban; using Scriban;
@ -18,7 +19,7 @@ namespace DiscordChatExporter.Core.Services
_settingsService = settingsService; _settingsService = settingsService;
} }
private void ExportChatLogSingle(ChatLog chatLog, string filePath, ExportFormat format) private async Task ExportChatLogSingleAsync(ChatLog chatLog, string filePath, ExportFormat format)
{ {
// Create template loader // Create template loader
var loader = new TemplateLoader(); var loader = new TemplateLoader();
@ -39,7 +40,6 @@ namespace DiscordChatExporter.Core.Services
// Create template model // Create template model
var templateModel = new TemplateModel(format, chatLog, _settingsService.DateFormat); var templateModel = new TemplateModel(format, chatLog, _settingsService.DateFormat);
context.PushGlobal(templateModel.GetScriptObject()); context.PushGlobal(templateModel.GetScriptObject());
// Create directory // Create directory
@ -54,11 +54,11 @@ namespace DiscordChatExporter.Core.Services
context.PushOutput(new TextWriterOutput(output)); context.PushOutput(new TextWriterOutput(output));
// Render output // Render output
context.Evaluate(template.Page); await context.EvaluateAsync(template.Page);
} }
} }
private void ExportChatLogPartitioned(IReadOnlyList<ChatLog> partitions, string filePath, ExportFormat format) private async Task ExportChatLogPartitionedAsync(IReadOnlyList<ChatLog> partitions, string filePath, ExportFormat format)
{ {
// Split file path into components // Split file path into components
var dirPath = Path.GetDirectoryName(filePath); var dirPath = Path.GetDirectoryName(filePath);
@ -77,20 +77,20 @@ namespace DiscordChatExporter.Core.Services
partitionFilePath = Path.Combine(dirPath, partitionFilePath); partitionFilePath = Path.Combine(dirPath, partitionFilePath);
// Export // Export
ExportChatLogSingle(partition, partitionFilePath, format); await ExportChatLogSingleAsync(partition, partitionFilePath, format);
// Increment partition number // Increment partition number
partitionNumber++; partitionNumber++;
} }
} }
public void ExportChatLog(ChatLog chatLog, string filePath, ExportFormat format, public async Task ExportChatLogAsync(ChatLog chatLog, string filePath, ExportFormat format,
int? partitionLimit = null) int? partitionLimit = null)
{ {
// If partitioning is disabled or there are fewer messages in chat log than the limit - process it without partitioning // If partitioning is disabled or there are fewer messages in chat log than the limit - process it without partitioning
if (partitionLimit == null || partitionLimit <= 0 || chatLog.Messages.Count <= partitionLimit) if (partitionLimit == null || partitionLimit <= 0 || chatLog.Messages.Count <= partitionLimit)
{ {
ExportChatLogSingle(chatLog, filePath, format); await ExportChatLogSingleAsync(chatLog, filePath, format);
} }
// Otherwise split into partitions and export separately // Otherwise split into partitions and export separately
else else
@ -100,7 +100,7 @@ namespace DiscordChatExporter.Core.Services
.Select(g => new ChatLog(chatLog.Guild, chatLog.Channel, chatLog.From, chatLog.To, g, chatLog.Mentionables)) .Select(g => new ChatLog(chatLog.Guild, chatLog.Channel, chatLog.From, chatLog.To, g, chatLog.Mentionables))
.ToArray(); .ToArray();
ExportChatLogPartitioned(partitions, filePath, format); await ExportChatLogPartitionedAsync(partitions, filePath, format);
} }
} }
} }

@ -278,7 +278,7 @@ namespace DiscordChatExporter.Gui.ViewModels
dialog.From, dialog.To, operation); dialog.From, dialog.To, operation);
// Export // Export
_exportService.ExportChatLog(chatLog, filePath, dialog.SelectedFormat, await _exportService.ExportChatLogAsync(chatLog, filePath, dialog.SelectedFormat,
dialog.PartitionLimit); dialog.PartitionLimit);
// Notify completion // Notify completion

Loading…
Cancel
Save