-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnumHelper.cs
More file actions
74 lines (70 loc) · 3.17 KB
/
EnumHelper.cs
File metadata and controls
74 lines (70 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Upsilon.Apps.Passkey.Core.Utils;
using Upsilon.Apps.Passkey.Interfaces.Enums;
namespace Upsilon.Apps.Passkey.GUI.WPF.Helper
{
internal static class EnumHelper
{
public static string ToReadableString(this ActivityEventType eventType)
{
return eventType switch
{
ActivityEventType.None => "All",
ActivityEventType.MergeAndSaveThenRemoveAutoSaveFile => "Auto-save merged then saved",
ActivityEventType.MergeWithoutSavingAndKeepAutoSaveFile => "Auto-save merged but not saved",
ActivityEventType.DontMergeAndRemoveAutoSaveFile => "Auto-save discarded",
ActivityEventType.DontMergeAndKeepAutoSaveFile => "Auto-save not merged and keeped",
ActivityEventType.DatabaseCreated
or ActivityEventType.DatabaseOpened
or ActivityEventType.DatabaseSaved
or ActivityEventType.DatabaseClosed
or ActivityEventType.LoginSessionTimeoutReached
or ActivityEventType.LoginFailed
or ActivityEventType.UserLoggedIn
or ActivityEventType.UserLoggedOut
or ActivityEventType.ImportingDataStarted
or ActivityEventType.ImportingDataSucceded
or ActivityEventType.ImportingDataFailed
or ActivityEventType.ExportingDataStarted
or ActivityEventType.ExportingDataSucceded
or ActivityEventType.ExportingDataFailed
or ActivityEventType.ItemUpdated
or ActivityEventType.ItemAdded
or ActivityEventType.ItemDeleted => eventType.ToString().ToSentenceCase(),
_ => throw new InvalidOperationException($"'{eventType}' event type not handled"),
};
}
public static ActivityEventType ActivityEventTypeFromReadableString(string readableString)
{
try
{
return Enum.GetValues<ActivityEventType>()
.Cast<ActivityEventType>()
.First(x => x.ToReadableString() == readableString);
}
catch
{
throw new InvalidOperationException($"'{readableString}' event type not handled");
}
}
public static string ToReadableString(this WarningType warningType)
{
return warningType switch
{
WarningType.PasswordUpdateReminderWarning | WarningType.PasswordLeakedWarning => "All",
WarningType.PasswordUpdateReminderWarning => "Expired passwords",
WarningType.PasswordLeakedWarning => "Leaked passwords",
_ => throw new InvalidOperationException($"'{warningType}' warning type not handled"),
};
}
public static WarningType ActivityWarningTypeFromReadableString(string readableString)
{
return readableString switch
{
"All" => WarningType.PasswordUpdateReminderWarning | WarningType.PasswordLeakedWarning,
"Expired passwords" => WarningType.PasswordUpdateReminderWarning,
"Leaked passwords" => WarningType.PasswordLeakedWarning,
_ => throw new InvalidOperationException($"'{readableString}' warning type not handled"),
};
}
}
}