public MainWindow()
        {
            channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
            client  = new Notifier.NotifierClient(channel);

            InitializeComponent();
            showChart();
        }
Exemple #2
0
        private void DoSendWork(object state)
        {
            Message message = _messageStorage.GetNext();

            while (message != null)
            {
                if (message != null)
                {
                    var connections = _connectionStorage.GetConnectionsByTopic(message.Topic);

                    foreach (var connection in connections)
                    {
                        var client  = new Notifier.NotifierClient(connection.GrpcChannel);
                        var request = new NotifyRequest()
                        {
                            Content = message.Content
                        };

                        try
                        {
                            if (connection.Limit <= 0)
                            {
                                client.Notify(new NotifyRequest()
                                {
                                    Content = "Message limit is out. You are disconnected."
                                });
                                _connectionStorage.Remove(connection.Address);
                                continue;
                            }

                            var reply = client.Notify(request);
                            _connectionStorage.UpdateLimit(connection.Address);
                            Console.WriteLine($"Notified subscriber {connection.Address} with {message.Content}. Response: {reply}");
                        }
                        catch (RpcException re)
                        {
                            if (re.StatusCode == StatusCode.Internal)
                            {
                                _connectionStorage.Remove(connection.Address);
                            }
                            Console.WriteLine(re.Message);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine($"Error notifying subscriber {connection.Address}. {e.Message}");
                        }
                    }
                }

                message = _messageStorage.GetNext();
            }
        }
Exemple #3
0
        private async Task DoSendWork(CancellationToken cancellationToken)
        {
            var isEmptyMessages = await _messageRepository.IsEmpty(cancellationToken);

            if (isEmptyMessages)
            {
                return;
            }

            var message = await _messageRepository.GetNext(cancellationToken);

            if (message != null)
            {
                var connections = await _connectionRepository.GetConnectionsByBank(message.Bank, cancellationToken);

                if (connections.Count == 0)
                {
                    await _messageRepository.Add(message, cancellationToken);
                }

                foreach (var connection in connections)
                {
                    var channel = GrpcChannel.ForAddress(connection.Address, new GrpcChannelOptions {
                        HttpHandler = _httpHandler
                    });
                    var client  = new Notifier.NotifierClient(channel);
                    var request = new NotifyRequest {
                        Bank = message.Bank, Content = message.Rates
                    };

                    try
                    {
                        var reply = client.Notify(request);
                        Console.WriteLine($"Notified subscriber {connection.Address} with {message.Rates}. Response: {reply.IsSuccess}");
                    }
                    catch (RpcException e)
                    {
                        if (e.StatusCode == StatusCode.Internal)
                        {
                            await _connectionRepository.Remove(connection.Address, cancellationToken);
                        }

                        Console.WriteLine($"Details: {e.Status.Detail}");
                        Console.WriteLine($"Status code: {e.Status.StatusCode}");
                    }
                }
            }
        }
        public async Task GetData(Notifier.NotifierClient client)
        {
            DataRequest request = new DataRequest {
            };

            using (var call = client.Data(request))
            {
                var responseStream = call.ResponseStream;

                while (await responseStream.MoveNext())
                {
                    DataReply dataReply = responseStream.Current;
                    timerTick(dataReply.ProductName, dataReply.ProductPrice);
                }
            }
        }
Exemple #5
0
        private void DoSendWork(object state)
        {
            while (!_messageStorege.IsEmpty() &&
                   _connectionStorage.GetConnectionsByTopic(_messageStorege.CheckNextTopic()).Count != 0)
            {
                var message = _messageStorege.GetNext();

                if (message != null)
                {
                    var connections = _connectionStorage.GetConnectionsByTopic(message.Topic);

                    foreach (var connection in connections)
                    {
                        var client  = new Notifier.NotifierClient(connection.Channel);
                        var request = new NotifyRequest()
                        {
                            Content = message.Content
                        };

                        try
                        {
                            var reply = client.Notify(request);
                            Console.WriteLine($"Notified subscriber {connection.Address} with {message.Content}. Response: {reply.IsSuccess}");
                        }

                        catch (RpcException rpcException)
                        {
                            if (rpcException.StatusCode == StatusCode.Internal)
                            {
                                _connectionStorage.Remove(connection.Address);
                            }

                            Console.WriteLine($"RPC Error notifying subscriber {connection.Address}. {rpcException.Message}");
                        }


                        catch (Exception exception)
                        {
                            Console.WriteLine($"Error notifying subscriber {connection.Address}. {exception.Message}");
                        }
                    }
                }
            }
        }
Exemple #6
0
        private async Task NotifySubscriber(Message msg, Connection conn)
        {
            try
            {
                var notifier = new Notifier.NotifierClient(conn.GrpcChannel);
                var command  = new NotifyCommand {
                    Sensor = msg.Sensor, Data = msg.Data, ExecutorType = conn.ExecutorType
                };
                await notifier.NotifyAsync(command);
            }
            catch (RpcException e)
            {
                Console.WriteLine($"Could not send to {conn.Address} | {e.Message}");

                if (e.StatusCode == StatusCode.Internal)
                {
                    _connectionService.RemoveConnection(conn.Address);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Could not send to {conn.Address} | {e.Message}");
            }
        }
 public NotifierClient(Notifier.NotifierClient client)
 {
     this.client = client;
 }
Exemple #8
0
 public PusherService(GrpcChannel channel, ILogger <PusherService> logger)
 {
     _channel = channel;
     _logger  = logger;
     _client  = new Notifier.NotifierClient(channel);
 }