/// <summary> /// Supply conversion from <see cref="string"/> to <seealso cref="Base64Id"/> otherwise use default implementation. /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value"></param> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { return(Base64Id.Parse((string)value)); } return(base.ConvertFrom(context, culture, value)); }
/// <inheritdoc/> public async Task <ILockLease> Renew(string name, string leaseId, CancellationToken cancellationToken = default) { var base64Id = Base64Id.Parse(leaseId); bool success; try { var affecterRows = await _dbContext.Database.ExecuteSqlRawAsync(_queryDescriptor.RenewLease, new List <object> { base64Id.Id }, cancellationToken); success = affecterRows > 0; } catch (SqlException) { await Cleanup(); success = false; } if (!success) { throw new LockManagerException($"Unable to renew lease {name} for leaseid {leaseId}."); } return(new LockLease(base64Id, name, this)); }
/// <inheritdoc/> public async Task ReleaseLock(ILockLease @lock) { var query = @"DELETE FROM [work].[Lock] WHERE ([Name] = {0} AND [Id] < {1}) OR [ExpirationDate] < GetDate();"; await _dbContext.Database.ExecuteSqlRawAsync(query, @lock.Name, Base64Id.Parse(@lock.LeaseId).Id); }
/// <inheritdoc/> public async Task ReleaseLock(ILockLease @lock) => await _dbContext.Database.ExecuteSqlRawAsync(_queryDescriptor.ReleaseLock, @lock.Name, Base64Id.Parse(@lock.LeaseId).Id);