/// <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); } } }