public async Task <string> AddObserverAsync(TimeSpan lifetime, IErrorObserver observer) { try { _ = observer ?? throw new ArgumentNullException(nameof(observer)); string leaseKey = Guid.NewGuid().ToString(); State.ErrorLeases.Add(leaseKey, observer); State.LeaseExpiry.Add(leaseKey, new Tuple <DateTime, string>(DateTime.UtcNow.Add(lifetime), "Error")); leaseTimer ??= RegisterTimer(CheckLeaseExpiryAsync, null, TimeSpan.FromSeconds(10.0), TimeSpan.FromSeconds(60.0)); await WriteStateAsync(); return(await Task.FromResult(leaseKey)); } catch (Exception ex) { await logger?.LogErrorAsync(ex, "Subscription add error observer."); await NotifyErrorAsync(ex); throw; } }
/// <summary> /// Adds an error observer to the subscription. Used to observe errors in the subscription. /// </summary> /// <param name="subscriptionUriString">Unique URI that identifies the subscription.</param> /// <param name="lifetime">Lifetime of the lease.</param> /// <param name="observer">Observer to receive events.</param> /// <returns>A unique string for the lease key, which is used to renew or delete the observer's lease.</returns> public async Task <string> AddSubscriptionObserverAsync(string subscriptionUriString, TimeSpan lifetime, ErrorObserver observer) { IErrorObserver observerRef = await client.CreateObjectReference <IErrorObserver>(observer); ISubscription subscription = GetSubscription(subscriptionUriString); return(await subscription.AddObserverAsync(lifetime, observerRef)); }
/// <summary> /// Add an error observer to a resource. /// </summary> /// <param name="resourceUriString">Unique URI that identifies the resource.</param> /// <param name="lifetime">The lifetime of the lease.</param> /// <param name="observer">Error observer to receive events.</param> /// <returns>A unique string for the lease key, whic is used to refresh the lease for the observer.</returns> public async Task <string> AddResourceObserverAsync(string resourceUriString, TimeSpan lifetime, ErrorObserver observer) { IErrorObserver objRef = await client.CreateObjectReference <IErrorObserver>(observer); IPiSystem resource = GetPiSystem(resourceUriString); return(await resource.AddObserverAsync(lifetime, objRef)); }
public async Task <string> AddObserverAsync(TimeSpan lifetime, IErrorObserver observer) { if (observer == null) { Exception ex = new ArgumentNullException("resource error observer"); await NotifyErrorAsync(ex); return(await Task.FromResult <string>(null)); } string leaseKey = null; Exception error = null; try { leaseKey = Guid.NewGuid().ToString(); State.ErrorLeases.Add(leaseKey, observer); State.LeaseExpiry.Add(leaseKey, new Tuple <DateTime, string>(DateTime.UtcNow.Add(lifetime), "Error")); if (leaseTimer == null) { leaseTimer = RegisterTimer(CheckLeaseExpiryAsync, null, TimeSpan.FromSeconds(10.0), TimeSpan.FromSeconds(60.0)); } } catch (Exception ex) { error = ex; //GetLogger().Log(1002, Orleans.Runtime.Severity.Error, "Resource add error observer {0}", new object[] { State.Metadata.ResourceUriString }, ex); } if (error != null) { await NotifyErrorAsync(error); } return(await Task.FromResult <string>(leaseKey)); }
public async Task <string> AddObserverAsync(TimeSpan lifetime, IErrorObserver observer) { if (observer == null) { Exception ex = new ArgumentNullException("subscription error observer"); await NotifyErrorAsync(ex); return(await Task.FromResult <string>(null)); } string leaseKey = Guid.NewGuid().ToString(); State.ErrorLeases.Add(leaseKey, observer); State.LeaseExpiry.Add(leaseKey, new Tuple <DateTime, string>(DateTime.UtcNow.Add(lifetime), "Error")); if (leaseTimer == null) { leaseTimer = RegisterTimer(CheckLeaseExpiryAsync, null, TimeSpan.FromSeconds(10.0), TimeSpan.FromSeconds(60.0)); } await WriteStateAsync(); return(await Task.FromResult <string>(leaseKey)); }
public void Detach(IErrorObserver observer) { _observers.Remove(observer); }
public void Attach(IErrorObserver observer) { _observers.Add(observer); }