From 067c8f5824f20cc2fc0fcfdf90c9289f176db854 Mon Sep 17 00:00:00 2001 From: Harrison Deng Date: Wed, 31 Mar 2021 15:37:40 -0500 Subject: [PATCH] Restructured untested persistence system. No longer conforming to C# dictionary format. Caught bug in untested persistence system. --- .../Games/GameServiceManager.cs | 12 +- ...uleDictionary.cs => GameServiceModules.cs} | 4 +- .../Persistence/IPersistent.cs | 14 + ...ntDictionary.cs => IReadOnlyPersistent.cs} | 12 +- .../IReadOnlyPersistentDictionary.cs | 19 - src/GameServiceWarden.Core/UMLSketch.drawio | 348 +++++++++--------- .../Modules/Games/FakePersistentDictionary.cs | 22 +- 7 files changed, 215 insertions(+), 216 deletions(-) rename src/GameServiceWarden.Core/Persistence/{GameServiceModuleDictionary.cs => GameServiceModules.cs} (95%) create mode 100644 src/GameServiceWarden.Core/Persistence/IPersistent.cs rename src/GameServiceWarden.Core/Persistence/{IPersistentDictionary.cs => IReadOnlyPersistent.cs} (55%) delete mode 100644 src/GameServiceWarden.Core/Persistence/IReadOnlyPersistentDictionary.cs diff --git a/src/GameServiceWarden.Core/Games/GameServiceManager.cs b/src/GameServiceWarden.Core/Games/GameServiceManager.cs index fc4c33c..deb9356 100644 --- a/src/GameServiceWarden.Core/Games/GameServiceManager.cs +++ b/src/GameServiceWarden.Core/Games/GameServiceManager.cs @@ -9,10 +9,10 @@ namespace GameServiceWarden.Core.Games public class GameServiceManager { private readonly IDictionary running; - private readonly IPersistentDictionary services; - private readonly IReadOnlyPersistentDictionary> modules; + private readonly IPersistent services; + private readonly IReadOnlyPersistent> modules; - public GameServiceManager(IPersistentDictionary services, IReadOnlyPersistentDictionary> modules) + public GameServiceManager(IPersistent services, IReadOnlyPersistent> modules) { this.services = services; this.modules = modules; @@ -40,11 +40,9 @@ namespace GameServiceWarden.Core.Games return modules.Keys; } - public IReadOnlyCollection GetServiceNames() + public IEnumerable GetServiceNames() { - string[] names = new string[services.Count]; - services.Keys.CopyTo(names, 0); - return names; + return services.Keys; } public IEnumerable GetServiceOptions(string serviceName) diff --git a/src/GameServiceWarden.Core/Persistence/GameServiceModuleDictionary.cs b/src/GameServiceWarden.Core/Persistence/GameServiceModules.cs similarity index 95% rename from src/GameServiceWarden.Core/Persistence/GameServiceModuleDictionary.cs rename to src/GameServiceWarden.Core/Persistence/GameServiceModules.cs index e48feea..f195fbc 100644 --- a/src/GameServiceWarden.Core/Persistence/GameServiceModuleDictionary.cs +++ b/src/GameServiceWarden.Core/Persistence/GameServiceModules.cs @@ -8,13 +8,13 @@ using GameServiceWarden.ModuleAPI; namespace GameServiceWarden.Core.Persistence { - public class GameServiceModuleDictionary : IReadOnlyPersistentDictionary> + public class GameServiceModules : IReadOnlyPersistent> { private readonly string mapDirectory; private readonly GameServiceModuleLoader loader = new GameServiceModuleLoader(); - public GameServiceModuleDictionary(string mapDirectory) + public GameServiceModules(string mapDirectory) { this.mapDirectory = mapDirectory; } diff --git a/src/GameServiceWarden.Core/Persistence/IPersistent.cs b/src/GameServiceWarden.Core/Persistence/IPersistent.cs new file mode 100644 index 0000000..2a4073d --- /dev/null +++ b/src/GameServiceWarden.Core/Persistence/IPersistent.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using GameServiceWarden.Core.Games; + +namespace GameServiceWarden.Core.Persistence +{ + public interface IPersistent : IReadOnlyPersistent + { + new V this[string key] { get; set; } + + void Add(string key, V value); + void Clear(); + bool Remove(string key); + } +} \ No newline at end of file diff --git a/src/GameServiceWarden.Core/Persistence/IPersistentDictionary.cs b/src/GameServiceWarden.Core/Persistence/IReadOnlyPersistent.cs similarity index 55% rename from src/GameServiceWarden.Core/Persistence/IPersistentDictionary.cs rename to src/GameServiceWarden.Core/Persistence/IReadOnlyPersistent.cs index e53202b..6dc934f 100644 --- a/src/GameServiceWarden.Core/Persistence/IPersistentDictionary.cs +++ b/src/GameServiceWarden.Core/Persistence/IReadOnlyPersistent.cs @@ -1,13 +1,22 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using GameServiceWarden.ModuleAPI; namespace GameServiceWarden.Core.Persistence { - public interface IPersistentDictionary : IDictionary + public interface IReadOnlyPersistent : IEnumerable> { + V this[string key] { get; } + /// /// The directory for this dictionary to use. /// string MapDirectory { get; } + int Count { get; } + IEnumerable Values { get; } + IEnumerable Keys { get; } + + bool ContainsKey(string key); /// /// The path to the data representing a specific key. @@ -15,5 +24,6 @@ namespace GameServiceWarden.Core.Persistence /// The key to get the path for. /// A representing the key. string GetPathForKey(string key); + bool TryGetValue(string key, [MaybeNullWhen(false)] out V value); } } \ No newline at end of file diff --git a/src/GameServiceWarden.Core/Persistence/IReadOnlyPersistentDictionary.cs b/src/GameServiceWarden.Core/Persistence/IReadOnlyPersistentDictionary.cs deleted file mode 100644 index c76a07b..0000000 --- a/src/GameServiceWarden.Core/Persistence/IReadOnlyPersistentDictionary.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; - -namespace GameServiceWarden.Core.Persistence -{ - public interface IReadOnlyPersistentDictionary : IReadOnlyDictionary - { - /// - /// The directory for this dictionary to use. - /// - string MapDirectory { get; } - - /// - /// The path to the data representing a specific key. - /// - /// The key to get the path for. - /// A representing the key. - string GetPathForKey(string key); - } -} \ No newline at end of file diff --git a/src/GameServiceWarden.Core/UMLSketch.drawio b/src/GameServiceWarden.Core/UMLSketch.drawio index 3bd8474..3cf06e7 100644 --- a/src/GameServiceWarden.Core/UMLSketch.drawio +++ b/src/GameServiceWarden.Core/UMLSketch.drawio @@ -1,6 +1,6 @@ - + @@ -53,7 +53,7 @@ - + @@ -214,348 +214,348 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/tests/GameServiceWarden.Core.Tests/Modules/Games/FakePersistentDictionary.cs b/tests/GameServiceWarden.Core.Tests/Modules/Games/FakePersistentDictionary.cs index 4a2e40e..bca5123 100644 --- a/tests/GameServiceWarden.Core.Tests/Modules/Games/FakePersistentDictionary.cs +++ b/tests/GameServiceWarden.Core.Tests/Modules/Games/FakePersistentDictionary.cs @@ -2,11 +2,12 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; +using GameServiceWarden.Core.Games; using GameServiceWarden.Core.Persistence; namespace GameServiceWarden.Core.Tests.Modules { - public class FakePersistentDictionary : IPersistentDictionary, IReadOnlyPersistentDictionary + public class FakePersistentDictionary : IPersistent { private IDictionary backing = new Dictionary(); public V this[string key] { get { return backing[key]; } set { backing[key] = value; } } @@ -21,9 +22,9 @@ namespace GameServiceWarden.Core.Tests.Modules public bool IsReadOnly { get { return false; } } - IEnumerable IReadOnlyDictionary.Keys { get { return backing.Keys; } } + IEnumerable IReadOnlyPersistent.Values => backing.Values; - IEnumerable IReadOnlyDictionary.Values { get { return backing.Values; } } + IEnumerable IReadOnlyPersistent.Keys => backing.Keys; public void Add(string key, V value) { @@ -35,26 +36,21 @@ namespace GameServiceWarden.Core.Tests.Modules backing.Add(item); } + public void Add(string key, GameServiceInfo value) + { + throw new System.NotImplementedException(); + } + public void Clear() { backing.Clear(); } - public bool Contains(KeyValuePair item) - { - return backing.Contains(item); - } - public bool ContainsKey(string key) { return backing.ContainsKey(key); } - public void CopyTo(KeyValuePair[] array, int arrayIndex) - { - backing.CopyTo(array, arrayIndex); - } - public IEnumerator> GetEnumerator() { return backing.GetEnumerator();