private void ExecuteAsync(object state)
        {
            var now = DateTime.Now;

            var lockables = lockableService.Query()
                            .Where(l => l.Locks.Any(_l => _l.MaxLeaseDate <= now))
                            .ToList();

            if (lockables.Any())
            {
                foreach (var lockable in lockables)
                {
                    var tasks        = new List <Task>();
                    var overDueLocks = lockable.Locks
                                       .Where(l => l.MaxLeaseDate >= now)
                                       .ToList();

                    // Remove over due locks.
                    foreach (var overDueLock in overDueLocks)
                    {
                        var _overDueLock = overDueLock;

                        tasks.Add(
                            new Task(() => lockableService.UnlockAsync(
                                         lockable,
                                         _overDueLock.Id)));
                    }
                }
            }
        }
Exemple #2
0
        public async Task <ActionResult <UnlockResponse> > Unlock(
            [FromBody] BaseRequest <UnlockRequest> unlockRequest)
        {
            var lockable = await lockablesService.RetrieveAsync(
                l => l.Id,
                unlockRequest.Data.LockableId);

            if (lockable == null)
            {
                return(NotFound());
            }

            var result = await lockablesService.UnlockAsync(
                lockable,
                unlockRequest.Data.LockId);

            return(result);
        }