private void PullSocketReceiveReady(object sender, NetMQSocketEventArgs e) { lock (pullSocketLock) { if (pullSocket != null) { var message = pullSocket.ReceiveMultipartMessage(2); if (message.FrameCount < 2) { logger.Error("Messages Server: Received corrupted message."); return; } var receivedObject = message[1].Buffer; switch ((PushMessageType)BitConverter.ToInt16(message[0].Buffer, 0)) { case PushMessageType.OpenOrderPush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { repository.AddNewOpenOrderMessage( MyUtils.ProtoBufDeserialize <OpenOrder>(ms)); } }); break; case PushMessageType.CommissionPush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { var commissionMessage = MyUtils.ProtoBufDeserialize <CommissionMessage>(ms); repository.AddCommissionMessage(commissionMessage); } }); break; case PushMessageType.ExecutionPush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { repository.AddExecutionMessage( MyUtils.ProtoBufDeserialize <ExecutionMessage>(ms)); } }); break; case PushMessageType.OrderStatusPush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { repository.AddNewOrderStatusMessage( MyUtils.ProtoBufDeserialize <OrderStatusMessage>(ms)); } }); break; case PushMessageType.LiveTradePush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { repository.AddOrUpdateLiveTrade( MyUtils.ProtoBufDeserialize <LiveTrade>(ms)); } }); break; case PushMessageType.AccountUpdatePush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { repository.UpdateAccountSummary( MyUtils.ProtoBufDeserialize <AccountSummaryUpdate>(ms)); } }); break; case PushMessageType.EquityUpdatePush: Task.Factory.StartNew(() => { using (var ms = new MemoryStream(receivedObject)) { repository.UpdateEquity( MyUtils.ProtoBufDeserialize <Equity>(ms)); } }); break; default: throw new ArgumentOutOfRangeException(); } } } }