public async Task <SendMessageResponse <TResponse> > SendAsync <TResponse>( IEnumerable <string> destinations, string text, SendOptions options = null) { options = options ?? new SendOptions(); var readyClientIds = this.GetReadyClientIds(); destinations = await this.DefaultClient.ProcessDestinationManyAsync(destinations); try { var responseChannel = Channel.CreateBounded <TResponse>(1); var timeoutChannel = Channel.CreateBounded <TResponse>(1); var resultTasks = readyClientIds.Select(clientId => this.SendWithClientAsync( clientId, destinations, text, options, responseChannel, timeoutChannel)); return(await HandleSendMessageTasksAsync(resultTasks, options, responseChannel, timeoutChannel)); } catch (Exception e) { return(new SendMessageResponse <TResponse> { ErrorMessage = "failed to send with any client" }); } }
public SendMessageResponse <TResponse> SendAsync <TResponse>( string destination, byte[] data, SendOptions options = null) { options = options ?? new SendOptions(); var readyClientIds = this.GetReadyClientIds(); destination = this.DefaultClient.ProcessDestinationAsync(destination); try { var responseChannel = Channel.CreateBounded <TResponse>(1); var timeoutChannel = Channel.CreateBounded <TResponse>(1); var resultTasks = readyClientIds.Select(clientId => this.SendWithClientAsync( clientId, destination, data, options, responseChannel, timeoutChannel)); return(HandleSendMessageTasksAsync(resultTasks, options, responseChannel, timeoutChannel)); } catch (Exception e) { return(new SendMessageResponse <TResponse> { ErrorMessage = "failed to send with any client" }); } }
public Task <string> SubscribeAsync( string topic, int duration, string identifier, string meta, TransactionOptions options = null) { options = options ?? new TransactionOptions(); return(RpcClient.Subscribe(topic, duration, identifier, meta, this, options)); }
public async Task <SendMessageResponse <byte[]> > PublishAsync( string topic, byte[] data, PublishOptions options = null) { options = options ?? new PublishOptions(); options.NoReply = true; var subscribers = await this.GetAllSubscribersAsync(topic, options); return(await this.SendAsync <byte[]>(subscribers.ToList(), data)); }
public SendMessageResponse <byte[]> PublishAsync( string topic, string text, PublishOptions options = null) { options = options ?? new PublishOptions(); options.NoReply = true; var subscribers = this.GetAllSubscribersAsync(topic, options); return(this.SendAsync <byte[]>(subscribers.ToList(), text)); }
/// <summary> /// Dial a session to a remote NKN address. /// </summary> /// <param name="remoteAddress">The address to open session with</param> /// <param name="options">Session configuration options</param> /// <returns>The session object</returns> public async Task <Session> DialAsync(string remoteAddress, SessionOptions options = null) { options = options ?? new SessionOptions(); var dialTimeout = Ncp.Constants.DefaultInitialRetransmissionTimeout; var sessionId = PseudoRandom.RandomBytesAsHexString(Constants.SessionIdLength); var session = this.MakeSession(remoteAddress, sessionId, options); var sessionKey = Session.MakeKey(remoteAddress, sessionId); this.sessions.Add(sessionKey, session); await session.DialAsync(dialTimeout); return(session); }
public MultiClient(MultiClientOptions options = null) { options = options ?? new MultiClientOptions(); options.Identifier = options.Identifier ?? ""; this.options = options; this.InitializeClients(); this.key = this.DefaultClient.Key; this.Address = (string.IsNullOrWhiteSpace(options.Identifier) ? "" : options.Identifier + ".") + this.key.PublicKey; this.messageHandlers = new List <Func <MessageHandlerRequest, Task <object> > >(); this.sessionHandlers = new List <Func <Session, Task> >(); this.acceptedAddresses = new List <Regex>(); this.sessions = new ConcurrentDictionary <string, Session>(); this.messageCache = new MemoryCache("messageCache"); this.isReady = false; this.isClosed = false; }
public async Task <GetSubscribersResult> GetSubscribersAsync(string topic, PublishOptions options = null) { options = options ?? new PublishOptions(); foreach (var clientId in this.Clients.Keys) { if (string.IsNullOrEmpty(this.Clients[clientId].Wallet.Options.RpcServerAddress) == false) { try { var mergedOptions = this.Clients[clientId].Wallet.Options.MergeWith(options); return(await Wallet.Wallet.GetSubscribersAsync(topic, mergedOptions)); } catch (Exception) { } } } var walletOptions = WalletOptions.NewFrom(this.options).AssignFrom(options); return(await Wallet.Wallet.GetSubscribersAsync(topic, walletOptions)); }
public Task <string> UnsubscribeAsync(string topic, string identifier, TransactionOptions options = null) { options = options ?? new TransactionOptions(); return(RpcClient.Unsubscribe(topic, identifier, this, options)); }
public Task <string> DeleteNameAsync(string name, TransactionOptions options = null) { options = options ?? new TransactionOptions(); return(RpcClient.DeleteName(name, this, options)); }
public Task <string> TransferToAsync(string toAddress, decimal amount, TransactionOptions options = null) { options = options ?? new TransactionOptions(); return(RpcClient.TransferTo(toAddress, new Amount(amount), this, options)); }
public string RegisterNameAsync(string name, TransactionOptions options = null) { options = options ?? new TransactionOptions(); return(RpcClient.RegisterName(name, this, options)); }