Ejemplo n.º 1
0
 private void HandleIncomingMeasurement(Packet packet)
 {
     var selectedUser = (User)cmbOnlinePatients.SelectedItem;
     var resultPacket = ((SerialDataPushPacket)packet);
     if (selectedUser.Username == resultPacket.Username)
     {
         if (this.InvokeRequired)
         {
             this.Invoke(new Action(() => HandleIncomingMeasurement(packet)));
         }
         else
         {
             HandleBikeData(resultPacket.Measurement);
         }
     }
 }
Ejemplo n.º 2
0
        public void HandleLoginEvent(Packet packet)
        {
            LoginResponsePacket responsePacket = packet as LoginResponsePacket;

            switch (responsePacket.Status)
            {
                case "200":
                    if (this.InvokeRequired)
                    {
                        this.Invoke((new Action(() => HandleLoginEvent(packet))));
                        return;
                    }
                    if (responsePacket.isDoctor)
                    {
                        DoctorForm d = new DoctorForm();
                        this.Hide();
                        d.Show();
                    }
                    else
                    {
                        PatientForm p = new PatientForm();
                        this.Hide();
                        p.Show();
                    }
                    break;
                case "201":
                    MessageBox.Show("You can only log in once", "Error", MessageBoxButtons.OK);
                    break;
                case "430":
                    MessageBox.Show("Invalid Username or Password", "Error", MessageBoxButtons.OK);
                    break;
                default:
                    MessageBox.Show("Unhandled error occured", "Error", MessageBoxButtons.OK);
                    break;
            }
        }
Ejemplo n.º 3
0
 private void OnResultEvent(Packet packet)
 {
     ResultDelegate handler = ResultEvent;
     if (handler != null) handler(packet);
 }
Ejemplo n.º 4
0
 private void MeasurementDataReceived(Packet p)
 {
     SerialDataPacket packet = p as SerialDataPacket;
     PatientMeasurements.Add(packet.PatientUsername, packet.Measurement);
 }
Ejemplo n.º 5
0
 private void PacketReceived(Packet p)
 {
     Console.WriteLine(p.ToJsonObject().ToString());
     if (p is SerialDataPushPacket)
     {
         Console.WriteLine("push packet received!");
         OnIncomingMeasurementEvent(p as SerialDataPushPacket);
     }
     else if (p is UserChangedPacket)
     {
         var packet = p as UserChangedPacket;
         if (packet.Username == this.Username)
             return;
         User x = Users.FirstOrDefault(u => u.Username == packet.Username);
         if (x == null)
         {
             x = new User(packet.Nickname, packet.Username, null);
             Users.Add(x);
         }
         x.OnlineStatus = packet.Status;
         OnUserChangedEvent(x);
     }
     else if (p is LoginResponsePacket)
     {
         OnLoginResultEvent(p as LoginResponsePacket);
     }
     //else if (p is RegisterResponsePacket)
     //{
     //    var packet = p as RegisterResponsePacket;
     //    OnRegisterResultEvent(packet.Status);
     //}
     //else if (p is PullResponsePacket<ChatMessage>)
     //{
     //    var packet = p as PullResponsePacket<ChatMessage>;
     //    FillChatMessageList(packet.Data.ToList());
     //    Console.WriteLine("PullResponsePacket<ChatMessage> received!");
     //}
     //else if (p is PullResponsePacket<User>)
     //{
     //    var packet = p as PullResponsePacket<User>;
     //    foreach (User u in packet.Data.ToList())
     //    {
     //        Users.Add(u);
     //    }
     //    InitializeContacts();
     //}
     else if (p is ResponsePacket) //this one should be last!
     {
         OnResultEvent(p as ResponsePacket);
     }
 }
Ejemplo n.º 6
0
        public void Send(Packet packet)
        {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Controller.SendAsync(packet);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
Ejemplo n.º 7
0
        private void CheckLoggedIn(Packet packet)
        {
            //Post logged-in method calls
            if (((LoginResponsePacket)packet).Status == "200")
            {
                Username = ((LoginResponsePacket)packet).username;
                Connected = true;
                Receive();
            }

        }
Ejemplo n.º 8
0
 public void Send(Packet s)
 {
     Send(s.ToString());
 }
Ejemplo n.º 9
0
        private void SendToAllOnlineDoctors(Packet packet)
        {
            List<string> onlineDoctors = Authentication.GetAllUsers()
                .Where(user => user.IsDoctor == true)
                .Select(user => user.Username).ToList();
            foreach (string u in onlineDoctors)
            {
                var clientHandler = Authentication.GetStream(u);
                if (clientHandler != null) clientHandler.Send(packet);
#if DEBUG
                if (clientHandler != null) Console.WriteLine("Notifing:\n{0}", packet);
#endif
            }
        }
Ejemplo n.º 10
0
        private void SendToAllOnlineUsers(Packet p)
        {
            foreach (var clientHandler in Authentication.GetAllUsers()
                .Select(linqUser => Authentication.GetStream(linqUser.Username))
                .Where(clientHandler => clientHandler != null))
            {
#if DEBUG
                Console.WriteLine("SendToAllUsers: Sending a packet");
#endif
                clientHandler.Send(p);
            }
        }