private CompareExchangeValue <string>?GetEmailReservation(string email) { var key = Conventions.CompareExchangeKeyFor(email); var getReservation = new GetCompareExchangeValueOperation <string>(key); return(docStore.Operations.Send(getReservation)); }
/// <inheritdoc /> public async Task <TUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken) { var getReq = new GetCompareExchangeValueOperation <string>(GetCompareExchangeKeyFromEmail(normalizedEmail)); var idResult = await DbSession.Advanced.DocumentStore.Operations.SendAsync(getReq, token: cancellationToken); if (idResult == null) { #pragma warning disable 8603 return(null); #pragma warning restore 8603 } return(await DbSession.LoadAsync <TUser>(idResult.Value, cancellationToken)); }
public IActionResult Run(RunParams runParams) { string cmpXchgKey = runParams.CmpXchgKey ?? "*****@*****.**"; string cmpXchgValue = runParams.CmpXchgValue ?? "employee/1-A"; string result = null; #region Demo #region Step_1 var putCmpXchgOperation = new PutCompareExchangeValueOperation <string>(cmpXchgKey, cmpXchgValue, 0); CompareExchangeResult <string> putCmpXchgResult = DocumentStoreHolder.Store.Operations.Send(putCmpXchgOperation); #endregion #region Step_2 var success = putCmpXchgResult.Successful; var putValue = putCmpXchgResult.Value; var putVersion = putCmpXchgResult.Index; if (success == false) { result = "Key already exists"; } #endregion #region Step_3 var getCmpXchgOperation = new GetCompareExchangeValueOperation <string>(cmpXchgKey); CompareExchangeValue <string> getCmpXchgResult = DocumentStoreHolder.Store.Operations.Send(getCmpXchgOperation); #endregion #region Step_4 var key = getCmpXchgResult.Key; var currentValue = getCmpXchgResult.Value; var currentValueVersion = getCmpXchgResult.Index; var currentMetadata = getCmpXchgResult.Metadata; #endregion #endregion result = result ?? $"Created a new Compare-Exchange Key: {key}, Value: {currentValue}, Value Version: {currentValueVersion}"; return(Ok(result)); }
/// <inheritdoc /> public async Task <TUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); if (string.IsNullOrEmpty(normalizedUserName)) { throw new ArgumentNullException(nameof(normalizedUserName)); } var compareExchangeKey = GetCompareExchangeKeyFromEmail(normalizedUserName); var getEmailReservationOperation = new GetCompareExchangeValueOperation <string>(compareExchangeKey); var emailReservationResultOrNull = await DbSession.Advanced.DocumentStore.Operations.SendAsync(getEmailReservationOperation); var userId = emailReservationResultOrNull?.Value; if (string.IsNullOrEmpty(userId)) { return(null); } cancellationToken.ThrowIfCancellationRequested(); return(await FindByIdAsync(userId, cancellationToken)); }