public RpcStreamingRequestResponseHandler(IStreamingClient client, string methodName) { MethodName = methodName; Client = client; Client.StreamingMessageReceived += RpcStreamingMessageResponseHandler; }
protected override void Cleanup() { if (_listener != null && _streamingClient != null) { _streamingClient.TearDownListener(_listener); } if (_listener != null) { _listener.Stop(); _listener.Dispose(); _listener = null; } if (_streamingClient != null) { _streamingClient.Dispose(); _streamingClient = null; } if (_client != null) { if (!string.IsNullOrEmpty(_client.Session)) _client.LogOut(); _client.Dispose(); _client = null; } }
public async Task HandleSubscription <T>( IStreamingClient client, RpcStreamingSubscriptionObservableHandler <T> subscription, Func <Task> subscribeFunc, Action <T> onNext, Func <Task> subscribeResponseFunc, CancellationToken cancellationToken) { subscription.GetSubscriptionDataResponsesAsObservable().Subscribe(onNext); var subscribed = false; subscription.GetSubscribeResponseAsObservable().Subscribe(async id => { subscribed = true; subscribeResponseFunc?.Invoke(); await _messagingService.SendLogMessage($"Subscribed ID: {id}"); }); subscription.GetUnsubscribeResponseAsObservable().Subscribe(async r => { subscribed = false; await _messagingService.SendLogMessage($"Unsubscribed result: {r}"); }); await client.StartAsync(); await subscribeFunc(); SpinWait.SpinUntil(() => subscribed && cancellationToken.IsCancellationRequested); await subscription.UnsubscribeAsync(); SpinWait.SpinUntil(() => !subscribed); }
public StreamingProtocolHandler(ILogger logger, IStreamingClient streamingClient) { _logger = logger; _streamingClient = streamingClient; _subscriptions = new ConcurrentDictionary <Request, IStreamingEventHandler>(); }
public static void Connect() { Console.WriteLine ("Connecting to CIAPI"); _rpcClient = new Client( new Uri(ConfigurationManager.AppSettings["Server"]), new Uri(ConfigurationManager.AppSettings["StreamingServer"]), ConfigurationManager.AppSettings["ApiKey"] ); _rpcClient.LogIn(ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]); _streamingClient = _rpcClient.CreateStreamingClient(); }
public static void Connect() { Console.WriteLine("Connecting to CIAPI"); _rpcClient = new Client( new Uri(ConfigurationManager.AppSettings["Server"]), new Uri(ConfigurationManager.AppSettings["StreamingServer"]), ConfigurationManager.AppSettings["ApiKey"]); _rpcClient.LogIn(ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]); _streamingClient = _rpcClient.CreateStreamingClient(); }
private void button2_Click(object sender, EventArgs e) { _rpcClient = new Client(new Uri(RpcUriTextBox.Text)); RpcClient.LogIn(UserNameTextBox.Text, PasswordTextBox.Text); _streamingClient = StreamingClientFactory.CreateStreamingClient(new Uri(StreamingUriTextBox.Text), UserNameTextBox.Text, RpcClient.Session); _streamingClient.Connect(); DialogResult = DialogResult.OK; }
public void ShouldThrowObjectDisposedException() { var client = this.BuildRpcClient(); client.LogIn(Settings.RpcUserName, Settings.RpcPassword); IStreamingClient streamingClient = client.CreateStreamingClient(); client.Dispose(); streamingClient.Dispose(); Assert.Throws(typeof(ObjectDisposedException), () => client.BeginLogIn("", "", a => { }, null), "async calls not guarded"); Assert.Throws(typeof(ObjectDisposedException), () => client.AccountInformation.GetClientAndTradingAccount(), "sync calls not guarded"); Assert.Throws(typeof(ObjectDisposedException), () => client.CreateStreamingClient(), "streaming client factory method not guarded"); Assert.Throws(typeof(ObjectDisposedException), () => streamingClient.BuildDefaultPricesListener(9), "streaming client listener factory method not guarded"); }
public void Dispose() { if (_newsListener != null) { _newsListener.Stop(); _newsListener = null; } if (_streamingClient != null) { _streamingClient.Disconnect(); _streamingClient = null; } if (_client != null) { _client.BeginLogOut(ar => _client.EndLogOut(ar), null); _client = null; } }
public EthApiService(IClient client, IStreamingClient streamingClient) : this(client, new TransactionManager(client)) { if (streamingClient == null) { _subscriptionService = new Lazy <EthSubscriptionService>(() => { throw new InvalidOperationException("Subscriptions require a streaming capable client to be configured"); }); } else { _subscriptionService = new Lazy <EthSubscriptionService>(() => { return(new EthSubscriptionService(streamingClient)); }); } }
private void BuildClients() { //Hook up a logger for the CIAPI.CS libraries LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat); Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client")); RpcClient = new Client(RpcUri, StreamingUri, "CI-WP7"); RpcClient.BeginLogIn(UerName, Password, ar => { try { RpcClient.EndLogIn(ar); //RpcClient.MagicNumberResolver.PreloadMagicNumbersAsync(); RpcClient.MagicNumberResolver.PreloadMagicNumbers(); ThreadPool.QueueUserWorkItem(_ => { Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners")); StreamingClient = RpcClient.CreateStreamingClient(); PriceListener = StreamingClient.BuildPricesListener(MarketId); PriceListener.MessageReceived += OnMessageReceived; Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info")); RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 => { Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2); Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info")); RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 => { Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation; Dispatcher.BeginInvoke(() => Button1.IsEnabled = true); }, null); }, null); }); } catch (Exception ex) { Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex)); } }, null); }
private void BuildClients() { //Hook up a logger for the CIAPI.CS libraries LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat); Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client")); RpcClient = new Client(RpcUri, StreamingUri, "CI-WP7"); RpcClient.BeginLogIn(UerName, Password, ar => { try { RpcClient.EndLogIn(ar); //RpcClient.MagicNumberResolver.PreloadMagicNumbersAsync(); RpcClient.MagicNumberResolver.PreloadMagicNumbers(); ThreadPool.QueueUserWorkItem(_ => { Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners")); StreamingClient = RpcClient.CreateStreamingClient(); PriceListener = StreamingClient.BuildPricesListener(MarketId); PriceListener.MessageReceived += OnMessageReceived; Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info")); RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 => { Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2); Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info")); RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 => { Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation; Dispatcher.BeginInvoke(() => Button1.IsEnabled = true); }, null); }, null); }); } catch (Exception ex) { Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex)); } }, null); }
/// <summary> /// Initializes a new instance of the <see cref="EventBus"/> class. /// </summary> /// <param name="streamingClient">The instance of <see cref="IStreamingClient"/> with connection to salesforce.</param> /// <param name="logger">The instance of <see cref="ILogger{SalesforceEventBus}"/>.</param> /// <param name="forceClient">The instance of <see cref="ForceClientProxy"/> to provide a publish functionality to the bus.</param> /// <param name="messageListeners"></param> /// <param name="options"></param> public EventBus( IStreamingClient streamingClient, ILogger <EventBus> logger, IResilientForceClient forceClient, IEnumerable <IMessageListener> messageListeners, IOptions <SalesforceConfiguration> options) { _streamingClient = streamingClient ?? throw new ArgumentNullException(nameof(streamingClient)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _forceClient = forceClient ?? throw new ArgumentNullException(nameof(forceClient)); _options = options.Value ?? throw new ArgumentNullException(nameof(options)); _messageListerners = messageListeners; _streamingClient.Reconnect += StreamingClient_Reconnect; _streamingClient.Handshake(); }
public override void Execute() { if (string.IsNullOrEmpty(ServerUrl)) throw new ApplicationException("StreamingLatencyMonitor: ServerUrl is not set"); lock (_sync) { if (_client == null) { _client = new Client(new Uri(ServerUrl), new Uri(StreamingServerUrl), "{API_KEY}", 1); _client.LogIn(UserName, Password); _streamingClient = _client.CreateStreamingClient(); _streamingStartTime = DateTime.UtcNow; _listener = _streamingClient.BuildPricesListener(MarketId); _listener.MessageReceived += OnPriceUpdate; } } }
private void BuildClients() { Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client")); RpcClient = new Client(RpcUri, StreamingUri, "CI-WP7"); RpcClient.BeginLogIn(UerName, Password, ar => { try { RpcClient.EndLogIn(ar); ThreadPool.QueueUserWorkItem(_ => { Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners")); StreamingClient = RpcClient.CreateStreamingClient(); PriceListener = StreamingClient.BuildPricesListener(MarketId); PriceListener.MessageReceived += OnMessageReceived; Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info")); RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 => { Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2); Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info")); RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 => { Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation; Dispatcher.BeginInvoke(() => Button1.IsEnabled = true); }, null); }, null); }); } catch (Exception ex) { Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex)); } }, null); }
public override async Task ExecuteAsync(IStreamingClient client) { var subscription = new EthNewBlockHeadersSubscription(client); await subscription.SendRequestAsync(Guid.NewGuid()); }
public abstract Task ExecuteAsync(IStreamingClient client);
public DemoCompressingController(IStreamingClient streamingClient) { _streamingClient = streamingClient; }
private void ToggleSubscribeButton_Click(object sender, RoutedEventArgs e) { if (ToggleSubscribeButtonlabel.Text == "Subscribe") { _rcpClient = new Rpc.Client(new Uri(RpcUriTextbox.Text)); var userName = UserNameTextbox.Text; var streamingUri = new Uri(StreamingUriTextbox.Text); var topic = TopicTextbox.Text; Log("Creating session..."); _rcpClient.BeginLogIn(userName, PasswordTextbox.Text, loginResult => { try { _rcpClient.EndLogIn(loginResult); _logger.DebugFormat("Session is: {0}", _rcpClient.SessionId); Log("Creating streaming client..."); _streamingClient = StreamingClientFactory.CreateStreamingClient(streamingUri, userName, _rcpClient.SessionId); _streamingClient.StatusChanged += (s, message) => Log(string.Format("Status update: {0}", message.Status)); _streamingClient.Connect(); Log("Listening to news stream..."); _newsListener = _streamingClient.BuildListener<NewsDTO>(topic); _newsListener.Start(); _newsListener.MessageRecieved += (s, message) => { try { NewsDTO recievedNewsHeadline = message.Data; Log( string.Format( "Recieved: NewsDTO: StoryId {0}, Headline {1}, PublishDate = {2}", recievedNewsHeadline.StoryId, recievedNewsHeadline.Headline, recievedNewsHeadline.PublishDate.ToString("u"))); } catch (Exception exception) { _logger.Error("Exception occured:", exception); } }; } catch (Exception exception) { _logger.Error("Exception occured:", exception); } }, null); ToggleSubscribeButtonlabel.Text = "Stop"; } else { try { Log("Stopping listening to news stream..."); // D: abbreviating conditionals makes it hard to step // and is also a good way to get bugs. you may notice that I always use // blocks. if (_newsListener != null) { _newsListener.Stop(); } Log("Disconnecting from streaming server..."); if (_streamingClient != null) { _streamingClient.Disconnect(); } Log("Deleting session..."); if (_rcpClient != null ) { // REMOVEME: i commented this out and still getting the ObjectDisposed exception // so it is not in the RpcClient _rcpClient.BeginLogOut(logoutResult => { // FIXME: id/session invalid - getting back LoggedOut: false /*do nothing*/ var breakTarget = 0; }, null); } } catch (Exception exception) { _logger.Error("Exception occured:", exception); } ToggleSubscribeButtonlabel.Text = "Subscribe"; } }
public EthApiContractService(IClient client, IStreamingClient streamingClient) : base(client, streamingClient) { }
protected RpcStreamingResponseParamsObservableHandler(IStreamingClient streamingClient, TRpcRequestResponseHandler rpcRequestResponseHandler) : base(streamingClient) { RpcRequestResponseHandler = rpcRequestResponseHandler; }
protected RpcStreamingSubscriptionHandler(IStreamingClient streamingClient, IUnsubscribeSubscriptionRpcRequestBuilder unsubscribeSubscriptionRpcRequestBuilder) { StreamingClient = streamingClient; UnsubscribeSubscriptionRpcRequestBuilder = unsubscribeSubscriptionRpcRequestBuilder; }
protected RpcStreamingSubscriptionEventResponseHandler(IStreamingClient streamingClient, IUnsubscribeSubscriptionRpcRequestBuilder unsubscribeSubscriptionRpcRequestBuilder) : base(streamingClient, unsubscribeSubscriptionRpcRequestBuilder) { }
public EthNewPendingTransactionSubscription(IStreamingClient client) : base(client, ApiMethods.eth_subscribe.ToString()) { }
public async Task ExecuteTestAsync(IStreamingClient client) { await ExecuteAsync(client); }
protected RpcStreamingRequestResponseHandler(IStreamingClient streamingClient) { StreamingClient = streamingClient; }
public Web3(IClient client, IStreamingClient streamingClient) : this(client) { StreamingClient = streamingClient; }
protected RpcStreamingResponseObservableHandler(IStreamingClient streamingClient) : base(streamingClient) { ResponseSubject = new Subject <TResponse>(); }
public EthNewSyncingSubscription(IStreamingClient client) : base(client, ApiMethods.eth_newFilter.ToString()) { }
public EthNewBlockHeadersSubscription(IStreamingClient client) : base(client, new EthUnsubscribeRequestBuilder()) { _ethNewBlockHeadersSubscriptionRequestBuilder = new EthNewBlockHeadersSubscriptionRequestBuilder(); }
public DemoStreamingController(IStreamingClient streamingClient) { _streamingClient = streamingClient; }
void SubscribeNewsUpdates(Action<NewsDTO> onUpdate, Action<Exception> onError) { _client = new Client(RPC_URI); _client.BeginLogIn(USERNAME, PASSWORD, ar => { try { _client.EndLogIn(ar); Debug.WriteLine("Login ok"); _streamingClient = StreamingClientFactory.CreateStreamingClient( STREAMING_URI, USERNAME, _client.SessionId); _streamingClient.Connect(); Debug.WriteLine("\r\n\r\n\r\n\r\n\r\nStreaming connected ok"); _newsListener = _streamingClient.BuildListener<NewsDTO>("NEWS.MOCKHEADLINES.UK"); _newsListener.MessageRecieved += (s, e) => { var msg = e.Data.Headline; Debug.WriteLine(msg); //onUpdate(e.Data); }; _newsListener.Start(); Debug.WriteLine("\r\n\r\n\r\n\r\n\r\nListener started ok"); } catch (Exception exc) { onError(exc); } }, null); }
public EthLogsObservableSubscription(IStreamingClient client) : base(client, new EthUnsubscribeRequestBuilder()) { _ethLogsSubscriptionRequestBuilder = new EthLogsSubscriptionRequestBuilder(); }
public EthNewBlockHeadersSubscription(IStreamingClient client) : base(client, ApiMethods.eth_subscribe.ToString()) { }
public EthGetBalanceObservableHandler(IStreamingClient streamingClient) : base(streamingClient, new EthGetBalance(null)) { }
public EthSyncingSubscription(IStreamingClient client) : base(client, new EthUnsubscribeRequestBuilder()) { _builder = new EthSyncingSubscriptionRequestBuilder(); }
public EthNewPendingTransactionObservableSubscription(IStreamingClient client) : base(client, new EthUnsubscribeRequestBuilder()) { _builder = new EthNewPendingTransactionSubscriptionRequestBuilder(); }
public EthBlockNumberObservableHandler(IStreamingClient streamingClient) : base(streamingClient, new EthBlockNumber(null)) { }
public EthSubscriptionService(IStreamingClient client) : base(client) { NewPendingTransactionSubscription = new EthNewPendingTransactionSubscription(client); NewBlockHeadersSubscription = new EthNewBlockHeadersSubscription(client); }