private void findTeamButton_Click(object sender, EventArgs e)
 {
     TheBlueAlliance.Models.TeamInformation ti = TheBlueAlliance.Teams.GetTeamInformation("frc" + teamNumber);
     teamName     = Convert.ToString(ti.nickname);
     teamNumber   = Convert.ToInt16(ti.team_number);
     teamLocation = Convert.ToString(ti.location);
     rookieYear   = Convert.ToInt32(ti.rookie_year);
     teamWebsite  = Convert.ToString(ti.website);
     Console.WriteLine("The information for team: " + Convert.ToString(teamNumber) +
                       " has been found successfully.");
     ConsoleWindow.WriteLine("The information for team: " + Convert.ToString(teamNumber) +
                             " has been found successfully.");
     teamNameDisplay.Text     = teamName;
     teamNumberDisplay.Text   = Convert.ToString(teamNumber);
     teamLocationDisplay.Text = teamLocation;
     teamWebsiteDisplay.Text  = teamWebsite;
     rookieYearDisplay.Text   = Convert.ToString(rookieYear);
     if (teamNumber == 3710)
     {
         MessageBox.Show("BEST TEAM EVER! Please invite to your alliance!");
     }
 }
Example #2
0
 private void cacheATeamsTBADataToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("This downloads the file(s) for ONE FRC team from TBA. The downloading of these file(s) may take a long time, and these files may take up a lot of storage space. Are you sure you want to continue?", "Are you sure you want to continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
     {
         try
         {
             Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\Saves");
             Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\");
             getTeamNum : string teamNum = Interaction.InputBox("What is the team number for the team's info that you want to cache?", "Get Team Num's Info to Cache", "(226)", -1, -1);
             string path              = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "\\*");
             string path0             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "AllInfo.html");
             string path1             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "Info.html");
             string path2             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "AwardsAt");
             string path3             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "MatchesAt");
             string path4             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "EventsDuring");
             string path5             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "HistoricalAwards.html");
             string path6             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "HistoricalEvents.html");
             string path7             = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "MediaLocationsDuring");
             string appendedUriString = "http://www.thebluealliance.com/team/" + (Convert.ToInt32(teamNum));
             TheBlueAlliance.Models.TeamInformation teamInfo = TheBlueAlliance.Teams.GetTeamInformation("frc" + (Convert.ToInt32(teamNum)));
             string tmp     = teamInfo.nickname;
             string teamKey = teamInfo.key;
             if (MessageBox.Show(("Is the team: " + tmp + " (Team " + (Convert.ToInt32(teamNum)) + "), correct?"), "Correct event?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes)
             {
                 //Part 1: Cache base (all?) info
                 Uri       siteUri         = new Uri(appendedUriString);
                 WebClient client          = new WebClient();
                 byte[]    siteData        = client.DownloadData(siteUri);
                 string    siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(path0, siteDataEncoded);
                 //Add headers for TBA API
                 client.Headers.Add("X-TBA-App-Id", "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version);
                 //Redo: Cache basic info using the API
                 string url = ("http://www.thebluealliance.com/api/v2/team/" + teamKey);
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(path1, siteDataEncoded);
                 //Get event name:
                 getEventName : string eventCode = Interaction.InputBox("What is the event key for the team's info at that event that you want to cache?", "Get Event Key's Event Info to Cache", "(year) + (code)", -1, -1);
                 TheBlueAlliance.Models.Event.EventInformation eventInfo = TheBlueAlliance.Events.GetEventInformation(eventCode);
                 tmp = eventInfo.short_name;
                 if (System.String.IsNullOrWhiteSpace(tmp))
                 {
                     tmp = eventCode.ToUpper().Substring(4);
                 }
                 if (!(MessageBox.Show(("Is the event: " + tmp + " (With team Team " + (Convert.ToInt32(teamNum)) + "), correct?"), "Correct event?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes))
                 {
                     goto getEventName;
                 }
                 //Part 2: Cache a teams awards at one event
                 url = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/event/" + eventCode + "/awards");
                 string thisPath = path2 + eventCode + ".html";
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(thisPath, siteDataEncoded);
                 //Part 3: Cache a teams matches at one event
                 url = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/event/" + eventCode +
                        "/matches");
                 thisPath        = path3 + eventCode + ".html";
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(thisPath, siteDataEncoded);
                 //Part 4: Get a teams events for one year
                 string year = Interaction.InputBox("What is the year for the team's info at that event that you want to cache?", "Get Year To Cache Team Info For", "2015", -1, -1);
                 url             = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/" + year + "/events");
                 thisPath        = path4 + year + ".html";
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(thisPath, siteDataEncoded);
                 //Part 5: Get a teams media locations for one year
                 url             = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/" + year + "/media");
                 thisPath        = path7 + year + ".html";
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(thisPath, siteDataEncoded);
                 //Part 6: Get a teams historical awards
                 url             = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/history/awards");
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(path5, siteDataEncoded);
                 //Part 7: Get a teams historical events
                 url             = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/history/events");
                 siteData        = client.DownloadData(new Uri(url));
                 siteDataEncoded = Encoding.ASCII.GetString(siteData);
                 File.WriteAllText(path6, siteDataEncoded);
                 MessageBox.Show(("Completed saving the data of: " + appendedUriString + " to " + path + "."), "Completed!", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             }
             else
             {
                 goto getTeamNum;
             }
         }
         catch (Exception exception)
         {
             Console.Write("Error Occured: " + exception.Message);
             ConsoleWindow.WriteLine("Error Occured: " + exception.Message);
             Notifications.ReportCrash(exception);
         }
     }
 }