Пример #1
0
        public static Packet GetPacketFromJson(JObject json)
        {
            if (json == null) return null;


            Packet p = null;
            switch ((string)json.GetValue("CMD", StringComparison.CurrentCultureIgnoreCase))
            {

                //case ChatPacket.DefCmd:
                //    p = new ChatPacket(json);
                //    break;
                case DisconnectPacket.DefCmd:
                    p = new DisconnectPacket(json);
                    break;
                case LoginPacket.DefCmd:
                    p = new LoginPacket(json);
                    break;
                case LoginResponsePacket.DefCmd:
                    p = new LoginResponsePacket(json);
                    break;
                case SerialDataPushPacket.DefCmd:
                    p = new SerialDataPushPacket(json);
                    break;
                //case RegisterPacket.DefCmd:
                //    p = new RegisterPacket(json);
                //    break;
                //case RegisterResponsePacket.DefCmd:
                //    p = new RegisterResponsePacket(json);
                //    break;
                case UserChangedPacket.DefCmd:
                    p = new UserChangedPacket(json);
                    break;
                case PullResponsePacket.DefCmd:
                    p = new PullResponsePacket<User>(json);
                    break;
                default:
                    try
                    {
                        p = new ResponsePacket(json);
                    }
                    catch (ArgumentException)
                    {
                    }
                    break;
            }
            return p;
        }
Пример #2
0
 private void OnIncomingMeasurementEvent(SerialDataPushPacket packet)
 {
     PushDelegate handler = IncomingMeasurementEvent;
     if (handler != null) handler(packet);
 }
Пример #3
0
        private void HandleSerialDataPacket(JObject json)
        {
            Console.WriteLine("Handle SerialData Packet");
            var packet = new SerialDataPacket(json);

            var PatientUsername = Authentication.GetAllUsers()
                .Where(user => user.Username == packet.PatientUsername)
                .Select(user => user.Username).FirstOrDefault();

            ClientDataHandler.ReturnValue returnVal = _clientDataHandler.AddMeasurementToLastBikeTest(packet.Measurement);
            if (returnVal == ClientDataHandler.ReturnValue.NotStarted)
            {
#if DEBUG
                Console.WriteLine("Error: Tried to add measurement while BikeTest was not started of patient {0}", Authentication.GetUser(packet.PatientUsername).Nickname);
#endif
            }
            else
            {
#if DEBUG
                Console.WriteLine("Error: General error occured while tried to add measurement of patient {0}", Authentication.GetUser(packet.PatientUsername).Nickname);
#endif
            }

            //Generate PushPacket
            Packet pushPacket = new SerialDataPushPacket(packet.Measurement, packet.PatientUsername);

            // Determining the sockets to send the pushpacket (to send to all online doctors) 
            SendToAllOnlineDoctors(pushPacket);
#if DEBUG
            Console.WriteLine(packet);
#endif
        }