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 | a341819711cda358652ad84b1e507d9559ecabfd (patch) | |
tree | d9bdde02e39f03612e53818fdab536f35836ff4c /BackEnd/Timeline/Services/Data/DataManagerExtensions.cs | |
parent | 436b9fc40c09f89e90bcf6abf84dec562ad14230 (diff) | |
download | timeline-a341819711cda358652ad84b1e507d9559ecabfd.tar.gz timeline-a341819711cda358652ad84b1e507d9559ecabfd.tar.bz2 timeline-a341819711cda358652ad84b1e507d9559ecabfd.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;
+ }
+ }
+}
|