示例#1
0
        /// <summary>
        /// Processes the connection.
        /// </summary>
        public void ProcessConnection()
        {
            try
            {
                var dataBuffer = new byte[65536];

                while (true)
                {
                    int byteCount = socket.Receive(dataBuffer);
                    if (byteCount > 0)
                    {
                        DataAssembler.Deserialize(dataBuffer, 0, byteCount);
                    }
                }
            }
            catch (IOException e)
            {
                Console.Error.WriteLine("Error receiving data from client. Did client disconnect?");
                Console.Error.WriteLine("Error message: {0}", e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }
            finally
            {
                socket.Close();
                RemoveSelf();
                StatsHolder.Remove(StatsHolder.Engine);
                StatsHolder.Remove(StatsHolder.Server);
                StatsHolder.Remove(StatsHolder.EndToEnd);
            }
        }
示例#2
0
        public void Ctor_WorkPathNull_ThrowsArgumentNullException()
        {
            var workPath = (string)null;

            void testAction()
            {
                _ = new DataAssembler(workPath);
            }

            _ = Assert.Throws <ArgumentNullException>(testAction);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientConnection"/> class based on
        /// the TCP socket channel.
        /// </summary>
        /// <param name="executor">The executor.</param>
        /// <param name="cepProvider">The cep provider.</param>
        /// <param name="statSec">The stat sec.</param>
        protected ClientConnection(Executor executor, CEPProvider.ICEPProvider cepProvider, int statSec)
        {
            myID           = Interlocked.Increment(ref _id) - 1;
            _dataAssembler = new DataAssembler();
            _dataAssembler.MarketDataEvent += EnqueueEvent;
            _executor    = executor;
            _cepProvider = cepProvider;
            _statSec     = statSec;

            lock (CLIENT_CONNECTIONS_LOCK)
            {
                CLIENT_CONNECTIONS.Put(myID, this);
            }
        }
示例#4
0
        public void LoadAll()
        {
            StopWatch.DateSet("LoadAll");

            Loaded = false;
            if (!InitializeData())
            {
                Loaded = true;
                return;
            }

            Loading = true;
            List <string> Pairs = this.GetAvailablePairs();
            List <ServiceConfiguration.TimeFrame> Frames = Enums.ToList <ServiceConfiguration.TimeFrame>();

            if (Pairs.Count <= 0 || Frames == null)
            {
                Loaded = true; return;
            }                                                                 //

            UpToDate = new Dictionary <string, DateTime>();

            this.LoadData();

            StopWatch.Run();

            foreach (string pair in Pairs) //for (int p = 0; p < Pairs.Count; p++)//foreach (ServiceConfiguration.TimeFrame frame in Frames)//for (int f = 0; f < Frames.Count; f++)
            //this.LoadFrames(pair);
            {
                ThreadsLoad.Run(() => this.LoadFrames(pair, Frames), pair, true, true); //ThreadsLoad.Run(() => this.Load(pair, frame), pair + frame, true, true);
            }
            ThreadsLoad.JoinAll();

            DataAssembler.Clear();

            var    dimespan = StopWatch.ms();
            double us       = StopWatch.us();


            Loaded   = true;
            Loading  = false;
            LoadTime = StopWatch.DateGet("LoadAll");
        }
示例#5
0
        /// <summary>
        /// Receives the callback.
        /// </summary>
        /// <param name="ar">The ar.</param>
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                SocketError errorCode;
                var         bytesReceived = _socket.EndReceive(ar, out errorCode);
                if (bytesReceived > 0)
                {
                    DataAssembler.Deserialize(_dataArray, 0, bytesReceived);
                }
            }
            catch (IOException e)
            {
                Console.Error.WriteLine("Error receiving data from client. Did client disconnect?");
                Console.Error.WriteLine("Error message: {0}", e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }

            _socket.BeginReceive(_dataArray, 0, _dataArray.Length, SocketFlags.None, ReceiveCallback, null);
        }