blob: 64d35b9baa4d7f7288d11deeb8e557d03a0b5c93 (
plain)
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
|
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;
}
}
}
|