예제 #1
0
파일: Home.xaml.cs 프로젝트: jhaby/GAMERS
        public Home(UserData Userinfo, string uri)
        {
            InitializeComponent();
            try
            {
                User     = Userinfo;
                this.uri = uri;
                Loaded  += Home_Loaded;
                string NameChip = "Hi, " + User.Firstname + " " + User.Surname;
                stat = new StatusModel
                {
                    UserId = User.UserId,
                    Status = "Active"
                };

                connection = new HubConnectionBuilder()
                             .WithUrl(uri + "/updates")
                             .Build();

                connection.Closed += async(error) =>
                {
                    await Task.Delay(5000);
                    await ServerConnect();

                    await signalService.SendStatus(stat);

                    CloseHomeWindow?.Invoke();
                };

                this.StateChanged += Home_StateChanged;


                signalService = new ConnService(connection);

                signalService.StatusReceived += Cos_StatusReceived;

                signalService.AlertReceived += CasesPage_AlertEvent;

                Task.Run(async() =>
                {
                    await ServerConnect();
                });

                persons       = new PersonnelInfoViewModel();
                schedule      = new SchedulePage();
                paypage       = new PaymentPage();
                loadingWindow = new LoadingWindow();

                signalService.NewUserSync += async(string id) =>
                {
                    await signalService.ConnectionSync(User.UserId);
                };

                signalService.DisconnectUser += (string obj) =>
                {
                    Task.Run(async() =>
                    {
                        await signalService.SendStatus(stat);
                        await signalService.UpdateStatus(stat.Status, stat.UserId);
                    });
                };
                LoadMap();

                HistoryPage.historyItem += (HistoryModel obj) =>
                {
                    MainHolder.Visibility = Visibility.Visible;
                    browser.Visibility    = Visibility.Collapsed;
                    Dispatcher.Invoke(() => MainHolder.NavigationService.Navigate(new CaseDetails(obj)));
                };



                this.Closing += MainWindow_Closing;

                sService = signalService;



                Respond += (string[] details) =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        ResponseView.Visibility = Visibility.Visible;
                        browser.Visibility      = Visibility.Collapsed;
                        var rpage = new ResponsePage(User, signalService, details);
                        Response.NavigationService.Navigate(rpage);


                        rpage.BtnClicked += (string obj) =>
                        {
                            switch (obj)
                            {
                            case "Close":
                                ResponseView.Visibility  = Visibility.Collapsed;
                                browser.Visibility       = Visibility.Visible;
                                RestoreButton.Visibility = Visibility.Visible;
                                break;

                            case "restart":
                                CasesModel alert = new CasesModel()
                                {
                                    DateTime    = Convert.ToDateTime(details[5]),
                                    Location    = details[2],
                                    VHTCode     = details[4],
                                    Description = details[6],
                                    Village     = details[3],
                                    Status      = "ongoing",
                                    CaseId      = details[0],
                                    Category    = details[7]
                                };
                                Dispatcher.Invoke(async() => {
                                    await signalService.RestartResponse(details[0]);
                                });
                                break;

                            case "completed":
                                Dispatcher.Invoke(() => {
                                    RadWindow.Confirm("Are you sure you want to mark case as completed?", async delegate
                                    {
                                        await signalService.CompletedCase(details[0]);
                                        RadWindow.Alert("This case has been marked as completed.", MarkCaseCompleted);
                                    });
                                });
                                break;
                            }
                        };
                    });
                };
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        public Dashboard(UserData Userinfo, StatusModel stat, ConnService signalService, string uri)
        {
            InitializeComponent();

            status           = stat;
            this.uri         = uri;
            User             = Userinfo;
            this.DataContext = User;
            _client          = new HttpClient();

            userRank = new UsersRank();

            LoadAgents();

            signalService.StatusReceived += (StatusModel obj) =>
            {
                int index = AgentsList.FindIndex(agent => agent.UserId.Equals(obj.UserId, StringComparison.Ordinal));
                if (obj.UserId == status.UserId)
                {
                    status.Status            = obj.Status;
                    User.Status              = obj.Status;
                    AgentsList[index].Status = obj.Status;
                    if (AgentsList[index].Status == "Active")
                    {
                        AgentsList[index].Background = Colors.LightGreen;
                    }
                    else
                    {
                        AgentsList[index].Background = Colors.LightPink;
                    }
                }
                else
                {
                    AgentsList[index].Status = obj.Status;
                    if (AgentsList[index].Status == "Active")
                    {
                        AgentsList[index].Background = Colors.LightGreen;
                    }
                    else
                    {
                        AgentsList[index].Background = Colors.LightPink;
                    }
                }
            };


            signalService.Ranking += (List <UsersRank> obj) =>
            {
                int index = obj.FindIndex(ag => ag.UserID.Equals(User.UserId, StringComparison.Ordinal));
                User.Rank = obj[index].Position.ToString();

                for (var i = 0; i < AgentsList.Count; i++)
                {
                    int pos = obj.FindIndex(ag => ag.UserID.Equals(AgentsList[i].UserId, StringComparison.Ordinal));
                    AgentsList[i].Rank = obj[pos].Position;
                }
            };



            StatusToggle.Unchecked += (o, e) =>
            {
                status.UserId = User.UserId;
                status.Status = "Unavailable";
                Task.Run(async() => {
                    await signalService.SendStatus(status);
                    await signalService.UpdateStatus(status.Status, status.UserId);

                    userRank.Position = 0;
                    await signalService.ReorderList("remove", User.UserId);
                    User.Rank = "";
                });
                User.Status = status.Status;
            };

            StatusToggle.Checked += (o, e) =>
            {
                status.UserId = User.UserId;
                status.Status = "Active";
                Task.Run(async() => {
                    await signalService.SendStatus(status);
                    await signalService.UpdateStatus("Active", status.UserId);


                    await signalService.ReorderList("add", User.UserId);
                });

                User.Status = status.Status;
            };

            if (User.Status == "Active")
            {
                StatusToggle.IsChecked = true;
            }
            else
            {
                StatusToggle.IsChecked = false;
            }
        }