Пример #1
0
                       public static void Main(string[] args)
                       {
                           var     jsonString = @"{""date"" : ""19:21:17 28/3/2020"", ""temp"" : 5}";
                           Message message    = Message.ToMessage(jsonString); // converte json pra Message

                           Console.WriteLine(message);
                           Console.WriteLine((ValueType)message.GetDate() ?? -5); // se a data nao for null entao imprime-a
                       }
Пример #2
0
        private void HandlePost(HttpListenerContext context)
        {
            string body = new StreamReader(context.Request.InputStream).ReadToEnd();

            Console.WriteLine("[POST] Recebeu: " + body);

            try {
                var msg = Message.ToMessage(body);
                Console.WriteLine(msg.ToString());
                MedidasDB.AddMessage(msg);
                // MedidasDB.AddMessage(Message.ToMessage(body));
                SendResponse(context.Response, "ACK");
            }
            catch (Exception e) {
                SendResponse(context.Response, "NACK", 400);
            }
        }
Пример #3
0
        private void ServerOnMessage(ClientManager clientManager, byte[] data)
        {
            ConsoleMessenger.Log(ConsoleMessenger.Prefix.Message, "Received a request");
            var message = Message.ToMessage(data);

            switch (message.Type)
            {
            case MessageType.LoginRequest:
                OnLoginRequest(clientManager, message);
                break;

            case MessageType.SignUpRequest:
                OnSignUpRequest(clientManager, message);
                break;

            case MessageType.SaveRequest:
                OnSaveRequest(clientManager, message);
                break;

            default:
                ConsoleMessenger.Log(ConsoleMessenger.Prefix.Error, "No implementation for case " + message.Type);
                break;
            }
        }