Пример #1
0
        public static TeamEvents.Event[] GetTeamEvents(string teamKey, int year)
        {
            var teamEventsToReturn = new List <TeamEvents.Event>();

            if (InternetTest.checkInternet())
            {
                var wc = new WebClient();
                wc.Headers.Add("X-TBA-App-Id",
                               "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version);
                try
                {
                    string url = ("http://www.thebluealliance.com/api/v2/team/" + teamKey + "/" + year + "/events");
                    teamEventsToReturn = JsonConvert.DeserializeObject <List <TeamEvents.Event> >(wc.DownloadString(url));
                }
                catch (Exception webError)
                {
                    Console.WriteLine("Error Message: " + webError.Message);
                }
            }
            else
            {
                try
                {
                    string teamNum   = teamKey.Substring(3);
                    string path      = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + "Team" + (Convert.ToInt32(teamNum)) + "EventsDuring.html");
                    string fileLines = File.ReadAllText(path);
                    teamEventsToReturn = JsonConvert.DeserializeObject <List <TeamEvents.Event> >(fileLines);
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error Message: " + exception.Message);
                }
            }
            return(teamEventsToReturn.ToArray());
        }
Пример #2
0
        public static EventTeams.Team[] GetEventTeamsList(string eventKey)
        {
            var teamList = new List <EventTeams.Team>();

            if (InternetTest.checkInternet())
            {
                var wc = new WebClient();
                wc.Headers.Add("X-TBA-App-Id", "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version);
                try
                {
                    string url = ("http://www.thebluealliance.com/api/v2/event/" + eventKey + "/teams");
                    teamList = JsonConvert.DeserializeObject <List <EventTeams.Team> >(wc.DownloadString(url));
                }
                catch (Exception webError)
                {
                    Console.WriteLine("Error Message: " + webError.Message);
                }
            }
            else
            {
                try
                {
                    string path      = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventKey + "Teamlist.html");
                    String fileLines = File.ReadAllText(path);
                    teamList = JsonConvert.DeserializeObject <List <EventTeams.Team> >(fileLines);
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error Message: " + exception.Message);
                }
            }
            return(teamList.ToArray());
        }
Пример #3
0
        public static Models.Events.Event[] GetEvents(int year)
        {
            var dataList = new List <Models.Events.Event>();

            if (InternetTest.checkInternet())
            {
                var wc = new WebClient();
                wc.Headers.Add("X-TBA-App-Id", "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version);
                try
                {
                    string url = ("http://www.thebluealliance.com/api/v2/events/" + year);
                    dataList = JsonConvert.DeserializeObject <List <Models.Events.Event> >(wc.DownloadString(url));
                }
                catch (Exception webError)
                {
                    Console.WriteLine("Error Message: " + webError.Message);
                }
            }
            else
            {
                try
                {
                    string path      = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\DefaultData\\" + year + "YearEvents.html");
                    string fileLines = File.ReadAllText(path);
                    dataList = JsonConvert.DeserializeObject <List <TheBlueAlliance.Models.Events.Event> >(fileLines);
                    return(dataList.ToArray());
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error Message: " + exception.Message);
                }
            }

            return(dataList.ToArray());
        }
Пример #4
0
        /// <summary>
        ///     Provides match information for a specific match
        /// </summary>
        /// <param name="matchKey"></param>
        /// <returns></returns>
        public static MatchInformation.Match GetMatchInformation(string matchKey)
        {
            var matchToReturn = new MatchInformation.Match();

            if (InternetTest.checkInternet())
            {
                var wc = new WebClient();
                wc.Headers.Add("X-TBA-App-Id", "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version);
                try
                {
                    string url = ("http://www.thebluealliance.com/api/v2/match/" + matchKey);
                    matchToReturn = JsonConvert.DeserializeObject <MatchInformation.Match>(wc.DownloadString(url));
                }
                catch (Exception webError)
                {
                    Console.WriteLine("Error Message: " + webError.Message);
                }
            }
            else
            {
                try
                {
                    string path      = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + matchKey + "MatchInfo.html");
                    string fileLines = File.ReadAllText(path);
                    matchToReturn = JsonConvert.DeserializeObject <MatchInformation.Match>(fileLines);
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error Message: " + exception.Message);
                }
            }
            return(matchToReturn);
        }
Пример #5
0
        public static EventRankings.Team[] GetEventRankings(string eventKey)
        {
            var teamList = new List <EventRankings.Team>();

            if (InternetTest.checkInternet())
            {
                var wc = new WebClient();
                wc.Headers.Add("X-TBA-App-Id", "3710-xNovax:FRC_Scouting_V2:" + Assembly.GetExecutingAssembly().GetName().Version);
                try
                {
                    string url      = ("http://www.thebluealliance.com/api/v2/event/" + eventKey + "/rankings");
                    var    dataList = JsonConvert.DeserializeObject <List <List <object> > >(wc.DownloadString(url));

                    for (int i = 1; i < dataList.Count; i++)
                    {
                        var teamToAdd = new EventRankings.Team
                        {
                            Rank         = Convert.ToInt32(dataList.ToArray()[i][0]),
                            Team_Number  = Convert.ToInt32(dataList.ToArray()[i][1]),
                            Qual_Average = Convert.ToDouble(dataList.ToArray()[i][2]),
                            Auto         = Convert.ToInt32(dataList.ToArray()[i][3]),
                            Container    = Convert.ToInt32(dataList.ToArray()[i][4]),
                            Coopertition = Convert.ToInt32(dataList.ToArray()[i][5]),
                            Litter       = Convert.ToInt32(dataList.ToArray()[i][6]),
                            Tote         = Convert.ToInt32(dataList.ToArray()[i][7]),
                            Played       = Convert.ToInt32(dataList.ToArray()[i][8])
                        };
                        teamList.Add(teamToAdd);
                    }
                }
                catch (Exception webError)
                {
                    Console.WriteLine("Error Message: " + webError.Message);
                }
            }
            else
            {
                try
                {
                    string path      = (AppDomain.CurrentDomain.BaseDirectory + "\\Saves\\TBA\\" + eventKey + "Rankings.html");
                    String fileLines = File.ReadAllText(path);
                    var    dataList  = JsonConvert.DeserializeObject <List <List <object> > >(fileLines);
                    for (int i = 1; i < dataList.Count; i++)
                    {
                        var teamToAdd = new EventRankings.Team
                        {
                            Rank         = Convert.ToInt32(dataList.ToArray()[i][0]),
                            Team_Number  = Convert.ToInt32(dataList.ToArray()[i][1]),
                            Qual_Average = Convert.ToDouble(dataList.ToArray()[i][2]),
                            Auto         = Convert.ToInt32(dataList.ToArray()[i][3]),
                            Container    = Convert.ToInt32(dataList.ToArray()[i][4]),
                            Coopertition = Convert.ToInt32(dataList.ToArray()[i][5]),
                            Litter       = Convert.ToInt32(dataList.ToArray()[i][6]),
                            Tote         = Convert.ToInt32(dataList.ToArray()[i][7]),
                            Played       = Convert.ToInt32(dataList.ToArray()[i][8])
                        };
                        teamList.Add(teamToAdd);
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error Message: " + exception.Message);
                }
            }
            return(teamList.ToArray());
        }