public async Task <Guid> StartWatchAsync( ReceivingAddressReservation address, PropertyAmount targetAmount, int targetConfirmation, TimeSpan timeout, TokenReceivingCallback callback, CancellationToken cancellationToken) { Rule rule; if (address == null) { throw new ArgumentNullException(nameof(address)); } if (address.ReleasedDate != null) { throw new ArgumentException("The reservation is already released.", nameof(address)); } if (!this.timerScheduler.IsValidDuration(timeout)) { throw new ArgumentOutOfRangeException(nameof(timeout), timeout, "The value is not valid."); } if (callback != null && callback.Completed) { throw new ArgumentException("The callback is already completed.", nameof(callback)); } await this.semaphore.WaitAsync(cancellationToken); try { if (this.stopped) { throw new InvalidOperationException("The watcher is already stopped."); } rule = new Rule(this.property, address, targetAmount, targetConfirmation, timeout, callback); await this.rules.AddAsync(rule, cancellationToken); StartTimer(rule, timeout); } finally { this.semaphore.Release(); } return(rule.Id); }
public Rule( PropertyId property, ReceivingAddressReservation addressReservation, PropertyAmount targetAmount, int targetConfirmation, TimeSpan originalTimeout, TokenReceivingCallback callback, Guid id) { if (property == null) { throw new ArgumentNullException(nameof(property)); } if (addressReservation == null) { throw new ArgumentNullException(nameof(addressReservation)); } if (targetAmount <= PropertyAmount.Zero) { throw new ArgumentOutOfRangeException( nameof(targetAmount), targetAmount, "The value is not a valid target amount."); } if (targetConfirmation < 1) { throw new ArgumentOutOfRangeException( nameof(targetConfirmation), targetConfirmation, "The value is not a valid target confirmation."); } if (originalTimeout < TimeSpan.Zero) { throw new ArgumentOutOfRangeException( nameof(originalTimeout), originalTimeout, "The value is not a valid timeout."); } Property = property; AddressReservation = addressReservation; TargetAmount = targetAmount; TargetConfirmation = targetConfirmation; OriginalTimeout = originalTimeout; Callback = callback; Id = id; }
public Rule( PropertyId property, ReceivingAddressReservation addressReservation, PropertyAmount targetAmount, int targetConfirmation, TimeSpan originalTimeout, TokenReceivingCallback callback) : this( property, addressReservation, targetAmount, targetConfirmation, originalTimeout, callback, Guid.NewGuid()) { }