예제 #1
0
 public string GetAllText()
 {
     return(weblog.GetAllText());
 }
예제 #2
0
        public void ProcessMessage(WsMessage wsMessage, IMessagingServer server)
        {
            switch (wsMessage.Type)
            {
            case WsMessageType.GetAllText:
            {
                wsMessage.Message = log.GetAllText();
                wsMessage.Type    = WsMessageType.GetAllText;
                var send = JsonConvert.SerializeObject(wsMessage);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.ClearLog:
            {
                log.ClearLog();
            }
            break;

            case WsMessageType.WriteLog:
            {
                log.Info(wsMessage.Message);
            }
            break;

            case WsMessageType.GetAllPositions:
            {
                var message = new WsMessage();
                message.From = wsMessage.From;
                message.Type = WsMessageType.GetAllPositions;
                var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>();
                message.Message = JsonConvert.SerializeObject(terminals.GetAllPositions());
                var send = JsonConvert.SerializeObject(message);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.GetAllPerformance:
            {
                var message = new WsMessage();
                message.From    = wsMessage.From;
                message.Type    = WsMessageType.GetAllPerformance;
                message.Message = "[]";
                var ds    = MainService.thisGlobal.Container.Resolve <DataService>();
                var month = int.Parse(wsMessage.Message);
                ds.StartPerf(month);
                var send = JsonConvert.SerializeObject(message);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.GetAllCapital:
            {
                var message = new WsMessage();
                message.From    = wsMessage.From;
                message.Type    = WsMessageType.GetAllCapital;
                message.Message = "[]";
                var result       = JsonConvert.DeserializeObject <Dictionary <string, string> >(wsMessage.Message);
                var wallet       = int.Parse(result["WalletId"]);
                var dateTimeFrom = DateTime.Parse(result["from"]);
                var dateTimeTo   = DateTime.Parse(result["to"]);
                xtrade.GetWalletBalanceRangeAsync(wallet, dateTimeFrom, dateTimeTo);
                var send = JsonConvert.SerializeObject(message);
                server.MulticastText(send);
            }
            break;

            case WsMessageType.UpdatePosition:
            {
                var result = JsonConvert.DeserializeObject <PositionInfo>(wsMessage.Message);
                if (result != null)
                {
                    var terminals = MainService.thisGlobal.Container.Resolve <ITerminalEvents>();
                    terminals.UpdatePositionFromClient(result);
                }
            }
            break;

            case WsMessageType.GetLevels:
            {
                wsMessage.From    = "Server";
                wsMessage.Message = xtrade.Levels4Symbol(wsMessage.Message);
                wsMessage.Type    = WsMessageType.GetLevels;
                var send = JsonConvert.SerializeObject(wsMessage);
                server.MulticastText(send);
            }
            break;


            default:
            {
                log.Info("Undefined Message");
                // Multicast message to all connected sessions
                // ((WsServer)Server).MulticastText(message);
            }
            break;
            }
        }