private async Task <ChannelCredentials> FindAndUpdateCurrentIndexAsync(Seed seed, int index) { while (true) { var subSeed = new Seed(Converter.TritsToTrytes(this.SigningHelper.GetSubseed(seed, index))); var channelSeed = new Seed((await this.AddressGenerator.GetAddressAsync(subSeed, SecurityLevel.Low, ChannelSeedIndex)).Value); var channelKey = (await this.AddressGenerator.GetAddressAsync(subSeed, SecurityLevel.Low, ChannelKeyIndex)).Value; var rootHash = CurlMerkleTreeFactory.Default.Create(channelSeed, 0, 1, IotaFhirRepository.SecurityLevel).Root.Hash; var credentials = new ChannelCredentials { Seed = channelSeed, ChannelKey = channelKey, RootHash = rootHash }; // Check if the index was used by another application. If not, return the corresponding channel credentials var subscription = this.SubscriptionFactory.Create(rootHash, Mode.Restricted, channelKey, true); var message = await subscription.FetchSingle(rootHash); if (message == null) { await this.SetCurrentSubSeedIndexAsync(seed, index); await this.ImportChannelWriteAccessAsync(credentials); return(credentials); } await this.ImportChannelWriteAccessAsync(credentials); SubscriptionAdded?.Invoke(this, new SubscriptionAddedEventArgs(rootHash.Value.Substring(0, 64), seed)); // The index is already in use. Increment by one and check that in the next round of the loop index++; } }
public void Subscribe <TEvent>(Action <TEvent> handler) where TEvent : Event { if (!_subscriptions.TryGetValue(typeof(TEvent), out var handlers)) { _subscriptions[typeof(TEvent)] = handlers = new HashSet <Handler>(); } handlers.Add(new Handler(item => handler.Invoke((TEvent)item))); SubscriptionAdded?.Invoke(typeof(TEvent), Array.Empty <IEventFilter>()); }
public void Subscribe <TEvent>(Action <TEvent> handler, IEnumerable <IEventFilter> filters) where TEvent : Event { if (!_subscriptions.TryGetValue(typeof(TEvent), out var handlers)) { _subscriptions[typeof(TEvent)] = handlers = new HashSet <Handler>(); } filters = filters.ToArray(); handlers.Add(new Handler(item => handler.Invoke((TEvent)item), filters)); SubscriptionAdded?.Invoke(typeof(TEvent), filters); }
public Result <IDisposable> Subscribe(Identity identity, TSubscription subscription) { if (subscribed.ContainsKey(identity)) { return(Result.FailWith <IDisposable>(State.Forbidden, $"Subscriber already contains subscription {identity.Id}.")); } subscribed.Add(identity, subscription); SubscriptionAdded?.Invoke(this, new SubscriptionEventArgs <TSubscription>(identity, subscription)); return(Result.Ok(Disposable.For(() => { if (subscribed.ContainsKey(identity)) { subscribed.Remove(identity); SubscriptionRemoved?.Invoke(this, new SubscriptionEventArgs <TSubscription>(identity, subscription)); } }))); }
protected virtual void RaiseSubscriptionAdded(WampSubscriptionAddEventArgs e) { SubscriptionAdded?.Invoke(this, e); }
/// <summary> /// Event invocator for the <see cref="SubscriptionAdded"/> event /// </summary> /// <param name="subscription">The added subscription</param> private void OnSubscriptionAdded(Subscription subscription) { SubscriptionAdded?.Invoke(this, subscription); }
/// <summary> /// Raises the <see cref="E:SubscriptionAdded" /> event. /// </summary> /// <param name="e">The <see cref="SubscriptionEventArgs"/> instance containing the event data.</param> protected internal virtual void OnSubscriptionAdded(SubscriptionEventArgs e) { SubscriptionAdded?.Invoke(this, e); }
public void Subscribe(Subscription subscription) { _subscriptions.TryAdd(subscription.Topic, subscription); SubscriptionAdded?.Invoke(this, new SubscriptionEventArgs(subscription)); }