Esempio n. 1
0
        private void LoginPacketResponse(Packet p)
        {
            var resp = p as LoginResponsePacket;

            if (resp == null)
                return;

            if (this.InvokeRequired)
            {
                this.Invoke((new Action(() => LoginPacketResponse(p))));
                return;
            }


            if (resp.Status == "200")
            {

                RH_APP.Classes.Settings.GetInstance().authToken = resp.AuthToken;
                RH_APP.Classes.Settings.GetInstance().CurrentUser = resp.User;
                if (resp.User.IsSpecialist || resp.User.IsAdministrator)
                {
                    //var mainScreen = new MainScreen(true);
                    TCPController.OnPacketReceived -= LoginPacketResponse;
                    //mainScreen.ShowDialog();

                    this.Hide();
                    MainMenu m = new MainMenu();
                    m.Show();
                }
                else if (resp.User.IsClient)
                {
                        this.Hide();
                        //var mainScreen = new MainScreen(false);
                        var mainScreen = new TrainingScreen(false);
                        TCPController.OnPacketReceived -= LoginPacketResponse;
                        mainScreen.Text = " Remote Healthcare - Client Edition";
                        mainScreen.ShowDialog();

                }
            }
            else
            {
                MessageBox.Show(resp.Description, "Your application has been reviewed");
            }

            

        }
        private void ReceiveHonoredGuests(Packet p)
        {
            if (this.InvokeRequired)
            {
                this.Invoke((new Action(() => ReceiveHonoredGuests(p))));
                return;
            }

            if (p is PullResponsePacket<User>)
            {
                var response = p as PullResponsePacket<User>;

                if (response.DataType == "connected_clients")
                    readClients(response.List);
                TCPController.OnPacketReceived -= ReceiveHonoredGuests;

            }
        }
        private void handleIncomingPackets(Packet p)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(() => handleIncomingPackets(p)));
                return;
            }

            // Tuple<userId, SessionId, DateOfSession>()
            if (p is PullResponsePacket<SessionData>)
            {
                var response = p as PullResponsePacket<SessionData>;

                if (response.DataType == "user_sessions")
                {
                    Console.WriteLine("Sessions loaded");
                    sessions = response.List;
                    usersCombobox_SelectedIndexChanged(this, EventArgs.Empty);

                }
            }
            else if (p is PullUsersResponsePacket)
            {
                var response = p as PullUsersResponsePacket;
                users = response.List.Where(x => x.IsClient).ToList();
                BindingSource bs = new BindingSource();
                bs.DataSource = users;
                usersCombobox.DataSource = bs;
                usersCombobox.DisplayMember = "Fullname";
                usersCombobox.ValueMember = "Id";
            }
            else if (p is PullResponsePacket<Measurement>)
            {
                TCPController.OnPacketReceived -= handleIncomingPackets;
                this.Close();
                GraphResultUI ui = new GraphResultUI(((PullResponsePacket<Measurement>)p).List);
                ui.Show();
            }
        }
Esempio n. 4
0
        private void HandleIncomingPackets(Packet p)
        {
            if (InvokeRequired)
            {
                Invoke((new Action(() => HandleIncomingPackets(p))));
                return;
            }

            if (p is DataFromClientPacket<Measurement>)
            {
                var response = p as DataFromClientPacket<Measurement>;

                if (response.ClientId != client.Id)
                    return;
                if (_spController == null)
                    startTraining(this, EventArgs.Empty);


                foreach (var m in response.List)
                {
                    _spController.SetMeasurement(m);
                    //Console.WriteLine("Received a measurement.");
                }
            }
            else if (p is ChatPacket)
            {
                var chat = p as ChatPacket;

                if (chat.IsBroadcast)
                {
                    AddNewMessage("<Broadcast> " + chat.UsernameDestination, chat.Message);
                    return;
                }
                if (client != null && chat.UsernameDestination != client.Username)
                    return;
                AddNewMessage(chat.UsernameDestination, chat.Message);

            }
            else if (p is PushPacket<Configuaration>)
            {
                var ppacket = p as PushPacket<Configuaration>;
                var config = ppacket.DataSource.FirstOrDefault();
                if (config == null)
                    return;

                if (config.Power.HasValue && _controller != null)
                {
                    _controller.SetPower(config.Power.Value);
                }
            }
            else if (p is NotifyPacket)
            {
                var traitor = p as NotifyPacket;
                if (traitor.NotifySubject == NotifyPacket.Subject.NewTrainingId)
                {
                    if (isSpecialist && int.Parse(traitor.SecundaryValue) == client.Id)
                    {
                        currentTraingId = int.Parse(traitor.PrimaryValue);
                    }
                    else
                        currentTraingId = int.Parse(traitor.PrimaryValue);
                }
                else if (traitor.NotifySubject == NotifyPacket.Subject.StartTraining)
                {
                    startTraining(this, EventArgs.Empty);
                }
                else if (traitor.NotifySubject == NotifyPacket.Subject.StopTraining)
                {
                    _quitButton_Click(this, EventArgs.Empty);
                }
            }

            string b = "";
        }
Esempio n. 5
0
        //private void Send(Object s)
        //{
        //    Send(s.ToString());
        //}

        private void Send(Packet p)
        {
            Send(p.ToString());
        }