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;
            }
        }
Exemplo n.º 3
0
        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>();
        }
Exemplo n.º 5
0
		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();
		}
Exemplo n.º 6
0
 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();
 }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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");
        }
Exemplo n.º 9
0
 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;
     }
 }
Exemplo n.º 10
0
 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));
         });
     }
 }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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());
 }
Exemplo n.º 17
0
 public abstract Task ExecuteAsync(IStreamingClient client);
Exemplo n.º 18
0
 public DemoCompressingController(IStreamingClient streamingClient)
 {
     _streamingClient = streamingClient;
 }
Exemplo n.º 19
0
        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";
            }
            
        }
Exemplo n.º 20
0
 public EthApiContractService(IClient client, IStreamingClient streamingClient) : base(client, streamingClient)
 {
 }
 protected RpcStreamingResponseParamsObservableHandler(IStreamingClient streamingClient, TRpcRequestResponseHandler rpcRequestResponseHandler) : base(streamingClient)
 {
     RpcRequestResponseHandler = rpcRequestResponseHandler;
 }
Exemplo n.º 22
0
 protected RpcStreamingSubscriptionHandler(IStreamingClient streamingClient, IUnsubscribeSubscriptionRpcRequestBuilder unsubscribeSubscriptionRpcRequestBuilder)
 {
     StreamingClient = streamingClient;
     UnsubscribeSubscriptionRpcRequestBuilder = unsubscribeSubscriptionRpcRequestBuilder;
 }
 protected RpcStreamingSubscriptionEventResponseHandler(IStreamingClient streamingClient, IUnsubscribeSubscriptionRpcRequestBuilder unsubscribeSubscriptionRpcRequestBuilder) : base(streamingClient, unsubscribeSubscriptionRpcRequestBuilder)
 {
 }
Exemplo n.º 24
0
 public EthNewPendingTransactionSubscription(IStreamingClient client) : base(client, ApiMethods.eth_subscribe.ToString())
 {
 }
Exemplo n.º 25
0
 public async Task ExecuteTestAsync(IStreamingClient client)
 {
     await ExecuteAsync(client);
 }
Exemplo n.º 26
0
 protected RpcStreamingRequestResponseHandler(IStreamingClient streamingClient)
 {
     StreamingClient = streamingClient;
 }
Exemplo n.º 27
0
 public Web3(IClient client, IStreamingClient streamingClient) : this(client)
 {
     StreamingClient = streamingClient;
 }
Exemplo n.º 28
0
 protected RpcStreamingResponseObservableHandler(IStreamingClient streamingClient) : base(streamingClient)
 {
     ResponseSubject = new Subject <TResponse>();
 }
Exemplo n.º 29
0
 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;
 }
Exemplo n.º 32
0
        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);
        }
Exemplo n.º 33
0
 public EthLogsObservableSubscription(IStreamingClient client) : base(client, new EthUnsubscribeRequestBuilder())
 {
     _ethLogsSubscriptionRequestBuilder = new EthLogsSubscriptionRequestBuilder();
 }
Exemplo n.º 34
0
 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();
 }
Exemplo n.º 37
0
 public EthNewPendingTransactionObservableSubscription(IStreamingClient client) : base(client, new EthUnsubscribeRequestBuilder())
 {
     _builder = new EthNewPendingTransactionSubscriptionRequestBuilder();
 }
 public EthBlockNumberObservableHandler(IStreamingClient streamingClient) : base(streamingClient, new EthBlockNumber(null))
 {
 }
Exemplo n.º 39
0
 public EthSubscriptionService(IStreamingClient client) : base(client)
 {
     NewPendingTransactionSubscription = new EthNewPendingTransactionSubscription(client);
     NewBlockHeadersSubscription       = new EthNewBlockHeadersSubscription(client);
 }