private DistributedLock MapDistributedLock(SqlDataReader reader) { var result = new DistributedLock(); if (reader[nameof(result.DistributedLockId)] == null) { return(null); } result.DistributedLockId = reader["DistributedLockId"] as string; result.LockedByLockingId = reader["LockingId"] as Guid?; result.LockDate = reader["LockDate"] as DateTime?; result.ExpiryDate = reader["ExpiryDate"] as DateTime?; return(result); }
/// <summary> /// Unlocks the specified distributed lock, freeing it up /// for other processes to use. /// </summary> /// <param name="distributedLock"> /// The distributed lock entry to unlock. This should be the instance /// you received from a call to the LockAsync method. /// </param> public Task UnlockAsync(DistributedLock distributedLock) { if (distributedLock == null) { throw new ArgumentNullException(nameof(distributedLock)); } var sql = @" update Cofoundry.DistributedLock set LockingId = null, LockDate = null, ExpiryDate = null where LockingId = @LockingId and DistributedLockId = @DistributedLockId "; return(_db.ExecuteAsync(sql, new SqlParameter("LockingId", distributedLock.LockedByLockingId), new SqlParameter("DistributedLockId", distributedLock.DistributedLockId) )); }