add UserStore + RoleStore

This commit is contained in:
2020-04-14 20:16:04 +02:00
parent c45001fcd2
commit 3f0452fa56
24 changed files with 893 additions and 762 deletions
@@ -0,0 +1,52 @@
using Raven.Client.Documents;
using Raven.Client.Documents.Operations.CompareExchange;
using System;
using System.Threading.Tasks;
namespace zero.Core.Extensions
{
public static class DocumentStoreExtensions
{
/// <summary>
/// Reserves a key cluster-wide
/// </summary>
public static async Task<bool> ReserveAsync(this IDocumentStore store, string key, string value = null)
{
if (String.IsNullOrWhiteSpace(key))
{
return false;
}
if (value == null)
{
value = key;
}
var operation = new PutCompareExchangeValueOperation<string>(key, value, 0);
CompareExchangeResult<string> result = await store.Operations.SendAsync(operation).ConfigureAwait(false);
return result.Successful;
}
/// <summary>
/// Removes a cluster-wide key reservation
/// </summary>
public static async Task<bool> RemoveReservationAsync(this IDocumentStore store, string key)
{
if (!String.IsNullOrWhiteSpace(key))
{
return false;
}
CompareExchangeValue<string> readResult = store.Operations.Send(new GetCompareExchangeValueOperation<string>(key));
if (readResult == null)
{
return false;
}
DeleteCompareExchangeValueOperation<string> operation = new DeleteCompareExchangeValueOperation<string>(key, readResult.Index);
CompareExchangeResult<string> result = await store.Operations.SendAsync(operation).ConfigureAwait(false);
return result.Successful;
}
}
}