/// <summary> /// Handles writing the data to a file. /// </summary> /// <param name="path">The location to save the file.</param> /// <param name="data">The data to save to the file.</param> /// <param name="client">The WebClient object to use for downloading the data.</param> private static void WriteFile(string path, string data, WebClient client) { Console.WriteLine("\nFetching data from the server. This process could take awhile for large wishlists, please wait...\n"); using (StreamWriter streamWriter = new StreamWriter(path)) { while (true) { if (!data.Contains("name")) { SteamApiAccess.SetApiUrl(SteamApiAccess.GetNextPage()); data = client.DownloadString(SteamApiAccess.GetApiUrl()); if (!data.Contains("name")) { break; } } data = data.Substring(data.IndexOf("name") + 7); int locationOfEndingQuote = data.IndexOf('\"'); string gameTitle = Regex.Unescape(data.Substring(0, locationOfEndingQuote)); data = data.Substring(locationOfEndingQuote); streamWriter.WriteLine(char.ToUpper(gameTitle[0]) + gameTitle.Substring(1)); } } ConnectionManager.ReleaseWebClient(); }
/// <summary> /// Attempts to establish a connection with the client. If successful, sets the data to be parsed. /// </summary> private static void GetData() { bool successfulConnection = false; while (!successfulConnection) { try { WishData.SetData(ConnectionManager.GetWebClient().DownloadString(SteamApiAccess.GetApiUrl())); successfulConnection = true; } catch { PromptUserForInput(false); } } }
/// <summary> /// Takes input from the user. /// </summary> /// <param name="firstTimePrompt">Represents whether the user has been prompted for input for the first time.</param> private static void PromptUserForInput(bool firstTimePrompt) { string promptUserForSteamID = "Please enter a SteamID: "; string promptUserForSteamIDOnError = "\nThe SteamID you have entered is invalid.\n\nPlease enter a valid steam ID: "; string promptContent = firstTimePrompt ? promptUserForSteamID : promptUserForSteamIDOnError; string userInput; do { Console.Write(promptContent); userInput = Console.ReadLine(); if (userInput.Equals("exit")) { Environment.Exit(0); } } while (!long.TryParse(userInput, out _)); SteamApiAccess.SetSteamID(userInput); }