/***************************************************************** * Method Name: void displayActiveRoster(ChampionObject) * Arguements: displayName * Purpose: Displays all current champions that are active in game. *****************************************************************/ public void displayActiveRoster(ChampionListDto championList, ChampionListDTO championListDTO) { // Determines if the list is empty. bool isEmpty = false; int code = 0; string whyItFailed = ""; if (championList == null) { isEmpty = true; } championList.getErrorCode(ref code, ref whyItFailed); if (championListDTO == null) { isEmpty = true; } if ((int)code == 200) // Success! { if (!isEmpty) { foreach (var champion in championListDTO.data) { Console.WriteLine("Name: {0} - ID: {1} ", champion.Key, champion.Value.id); } } else { Console.WriteLine("List is empty."); } } else // Failed! { Console.WriteLine("-- Failed --"); Console.WriteLine("Error Code: " + code); Console.WriteLine("Reason: " + whyItFailed); } return; }
static void Main(string[] args) { mainMenu menuObject = new mainMenu(); bool menuLoop = true; bool errorConnection = false; bool fileCreate = false; int menuItem = 0; string fileSettings = "Settings.ini"; // Json objects from servers ChampionListDto liveChampionList = new ChampionListDto(); GameObject pastGames = new GameObject(); league_v2_3 summonerLeagueLadder = new league_v2_3(); API_Call Operator = new API_Call(); summonerProfile summonerStats = new summonerProfile(); stats_v1_2_Ranked testStats = new stats_v1_2_Ranked(); ChampionListDTO listOfChampions = new ChampionListDTO(); // Operator makes call and grabs data from Riot. Operator.MakeCall(ref liveChampionList); Console.WriteLine("Calling pastGames"); Operator.MakeCall(ref pastGames); Console.WriteLine("Calling summonerLeagueLadder"); Operator.MakeCall(ref summonerLeagueLadder); Operator.MakeCall(ref testStats); Operator.MakeCall(ref listOfChampions); // Determines if user has run the program before. fileCreate = menuObject.checkFile(fileSettings); // Creates a file for user; mostly ini if (fileCreate) { } if (!errorConnection) { while (menuLoop) { menuObject.displayMenu(ref menuItem); switch (menuItem) { case 1: // Display Active Roster menuObject.displayActiveRoster(liveChampionList, listOfChampions); break; case 2: //Display Free to Play Roster // menuObject.displayFreeToPlay(liveChampionList); break; case 3: // Change Current Region // menuObject.displayBotChampions(liveChampionList); break; case 4: // Displays last 10 games from user. // menuObject.displayGamesPlayed(pastGames, liveChampionList); break; case 5: // Display players in current league of player menuObject.displayLeaderBoard(ref summonerLeagueLadder); break; case 6: // Display Summary Stats menuObject.displaySummaryStats(summonerStats); break; default: menuLoop = false; break; } // Exit program by user. if (menuItem == 0) { menuLoop = false; } } } else { Console.WriteLine("Closing program."); } Console.WriteLine("Hit any-key"); Console.Read(); }
public void MakeCall(ref ChampionListDTO listOfChampions) { // https://{region}.api.pvp.net/api/lol/ WebRequest request_champ_stream; string responseFromServer; string API_URL = "https://na.api.pvp.net/api/lol/static-data/na/v1.2/champion" + api_Key; string temp = API_URL; API_URL = temp.Replace("{region}", user_region); temp = API_URL; // Displays where at Console.WriteLine("listOfChampions Object Call"); try { // Open stream and generate URI request WebRequest.Create(API_URL); request_champ_stream = WebRequest.Create(API_URL); request_champ_stream.Credentials = CredentialCache.DefaultCredentials; // Setting 'Timeout' property in Milliseconds request_champ_stream.Timeout = 30000; // This request will throw a WebException if it reaches the timeout limit before it is able to fetch the resource. WebResponse response = request_champ_stream.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream contaning content returned by the server. Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); // Reading content from server and converting it to string type. responseFromServer = reader.ReadToEnd(); // Parse Data from server into object listOfChampions = JsonConvert.DeserializeObject <ChampionListDTO>(responseFromServer); // Closing Stream reader.Close(); response.Close(); errorResponse = false; } // Determines if the call failed. catch (WebException e) { Console.WriteLine("This program can't comminicate with the Web Server." + "\n\nException Message :" + e.Message); if (e.Status == WebExceptionStatus.ProtocolError) { errorHTTPStatusCode = "Status Code : {0}" + (((HttpWebResponse)e.Response).StatusCode).ToString(); Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode); errorReason = "Status Description : {0}" + (((HttpWebResponse)e.Response).StatusDescription).ToString(); Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription); } } catch (Exception e) { Console.WriteLine(e.Message); } return; }