/// <summary> /// Subscribes this instance. /// </summary> public Task SubscribeAsync(CancellationToken cancellationToken) { Task.Delay(500, cancellationToken).ContinueWith(t => { var connection = _factory.GetConnection(cancellationToken); if (connection == null) { return; } connection.On <string>(nameof(IProviderHub.ProviderAdded), async scheme => { var definition = await _store.FindBySchemeAsync(scheme).ConfigureAwait(false); await _manager.AddAsync(definition).ConfigureAwait(false); }); connection.On <string>(nameof(IProviderHub.ProviderRemoved), async scheme => { await _manager.RemoveAsync(scheme).ConfigureAwait(false); }); connection.On <string>(nameof(IProviderHub.ProviderUpdated), async scheme => { var definition = await _store.FindBySchemeAsync(scheme).ConfigureAwait(false); await _manager.UpdateAsync(definition).ConfigureAwait(false); }); _factory.StartConnectionAsync(cancellationToken).ContinueWith(t => { }); }); return(Task.CompletedTask); }
/// <summary> /// Subscribes this instance. /// </summary> public void Subscribe() { Task.Delay(1000).ContinueWith(t => { var connection = _factory.GetConnection(); if (connection == null) { return; } connection.On <string>(nameof(IProviderHub.ProviderAdded), async scheme => { var definition = await _store.FindBySchemeAsync(scheme).ConfigureAwait(false); await _manager.AddAsync(definition).ConfigureAwait(false); }); connection.On <string>(nameof(IProviderHub.ProviderRemoved), async scheme => { await _manager.RemoveAsync(scheme).ConfigureAwait(false); }); connection.On <string>(nameof(IProviderHub.ProviderUpdated), async scheme => { var definition = await _store.FindBySchemeAsync(scheme).ConfigureAwait(false); await _manager.UpdateAsync(definition).ConfigureAwait(false); }); }); }
/// <summary> /// Subscribes this instance. /// </summary> public Task SubscribeAsync(CancellationToken cancellationToken) { Task.Delay(0, cancellationToken).ContinueWith(t => { var connection = _factory.GetConnection(cancellationToken); if (connection == null) { return; } connection.On <string>(nameof(IProviderHub.ProviderAdded), async scheme => { _logger.LogInformation($"SignalR notification received: {nameof(IProviderHub.ProviderAdded)}({scheme})"); var definition = await _store.FindBySchemeAsync(scheme).ConfigureAwait(false); await _manager.AddAsync(definition).ConfigureAwait(false); }); connection.On <string>(nameof(IProviderHub.ProviderRemoved), async scheme => { _logger.LogInformation($"SignalR notification received: {nameof(IProviderHub.ProviderRemoved)}({scheme})"); await _manager.RemoveAsync(scheme).ConfigureAwait(false); }); connection.On <string>(nameof(IProviderHub.ProviderUpdated), async scheme => { _logger.LogInformation($"SignalR notification received: {nameof(IProviderHub.ProviderUpdated)}({scheme})"); var definition = await _store.FindBySchemeAsync(scheme).ConfigureAwait(false); await _manager.UpdateAsync(definition).ConfigureAwait(false); }); connection.On <string, string>(nameof(IProviderHub.KeyRevoked), (kind, id) => { _logger.LogInformation($"SignalR notification received: {nameof(IProviderHub.KeyRevoked)}({kind}, {id})"); var keyId = Guid.Parse(id); if (kind == nameof(IAuthenticatedEncryptorDescriptor)) { _dataProtectionKeyManagerWrapper.Manager.RevokeKey(keyId, "Revoked by another instance."); return; } _signingKeyManagerWrapper.Manager.RevokeKey(keyId, "Revoked by another instance."); }); _factory.StartConnectionAsync(cancellationToken).ContinueWith(t => { }); }); return(Task.CompletedTask); }
/// <summary> /// Called when scheme change. /// </summary> /// <param name="change">The change.</param> /// <returns></returns> public async Task OnSchemeChange(SchemeChange change) { var definition = await _store.FindBySchemeAsync(change.Scheme); switch (change.Kind) { case SchemeChangeKind.Added: await _manager.AddAsync(definition); break; case SchemeChangeKind.Updated: await _manager.UpdateAsync(definition); break; case SchemeChangeKind.Deleted: await _manager.RemoveAsync(change.Scheme); break; } }