diff options
author | crupest <crupest@outlook.com> | 2021-04-27 18:22:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-27 18:22:57 +0800 |
commit | deb02d10e6139bb74a63343e2a8b70fee11bec22 (patch) | |
tree | 160b7a2691786bfad8decbeeabe5fa1e09a876f3 /BackEnd/Timeline/Services/Data/DataManagerExtensions.cs | |
parent | 956306bf47db6495386945c2dbfe623cf48b185a (diff) | |
download | timeline-deb02d10e6139bb74a63343e2a8b70fee11bec22.tar.gz timeline-deb02d10e6139bb74a63343e2a8b70fee11bec22.tar.bz2 timeline-deb02d10e6139bb74a63343e2a8b70fee11bec22.zip |
refactor: Refactor data services.
Diffstat (limited to 'BackEnd/Timeline/Services/Data/DataManagerExtensions.cs')
-rw-r--r-- | BackEnd/Timeline/Services/Data/DataManagerExtensions.cs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs b/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs new file mode 100644 index 00000000..64d35b9b --- /dev/null +++ b/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs @@ -0,0 +1,26 @@ +using System;
+using System.Threading.Tasks;
+
+namespace Timeline.Services.Data
+{
+ public static class DataManagerExtensions
+ {
+ /// <summary>
+ /// Try to get an entry and throw <see cref="DatabaseCorruptedException"/> if not exist.
+ /// </summary>
+ public static async Task<byte[]> GetEntryAndCheck(this IDataManager dataManager, string tag, string notExistMessage)
+ {
+ if (dataManager is null)
+ throw new ArgumentNullException(nameof(dataManager));
+ if (tag is null)
+ throw new ArgumentNullException(nameof(tag));
+ if (notExistMessage is null)
+ throw new ArgumentNullException(nameof(notExistMessage));
+
+ var data = await dataManager.GetEntry(tag);
+ if (data is null)
+ throw new DatabaseCorruptedException(string.Format(Resource.GetEntryAndCheckNotExist, tag, notExistMessage));
+ return data;
+ }
+ }
+}
|