From be59588351802ed57e9a49812634270543e03d4f Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sun, 18 Jun 2023 15:22:32 +0200 Subject: [PATCH] improve standard format by adding date range and tool version --- EliteBGS/DiscordLogGenerator.cs | 42 ++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/EliteBGS/DiscordLogGenerator.cs b/EliteBGS/DiscordLogGenerator.cs index 3187e53..b155a49 100644 --- a/EliteBGS/DiscordLogGenerator.cs +++ b/EliteBGS/DiscordLogGenerator.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Collections.Generic; using System.Text; using EliteBGS.LogGenerator; +using System.Reflection; +using System.Runtime.CompilerServices; namespace EliteBGS; @@ -23,6 +25,37 @@ public class DiscordLogGenerator { new SearchAndRescueFormat(), }; + protected virtual string GetToolVersion() { + Version v = Assembly.GetCallingAssembly().GetName().Version; + string ver; + if (v == null) { + ver = "v?.?.?"; + } else { + ver = "v" + v.ToString(3); + } + return string.Format("EliteBGS {0}", ver); + } + + protected virtual DateTime GetDateOfEarliestEntry(Objective objective) { + return objective + .Transactions + .SelectMany(x => x.Entries) + .OrderBy(x => x.Timestamp) + .First() + .Timestamp + ; + } + + protected virtual DateTime GetDateOfLatestEntry(Objective objective) { + return objective + .Transactions + .SelectMany(x => x.Entries) + .OrderByDescending(x => x.Timestamp) + .First() + .Timestamp + ; + } + protected virtual string GenerateSummary(Objective objective) { StringBuilder sb = new StringBuilder(); @@ -76,7 +109,14 @@ public class DiscordLogGenerator { string summary = GenerateSummary(objective); - log.AppendFormat("**Date:** {0}\n", DateTime.Now.ToString("dd/MM/yyyy")); + log.AppendFormat("**Log Generated:** {0} by {1}\n", + DateTime.Now.ToString("dd/MM/yyyy"), + GetToolVersion() + ); + log.AppendFormat("**Date:** {0} - {1}\n", + GetDateOfEarliestEntry(objective), + GetDateOfLatestEntry(objective) + ); log.AppendFormat("**Target:** {0}\n", location); if (!string.IsNullOrEmpty(summary)) { log.AppendFormat("**Summary**: {0}\n", summary);