diff options
Diffstat (limited to 'BackEnd/Timeline/Services/Data')
4 files changed, 24 insertions, 8 deletions
diff --git a/BackEnd/Timeline/Services/Data/DataManager.cs b/BackEnd/Timeline/Services/Data/DataManager.cs index 9de17da3..6cf3225f 100644 --- a/BackEnd/Timeline/Services/Data/DataManager.cs +++ b/BackEnd/Timeline/Services/Data/DataManager.cs @@ -21,7 +21,7 @@ namespace Timeline.Services.Data _eTagGenerator = eTagGenerator;
}
- public async Task<string> RetainEntry(byte[] data, CancellationToken cancellationToken = default)
+ public async Task<string> RetainEntryAsync(byte[] data, CancellationToken cancellationToken = default)
{
if (data == null)
throw new ArgumentNullException(nameof(data));
@@ -56,7 +56,7 @@ namespace Timeline.Services.Data return tag;
}
- public async Task FreeEntry(string tag, CancellationToken cancellationToken = default)
+ public async Task FreeEntryAsync(string tag, CancellationToken cancellationToken = default)
{
if (tag == null)
throw new ArgumentNullException(nameof(tag));
@@ -87,7 +87,7 @@ namespace Timeline.Services.Data }
}
- public async Task<byte[]?> GetEntry(string tag, CancellationToken cancellationToken = default)
+ public async Task<byte[]?> GetEntryAsync(string tag, CancellationToken cancellationToken = default)
{
if (tag == null)
throw new ArgumentNullException(nameof(tag));
diff --git a/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs b/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs index 64d35b9b..d149f3fa 100644 --- a/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs +++ b/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs @@ -1,4 +1,5 @@ using System;
+using System.Threading;
using System.Threading.Tasks;
namespace Timeline.Services.Data
@@ -8,7 +9,7 @@ namespace Timeline.Services.Data /// <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)
+ public static async Task<byte[]> GetEntryAndCheck(this IDataManager dataManager, string tag, string notExistMessage, CancellationToken cancellationToken = default)
{
if (dataManager is null)
throw new ArgumentNullException(nameof(dataManager));
@@ -17,7 +18,7 @@ namespace Timeline.Services.Data if (notExistMessage is null)
throw new ArgumentNullException(nameof(notExistMessage));
- var data = await dataManager.GetEntry(tag);
+ var data = await dataManager.GetEntryAsync(tag, cancellationToken);
if (data is null)
throw new DatabaseCorruptedException(string.Format(Resource.GetEntryAndCheckNotExist, tag, notExistMessage));
return data;
diff --git a/BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs b/BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs new file mode 100644 index 00000000..2717e63c --- /dev/null +++ b/BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
+namespace Timeline.Services.Data
+{
+ public static class DataServicesServiceCollectionExtensions
+ {
+ public static IServiceCollection AddDataServices(this IServiceCollection services)
+ {
+ services.TryAddScoped<IETagGenerator, ETagGenerator>();
+ services.TryAddScoped<IDataManager, DataManager>();
+ return services;
+ }
+ }
+}
diff --git a/BackEnd/Timeline/Services/Data/IDataManager.cs b/BackEnd/Timeline/Services/Data/IDataManager.cs index 6a87c1b2..4191367e 100644 --- a/BackEnd/Timeline/Services/Data/IDataManager.cs +++ b/BackEnd/Timeline/Services/Data/IDataManager.cs @@ -23,7 +23,7 @@ namespace Timeline.Services.Data /// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The tag of the created entry.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="data"/> is null.</exception>
- public Task<string> RetainEntry(byte[] data, CancellationToken cancellationToken = default);
+ public Task<string> RetainEntryAsync(byte[] data, CancellationToken cancellationToken = default);
/// <summary>
/// Decrease the the ref count of the entry.
@@ -35,7 +35,7 @@ namespace Timeline.Services.Data /// <remarks>
/// It's no-op if entry with tag does not exist.
/// </remarks>
- public Task FreeEntry(string tag, CancellationToken cancellationToken = default);
+ public Task FreeEntryAsync(string tag, CancellationToken cancellationToken = default);
/// <summary>
/// Retrieve the entry with given tag. If not exist, returns null.
@@ -44,6 +44,6 @@ namespace Timeline.Services.Data /// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The data of the entry. If not exist, returns null.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="tag"/> is null.</exception>
- public Task<byte[]?> GetEntry(string tag, CancellationToken cancellationToken = default);
+ public Task<byte[]?> GetEntryAsync(string tag, CancellationToken cancellationToken = default);
}
}
|