Exemple #1
0
        /// <summary>
        ///     Handles incoming data "push" requests: the client sends data for us to add to local storage.
        /// </summary>
        private void AcceptDataAdditionRequest(string requesterIdentity)
        {
            lock (socketLock)
            {
                if (socket != null)
                {
                    var buffer = socket.ReceiveFrameBytes();
                    DataAdditionRequest request;
                    using (var ms = new MemoryStream(buffer))
                    {
                        // Final message part: receive the DataAdditionRequest object

                        request = MyUtils.ProtoBufDeserialize <DataAdditionRequest>(ms);
                    }

                    logger.Info($"Received data push request for {request.Instrument.Symbol}.");
                    // Start building the reply
                    socket.SendMoreFrame(requesterIdentity);
                    socket.SendMoreFrame(BitConverter.GetBytes((byte)DataRequestMessageType.HistPushReply));

                    try
                    {
                        broker.AddData(request);

                        socket.SendFrame(BitConverter.GetBytes((byte)DataRequestMessageType.Success));
                    }
                    catch (Exception ex)
                    {
                        socket.SendMoreFrame(BitConverter.GetBytes((byte)DataRequestMessageType.Error));
                        socket.SendFrame(ex.Message);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///     Handles incoming data "push" requests: the client sends data for us to add to local storage.
        /// </summary>
        private void AcceptDataAdditionRequest(string requesterIdentity)
        {
            lock (_socketLock)
            {
                if (_socket != null)
                {
                    using (var ms = new MemoryStream())
                    {
                        // Final message part: receive the DataAdditionRequest object
                        bool hasMore;
                        var  buffer  = _socket.ReceiveFrameBytes(out hasMore);
                        var  request = MyUtils.ProtoBufDeserialize <DataAdditionRequest>(buffer, ms);

                        _logger.Info($"Received data push request for {request.Instrument.Symbol}.");
                        // Start building the reply
                        _socket.SendMoreFrame(requesterIdentity);
                        _socket.SendMoreFrame(MessageType.HistPushReply);

                        try
                        {
                            _broker.AddData(request);

                            _socket.SendFrame(MessageType.Success);
                        }
                        catch (Exception ex)
                        {
                            _socket.SendMoreFrame(MessageType.Error);
                            _socket.SendFrame(ex.Message);
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Handles incoming data "push" requests: the client sends data for us to add to local storage.
        /// </summary>
        private void AcceptDataAdditionRequest(string requesterIdentity, NetMQSocket socket)
        {
            //final message part: receive the DataAdditionRequest object
            bool hasMore;
            var  ms = new MemoryStream();

            byte[] buffer = socket.Receive(out hasMore);

            var request = MyUtils.ProtoBufDeserialize <DataAdditionRequest>(buffer, ms);

            //log the request
            Log(LogLevel.Info, string.Format("Received data push request for {0}.",
                                             request.Instrument.Symbol));

            //start building the reply
            socket.SendMore(requesterIdentity);
            socket.SendMore("PUSHREP");
            try
            {
                _broker.AddData(request);
                socket.Send("OK");
            }
            catch (Exception ex)
            {
                socket.SendMore("ERROR");
                socket.Send(ex.Message);
            }
        }