BirthdayBot/Data/OperationStatus.cs
Noi ddcde10e09 First commit for C# rewrite
All existing VB code was 'translated' to C# as closely as possible, with
minor changes and additional notes. Currently untested and likely
broken.
Further commits will go toward making overall improvements until this
version replaces the currently existing code.
2020-04-02 11:38:26 -07:00

64 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace BirthdayBot.Data
{
/// <summary>
/// Holds information regarding the previous updating information done on a guild including success/error information.
/// </summary>
class OperationStatus
{
private readonly Dictionary<OperationType, string> _log = new Dictionary<OperationType, string>();
public DateTimeOffset Timestamp { get; }
public OperationStatus (params (OperationType, string)[] statuses)
{
Timestamp = DateTimeOffset.UtcNow;
foreach (var status in statuses)
{
_log[status.Item1] = status.Item2;
}
}
/// <summary>
/// Prepares known information in a displayable format.
/// </summary>
public string GetDiagStrings()
{
var report = new StringBuilder();
foreach (OperationType otype in Enum.GetValues(typeof(OperationType)))
{
var prefix = $"`{Enum.GetName(typeof(OperationType), otype)}`: ";
string info = null;
if (!_log.TryGetValue(otype, out info))
{
report.AppendLine(prefix + "No data");
continue;
}
if (info == null)
{
report.AppendLine(prefix + "Success");
}
else
{
report.AppendLine(prefix + info);
}
}
return report.ToString();
}
/// <summary>
/// Specifies the type of operation logged. These enum values are publicly displayed in the specified order.
/// </summary>
public enum OperationType
{
UpdateBirthdayRoleMembership,
SendBirthdayAnnouncementMessage
}
}
}