Example #1
0
        public async Task ToggleLockAsync(string id, string reason)
        {
            if (!IdToLock.TryGetValue(id, out Lock @lock))
            {
                throw new ArgumentException("Unknown id", nameof(id));
            }

            await @lock.Semaphore.WaitAsync();

            try
            {
                @lock.Timeout = null;
                LockState newState = await ToggleAsync(@lock, reason);

                await DbSemaphore.WaitAsync();

                try
                {
                    await UpdateLockDto(id, newState, null);
                }
                finally
                {
                    DbSemaphore.Release();
                }
            }
            finally
            {
                @lock.Semaphore.Release();
            }
            await UpdateTimerAsync();
        }
Example #2
0
        public async Task SetLockAsync(string id, LockState state, string reason, DateTime?timeout = null)
        {
            if (!IdToLock.TryGetValue(id, out Lock @lock))
            {
                throw new ArgumentException("Unknown id", nameof(id));
            }

            await @lock.Semaphore.WaitAsync();

            try
            {
                @lock.Timeout = timeout;
                await SetAsync(@lock, state, reason);

                await DbSemaphore.WaitAsync();

                try
                {
                    await UpdateLockDto(id, state, timeout);
                }
                finally
                {
                    DbSemaphore.Release();
                }
            }
            finally
            {
                @lock.Semaphore.Release();
            }
            await UpdateTimerAsync();
        }