using System;
using System.Threading.Tasks;
namespace Timeline.Services.Data
{
public static class DataManagerExtensions
{
///
/// Try to get an entry and throw if not exist.
///
public static async Task 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;
}
}
}