Example #1
0
        public void displayGamesPlayed(GameObject pastGames, champions champList)
        {
            int ndx         = 0;
            int sizeOfList  = 0;
            int statCounter = 0;

            // Sorts games by game time.
            pastGames.sortObject();

            sizeOfList = pastGames.games.Count;

            // Displays last games of current user.
            for (ndx = 0; ndx < sizeOfList; ndx++)
            {
                // Display info on games played
                Console.WriteLine(pastGames.games[ndx].championId);

                // Write Time and convert from epoch.
                Console.WriteLine("Time in epoch: " + pastGames.games[ndx].createDate);
                DateTime myTime = FromUnixTime(pastGames.games[ndx].createDate);
                string   format = "hh:mm:ss tt yyyy";  // Use this format
                Console.WriteLine(myTime.ToString(format));

                Console.WriteLine("\n");
            }

            Console.WriteLine("Largest Stat: " + statCounter);
        }
Example #2
0
        public void getChampionsFromAPI(string API_URL, ref champions liveChampionList, ref bool errorConnection)
        {
            WebRequest request_champ_stream;

            try
            {
                // Open stream and generate URI request
                Console.Write("\n");
                Console.WriteLine("Opening URL");
                request_champ_stream             = WebRequest.Create(API_URL);
                request_champ_stream.Credentials = CredentialCache.DefaultCredentials;

                // Get Response
                Console.WriteLine("\nThe Timeout time of the request before setting is : {0} milliseconds", request_champ_stream.Timeout);

                // Setting 'Timeout' property in Milliseconds
                request_champ_stream.Timeout = 30000;
                Console.Write("Waiting on Web Response: ");

                // 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
                Console.WriteLine("Converting stream to string.");
                string responseFromServer = reader.ReadToEnd();


                // Parse Data from server
                Console.WriteLine("Parsing Data");
                liveChampionList = JsonConvert.DeserializeObject <champions>(responseFromServer);

                Console.WriteLine("Closing Stream");
                reader.Close();
                response.Close();
            }
            catch (WebException e)
            {
                errorConnection = true;
                Console.WriteLine("This program can't comminicate with the Web Server." +
                                  "\n\nException Message :" + e.Message);
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    Console.WriteLine("Status Code : {0}", ((HttpWebResponse)e.Response).StatusCode);
                    Console.WriteLine("Status Description : {0}", ((HttpWebResponse)e.Response).StatusDescription);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }