public void _timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     Classes.CustomSnapshotRoot root = null;
     Classes.KeeperAPI keeper = new Classes.KeeperAPI();
     Action workAction = delegate
     {
         BackgroundWorker worker = new BackgroundWorker();
         worker.DoWork += delegate
         {
             root = keeper.getKeeperInfo(guid);
         };
         worker.RunWorkerCompleted += delegate
         {
             try {
                 //image.Source = null;
                 Classes.ScoreboardRenderer render = new Classes.ScoreboardRenderer(this, root.snapshot.mapId, root);
             }catch(Exception ex)
             {
                 Classes.Logger.addLog(ex.ToString(), 1);
             }
             //Update code in here
         };
         worker.RunWorkerAsync();
     };
     Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, workAction);
 }
Beispiel #2
0
        public void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Classes.CustomSnapshotRoot root   = null;
            Classes.KeeperAPI          keeper = new Classes.KeeperAPI();
            Action workAction = delegate
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    root = keeper.getKeeperInfo(guid);
                };
                worker.RunWorkerCompleted += delegate
                {
                    try {
                        //image.Source = null;
                        Classes.ScoreboardRenderer render = new Classes.ScoreboardRenderer(this, root.snapshot.mapId, root);
                    }catch (Exception ex)
                    {
                        Classes.Logger.addLog(ex.ToString(), 1);
                    }
                    //Update code in here
                };
                worker.RunWorkerAsync();
            };

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, workAction);
        }
        public async void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            classCounts = null;
            classCounts = new classCounters();
            Classes.CustomSnapshotRoot root   = null;
            Classes.KeeperAPI          keeper = new Classes.KeeperAPI();
            Action workAction = delegate
            {
                BackgroundWorker worker = new  BackgroundWorker();
                worker.DoWork += delegate
                {
                    root = keeper.getKeeperInfo(guid);
                };
                worker.RunWorkerCompleted += async delegate
                {
                    try
                    {
                        if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team1.faction) == "US")
                        {
                            imgFaction1.Source = loadBitmap(Properties.Resources.usa);
                        }
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team1.faction) == "CN")
                        {
                            imgFaction1.Source = loadBitmap(Properties.Resources.china);
                        }
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team1.faction) == "RU")
                        {
                            imgFaction1.Source = loadBitmap(Properties.Resources.ru);
                        }
                        if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team2.faction) == "US")
                        {
                            imgFaction2.Source = loadBitmap(Properties.Resources.usa);
                        }
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team2.faction) == "CN")
                        {
                            imgFaction2.Source = loadBitmap(Properties.Resources.china);
                        }
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team2.faction) == "RU")
                        {
                            imgFaction2.Source = loadBitmap(Properties.Resources.ru);
                        }

                        foreach (var player in root.snapshot.teamInfo.team1.player)
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);

                            switch (playerInfo.selectedKit.ToString())
                            {
                            case "0":
                                classCounts.t1Assault += 1;

                                if (playerInfo.kitList[0].kitIdInformation[3] != 2887915611 && playerInfo.kitList[0].kitIdInformation[4] != 2887915611)
                                {
                                    classCounts.defib += 1;
                                }
                                break;     //2887915611

                            case "1":
                                classCounts.t1Engineer += 1;
                                break;

                            case "2":
                                classCounts.t1Support += 1;
                                break;

                            case "3":
                                classCounts.t1Recon += 1;
                                break;

                            default:
                                break;
                            }
                        }
                        //Assault
                        pbAssault1.Value     = classCounts.t1Assault;
                        lblt1Assault.Content = classCounts.t1Assault.ToString();
                        //Engineer
                        pbEngineer1.Value     = classCounts.t1Engineer;
                        lblt1Engineer.Content = classCounts.t1Engineer.ToString();
                        //Support
                        pbSupport1.Value     = classCounts.t1Support;
                        lblt1Support.Content = classCounts.t1Support.ToString();
                        //Recon
                        pbRecon1.Value     = classCounts.t1Recon;
                        lblt1Recon.Content = classCounts.t1Recon.ToString();

                        foreach (var player in root.snapshot.teamInfo.team2.player)
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);

                            switch (playerInfo.selectedKit.ToString())
                            {
                            case "0":
                                classCounts.t2Assault += 1;
                                if (playerInfo.kitList[0].kitIdInformation[3] != 2887915611 && playerInfo.kitList[0].kitIdInformation[4] != 2887915611)
                                {
                                    classCounts.defib += 1;
                                }
                                break;

                            case "1":
                                classCounts.t2Engineer += 1;
                                break;

                            case "2":
                                classCounts.t2Support += 1;
                                break;

                            case "3":
                                classCounts.t2Recon += 1;
                                break;

                            default:
                                break;
                            }
                        }
                        //Assault
                        pbAssault2.Value     = classCounts.t2Assault;
                        lblt2Assault.Content = classCounts.t2Assault.ToString();
                        //Support
                        pbEngineer2.Value     = classCounts.t2Engineer;
                        lblt2Engineer.Content = classCounts.t2Engineer.ToString();
                        //Engineer
                        pbSupport2.Value     = classCounts.t2Support;
                        lblt2Support.Content = classCounts.t2Support.ToString();
                        //Recon
                        pbRecon2.Value     = classCounts.t2Recon;
                        lblt2Recon.Content = classCounts.t2Recon.ToString();
                        lblAssaultPlayerWithDefibs.Content = classCounts.defib.ToString();
                    }
                    catch (Exception ex)
                    {
                        Classes.Logger.addLog(ex.ToString(), 1);
                    }
                    //Update code in here
                };
                worker.RunWorkerAsync();
            };
            await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, workAction);
        }
        public async void getData()
        {
            Classes.CustomSnapshotRoot root   = null;
            Classes.KeeperAPI          keeper = new Classes.KeeperAPI();
            Action workAction = delegate
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    root = keeper.getKeeperInfo(guid);
                };
                worker.RunWorkerCompleted += async delegate
                {
                    if (root == null)
                    {
                        if (extendedStats.Count == 0)
                        {
                            lblSaved.Content = "Something went wrong with the server";
                            //Potentially exit the form here!
                            _timer.Enabled = false;
                            MessageBox.Show("The server crashed or was never available. \n Please close this window.");
                            this.Close();
                            return;
                        }
                        else
                        {
                            forceSave();
                            extendedStats.Clear();
                            return;
                        }
                    }
                    if (!root.snapshot.status.Equals("SUCCESS", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }
                    try
                    {
                        int t1count      = root.snapshot.teamInfo.team1.player.Count;
                        int t2count      = root.snapshot.teamInfo.team2.player.Count;
                        int totalPlayers = t1count + t2count;
                        lblTime.Content         = "Round Time: " + Classes.UsefulFunctions.getTime(root.snapshot.roundTime, 1);
                        lblCountPlayers.Content = "Getting Statistics for " + totalPlayers.ToString() + " players";
                        lblMap.Content          = "Map: " + Classes.JSONHelper.whatMap(root.snapshot.mapId);
                        lblMode.Content         = "Mode: " + Classes.JSONHelper.whatMode(root.snapshot.modeId);
                        foreach (var player in root.snapshot.teamInfo.team1.player)
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);

                            player.kit             = playerInfo.selectedKit;
                            player.primaryWeapon   = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[0];
                            player.secondaryWeapon = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[1];
                        }
                        foreach (var player in root.snapshot.teamInfo.team2.player)
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);

                            player.kit             = playerInfo.selectedKit;
                            player.primaryWeapon   = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[0];
                            player.secondaryWeapon = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[1];
                        }
                        this.Title = "Logging: " + totalPlayers.ToString() + "P | " + Classes.UsefulFunctions.getTime(root.snapshot.roundTime, 1) + " | " + Classes.JSONHelper.whatMap(root.snapshot.mapId);
                        if (root.snapshot.roundTime != 0)
                        {
                            extendedStats.Add(root);
                        }
                        bool descrEnabled = false;
                        if ((bool)cbAddDescrAuto.IsChecked)
                        {
                            descrEnabled = true;
                        }
                        Classes.DataExport export = new Classes.DataExport(extendedStats, root);
                        string             fileName;
                        if (descrEnabled == true)
                        {
                            fileName = export.saveOrNot(txtDescription.Text);
                            if (fileName != "")
                            {
                                lblSaved.Content = "Last Saved at: " + DateTime.Now.ToString();
                                if (cbOpenOnFinish.IsChecked == true)
                                {
                                    XAML.AddBombs addBombs = new XAML.AddBombs(Classes.UsefulFunctions.getFullReport(fileName), fileName);
                                    addBombs.Show();
                                }
                                fileName = null;
                                extendedStats.Clear();
                            }
                        }
                        else
                        {
                            fileName = export.saveOrNot(txtDescription.Text);
                            if (fileName != "")
                            {
                                lblSaved.Content = "Last Saved at: " + DateTime.Now.ToString();
                                if (cbOpenOnFinish.IsChecked == true)
                                {
                                    XAML.AddBombs addBombs = new XAML.AddBombs(Classes.UsefulFunctions.getFullReport(fileName), fileName);
                                    addBombs.Show();
                                }
                                fileName = null;

                                extendedStats.Clear();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Classes.Logger.addLog("Guid: " + guid + "|" + root.ToString() + ":" + ex.ToString(), 1);
                    }
                };
                worker.RunWorkerAsync();
            };
            await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, workAction);
        }
        public async void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {

            classCounts = null;
            classCounts = new classCounters();
            Classes.CustomSnapshotRoot root = null;
            Classes.KeeperAPI keeper = new Classes.KeeperAPI();
            Action workAction = delegate
            {
                BackgroundWorker worker = new  BackgroundWorker();
                worker.DoWork += delegate
                {
                    root = keeper.getKeeperInfo(guid);
                };
                worker.RunWorkerCompleted += async delegate
                {
                    try
                    {
                        if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team1.faction) == "US")
                            imgFaction1.Source = loadBitmap(Properties.Resources.usa);
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team1.faction) == "CN")
                            imgFaction1.Source = loadBitmap(Properties.Resources.china);
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team1.faction) == "RU")
                            imgFaction1.Source = loadBitmap(Properties.Resources.ru);
                        if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team2.faction) == "US")
                            imgFaction2.Source = loadBitmap(Properties.Resources.usa);
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team2.faction) == "CN")
                            imgFaction2.Source = loadBitmap(Properties.Resources.china);
                        else if (Classes.JSONHelper.whatFaction(root.snapshot.teamInfo.team2.faction) == "RU")
                            imgFaction2.Source = loadBitmap(Properties.Resources.ru);
                            
                        foreach (var player in root.snapshot.teamInfo.team1.player)
                        {
                            
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);
                            switch (playerInfo.selectedKit.ToString())
                            {
                                case "0":
                                    classCounts.t1Assault += 1;

                                    if (playerInfo.kitList[0].kitIdInformation[3] != 2887915611 && playerInfo.kitList[0].kitIdInformation[4] != 2887915611)
                                        classCounts.defib += 1;
                                    break; //2887915611
                                case "1":
                                    classCounts.t1Engineer += 1;
                                    break;
                                case "2":
                                    classCounts.t1Support += 1;
                                    break;
                                case "3":
                                    classCounts.t1Recon += 1;
                                    break;
                                default:
                                    break;
                            }
                        }
                        //Assault
                        pbAssault1.Value = classCounts.t1Assault;
                        lblt1Assault.Content = classCounts.t1Assault.ToString();
                        //Engineer
                        pbEngineer1.Value = classCounts.t1Engineer;
                        lblt1Engineer.Content = classCounts.t1Engineer.ToString();
                        //Support
                        pbSupport1.Value = classCounts.t1Support;
                        lblt1Support.Content = classCounts.t1Support.ToString();
                        //Recon
                        pbRecon1.Value = classCounts.t1Recon;
                        lblt1Recon.Content = classCounts.t1Recon.ToString();

                        foreach (var player in root.snapshot.teamInfo.team2.player)
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);
                            switch (playerInfo.selectedKit.ToString())
                            {
                                case "0":
                                    classCounts.t2Assault += 1;
                                    if (playerInfo.kitList[0].kitIdInformation[3] != 2887915611 && playerInfo.kitList[0].kitIdInformation[4] != 2887915611)
                                        classCounts.defib += 1;
                                    break;
                                case "1":
                                    classCounts.t2Engineer += 1;
                                    break;
                                case "2":
                                    classCounts.t2Support += 1;
                                    break;
                                case "3":
                                    classCounts.t2Recon += 1;
                                    break;
                                default:
                                    break;
                            }
                        }
                        //Assault
                        pbAssault2.Value = classCounts.t2Assault;
                        lblt2Assault.Content = classCounts.t2Assault.ToString();
                        //Support
                        pbEngineer2.Value = classCounts.t2Engineer;
                        lblt2Engineer.Content = classCounts.t2Engineer.ToString();
                        //Engineer
                        pbSupport2.Value = classCounts.t2Support;
                        lblt2Support.Content = classCounts.t2Support.ToString();
                        //Recon
                        pbRecon2.Value = classCounts.t2Recon;
                        lblt2Recon.Content = classCounts.t2Recon.ToString();
                        lblAssaultPlayerWithDefibs.Content = classCounts.defib.ToString();
                    }
                    catch (Exception ex)
                    {
                        Classes.Logger.addLog(ex.ToString(), 1);
                    }
                    //Update code in here
                };
                worker.RunWorkerAsync();
            };
            await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, workAction);
        }
        public async void getData()
        {

            Classes.CustomSnapshotRoot root = null;
            Classes.KeeperAPI keeper = new Classes.KeeperAPI();
            Action workAction = delegate
            {
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    root = keeper.getKeeperInfo(guid);
                };
worker.RunWorkerCompleted += async delegate
                {
                    if (root == null)
                    {
                        if (extendedStats.Count == 0)
                        {
                            lblSaved.Content = "Something went wrong with the server";
                            //Potentially exit the form here!
                            _timer.Enabled = false;
                            MessageBox.Show("The server crashed or was never available. \n Please close this window.");
                            this.Close();
                            return;
                        }
                        else
                        {
                            forceSave();
                            extendedStats.Clear();
                            return;
                        }

                    }
                    if (!root.snapshot.status.Equals("SUCCESS", StringComparison.OrdinalIgnoreCase))
                        return;
                    try
                    {
                        int t1count = root.snapshot.teamInfo.team1.player.Count;
                        int t2count = root.snapshot.teamInfo.team2.player.Count;
                        int totalPlayers = t1count + t2count;
                        lblTime.Content = "Round Time: " + Classes.UsefulFunctions.getTime(root.snapshot.roundTime, 1);
                        lblCountPlayers.Content = "Getting Statistics for " + totalPlayers.ToString() + " players";
                        lblMap.Content = "Map: " + Classes.JSONHelper.whatMap(root.snapshot.mapId);
                        lblMode.Content = "Mode: " + Classes.JSONHelper.whatMode(root.snapshot.modeId);
                        foreach( var player in root.snapshot.teamInfo.team1.player )
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);
                        
                            player.kit = playerInfo.selectedKit;
                            player.primaryWeapon = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[0];
                            player.secondaryWeapon = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[1];
                        }
                        foreach (var player in root.snapshot.teamInfo.team2.player)
                        {
                            Classes.Structs.PlayerLoadout playerInfo = await Classes.GetPlayersKit.GetWeaponInfo(player.playerId, player.name);

                            player.kit = playerInfo.selectedKit;
                            player.primaryWeapon = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[0];
                            player.secondaryWeapon = playerInfo.kitList[Convert.ToInt32(playerInfo.selectedKit)].kitIdInformation[1];
                        }
                this.Title = "Logging: " + totalPlayers.ToString() + "P | " + Classes.UsefulFunctions.getTime(root.snapshot.roundTime, 1) + " | " + Classes.JSONHelper.whatMap(root.snapshot.mapId);
                        if (root.snapshot.roundTime != 0)
                        {
                            extendedStats.Add(root);
                        }
                        bool descrEnabled = false;
                        if ((bool)cbAddDescrAuto.IsChecked)
                        {
                            descrEnabled = true;
                        }
                        Classes.DataExport export = new Classes.DataExport(extendedStats, root);
                        string fileName;
                        if (descrEnabled == true)
                        {
                            fileName = export.saveOrNot(txtDescription.Text);
                            if (fileName != "")
                            {
                                lblSaved.Content = "Last Saved at: " + DateTime.Now.ToString();
                                if (cbOpenOnFinish.IsChecked == true)
                                {
                                    XAML.AddBombs addBombs = new XAML.AddBombs(Classes.UsefulFunctions.getFullReport(fileName), fileName);
                                    addBombs.Show();
                                }
                                fileName = null;
                                extendedStats.Clear();
                            }
                        }
                        else
                        {
                            fileName = export.saveOrNot(txtDescription.Text);
                            if (fileName != "")
                            {
                                lblSaved.Content = "Last Saved at: " + DateTime.Now.ToString();
                                if (cbOpenOnFinish.IsChecked == true)
                                {
                                    XAML.AddBombs addBombs = new XAML.AddBombs(Classes.UsefulFunctions.getFullReport(fileName), fileName);
                                    addBombs.Show();

                                }
                                fileName = null;

                                extendedStats.Clear();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Classes.Logger.addLog("Guid: " + guid + "|" + root.ToString() + ":" + ex.ToString(), 1);
                    }

                };
                worker.RunWorkerAsync();
            };
            await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, workAction);
        }