public Task ReleaseLockAsync(IdGeneratorState idGeneratorState, Guid sessionId)
 {
     if (idGeneratorState.IsLocked)
     {
         throw new Exception("Cannot release lock for state that is still locked");
     }
     return(idGeneratorStateCollection.ReplaceOneAsync(
                x => x.DataType == idGeneratorState.DataType && x.LockSessionId == sessionId,
                idGeneratorState));
 }
        private async Task ReleaseLockAsync(IdGeneratorState idGeneratorState)
        {
            if (!idGeneratorState.IsLocked)
            {
                return;
            }
            var sessionId = idGeneratorState.LockSessionId.Value;

            idGeneratorState.Unlock(sessionId);
            await idGeneratorStateRepository.ReleaseLockAsync(idGeneratorState, sessionId);
        }
        public async Task <bool> TryGetLockAsync(IdGeneratorState idGeneratorState)
        {
            if (!idGeneratorState.IsLocked)
            {
                throw new Exception("Cannot get lock for state that is not locked");
            }
            var replaceResult = await idGeneratorStateCollection.ReplaceOneAsync(
                x => x.DataType == idGeneratorState.DataType && !x.IsLocked,
                idGeneratorState,
                new ReplaceOptions { IsUpsert = true });

            return(replaceResult.IsAcknowledged && replaceResult.ModifiedCount == 1);
        }