private void findEventButton_Click(object sender, EventArgs e) { TheBlueAlliance.Models.Event.EventInformation ei = TheBlueAlliance.Events.GetEventInformation(Convert.ToString(eventCodeEntryTextBox.Text)); locationTextBox.Text = ei.location; eventNameLabel.Text = ("Event Name: " + ei.name); eventSpanLabel.Text = string.Format("Event Date(s): {0} to {1}", ei.start_date, ei.end_date); isOfficialLabel.Text = "Is Official?: " + ei.official; if (ei.official) { isOfficialLabel.ForeColor = Color.Green; } else { isOfficialLabel.ForeColor = Color.Red; } websiteDisplay.Text = ei.website; }
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); } } }
private void cacheTBAEventData(object sender, EventArgs e) { if (MessageBox.Show("This downloads the file(s) for ONE FRC event 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\\"); getEvent : string eventCode = Interaction.InputBox("What is the event code for the event that you want to cache?", "Get Event Info to Cache", "(year) + eventName", -1, -1); if (!(eventCode.Length > 4)) { goto getEvent; } string path = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + "\\*"); string path0 = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + "AllInfo.html"); string path1 = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + ".html"); string path2 = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + "Awards.html"); string path3 = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + "Matches.html"); string path4 = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + "Rankings.html"); string path5 = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventCode + "Teamlist.html"); string appendedUriString = "http://www.thebluealliance.com/event/" + eventCode; TheBlueAlliance.Models.Event.EventInformation eventInfo = TheBlueAlliance.Events.GetEventInformation(eventCode); string tmp = eventInfo.short_name; if (System.String.IsNullOrWhiteSpace(tmp)) { tmp = eventCode.ToUpper().Substring(4); } if (MessageBox.Show(("Is the event: " + tmp + " (" + eventCode + "), correct?"), "Correct event?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.Yes) { Uri siteUri = new Uri(appendedUriString); WebClient client = new WebClient(); //Part 1: Cache base (all?) info byte[] siteData = client.DownloadData(siteUri); string siteDataEncoded = Encoding.ASCII.GetString(siteData); File.WriteAllText(path0, siteDataEncoded); //Add headers for TBA API calls client.Headers.Add("X-TBA-App-Id", "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version); //Redo: Cache basic info using the API siteUri = new Uri("http://www.thebluealliance.com/api/v2/event/" + eventCode); siteData = client.DownloadData(siteUri); siteDataEncoded = Encoding.ASCII.GetString(siteData); File.WriteAllText(path1, siteDataEncoded); //Part 2: Cache event awards siteUri = new Uri("http://www.thebluealliance.com/api/v2/event/" + eventCode + "/awards"); siteData = client.DownloadData(siteUri); siteDataEncoded = Encoding.ASCII.GetString(siteData); File.WriteAllText(path2, siteDataEncoded); //Part 3: Cache event matches siteUri = new Uri("http://www.thebluealliance.com/api/v2/event/" + eventCode + "/matches"); siteData = client.DownloadData(siteUri); siteDataEncoded = Encoding.ASCII.GetString(siteData); File.WriteAllText(path3, siteDataEncoded); //Part 4: Cache event rankings siteUri = new Uri("http://www.thebluealliance.com/api/v2/event/" + eventCode + "/rankings"); siteData = client.DownloadData(siteUri); siteDataEncoded = Encoding.ASCII.GetString(siteData); File.WriteAllText(path4, siteDataEncoded); //Part 5: Cache event team list siteUri = new Uri("http://www.thebluealliance.com/api/v2/event/" + eventCode + "/teams"); siteData = client.DownloadData(siteUri); siteDataEncoded = Encoding.ASCII.GetString(siteData); File.WriteAllText(path5, siteDataEncoded); MessageBox.Show(("Completed saving the data of: " + tmp + " event's data to " + path + "."), "Completed!", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { goto getEvent; } } catch (Exception exception) { Console.Write("Error Occured: " + exception.Message); ConsoleWindow.WriteLine("Error Occured: " + exception.Message); Notifications.ReportCrash(exception); } } }