diff --git a/src/Wiki.Net.Example/Example.cs b/src/Wiki.Net.Example/Example.cs index a3652ea..c5abaf7 100644 --- a/src/Wiki.Net.Example/Example.cs +++ b/src/Wiki.Net.Example/Example.cs @@ -3,79 +3,79 @@ namespace WikiDotNet.Example { - internal static class Example - { - private static void Main() - { - #region Using a proxy for requests + internal static class Example + { + private static void Main() + { + #region Using a proxy for requests - GetProxy: - string useProxy = AskUserString("Use a proxy to connect?", false).ToLower(); - switch (useProxy) - { - case "true": - case "yes": - case "y": - WikiSearcher.Proxy = new WebProxy(AskUserString("Enter the proxy address")) - { - Credentials = new NetworkCredential(AskUserString("Enter the proxy username"), - AskUserString("Enter the proxy password")) - }; - break; - case "false": - case "no": - case "n": - break; - default: - Console.Clear(); - Console.WriteLine("Enter a valid response (Y/N or true/false)"); - goto GetProxy; - } + GetProxy: + string useProxy = AskUserString("Use a proxy to connect?", false).ToLower(); + switch (useProxy) + { + case "true": + case "yes": + case "y": + WikiSearcher.Proxy = new WebProxy(AskUserString("Enter the proxy address")) + { + Credentials = new NetworkCredential(AskUserString("Enter the proxy username"), + AskUserString("Enter the proxy password")) + }; + break; + case "false": + case "no": + case "n": + break; + default: + Console.Clear(); + Console.WriteLine("Enter a valid response (Y/N or true/false)"); + goto GetProxy; + } - #endregion + #endregion - #region Loop until the user exits + #region Loop until the user exits - WikiSearchSettings searchSettings = new WikiSearchSettings - {RequestId = "Request ID", ResultLimit = 5, ResultOffset = 2, Language = "en"}; - Request: - //Get a search from the user, or exit - string req = AskUserString("Enter a search query, 'exit' or 'quit' to quit"); - // ReSharper disable once SwitchStatementMissingSomeCases - switch (req.ToLower()) - { - case "quit": - case "exit": - Console.WriteLine("Exiting..."); - return; - } + WikiSearchSettings searchSettings = new() + {RequestId = "Request ID", ResultLimit = 5, ResultOffset = 2, Language = "en"}; + Request: + //Get a search from the user, or exit + string req = AskUserString("Enter a search query, 'exit' or 'quit' to quit"); + // ReSharper disable once SwitchStatementMissingSomeCases + switch (req.ToLower()) + { + case "quit": + case "exit": + Console.WriteLine("Exiting..."); + return; + } - Console.Clear(); - PrintResults(req, searchSettings); - //Wait until the user presses enter to search again - Console.WriteLine("Press any key to search again"); - Console.ReadKey(true); - goto Request; + Console.Clear(); + PrintResults(req, searchSettings); + //Wait until the user presses enter to search again + Console.WriteLine("Press any key to search again"); + Console.ReadKey(true); + goto Request; - #endregion - } + #endregion + } - private static void PrintResults(string searchString, WikiSearchSettings searchSettings = null) - { - WikiSearchResponse response = WikiSearcher.Search(searchString, searchSettings); + private static void PrintResults(string searchString, WikiSearchSettings searchSettings = null) + { + WikiSearchResponse response = WikiSearcher.Search(searchString, searchSettings); - Console.WriteLine($"\nResults found ({searchString}):\n"); - foreach (WikiSearchResult result in response.Query.SearchResults) - Console.WriteLine( - $"\t{result.Title} ({result.WordCount} words, {result.Size} bytes, id {result.PageId}):\t{result.Preview}...\n\tAt {result.Url(searchSettings.Language)} and {result.ConstantUrl(searchSettings.Language)}\n\tLast edited at {result.LastEdited}\n"); - } + Console.WriteLine($"\nResults found ({searchString}):\n"); + foreach (WikiSearchResult result in response.Query.SearchResults) + Console.WriteLine( + $"\t{result.Title} ({result.WordCount} words, {result.Size} bytes, id {result.PageId}):\t{result.Preview}...\n\tAt {result.Url(searchSettings.Language)} and {result.ConstantUrl(searchSettings.Language)}\n\tLast edited at {result.LastEdited}\n"); + } - private static string AskUserString(string message, bool clearConsole = true) - { - if (clearConsole) - Console.Clear(); - Console.WriteLine(message); - return Console.ReadLine(); - } - } + private static string AskUserString(string message, bool clearConsole = true) + { + if (clearConsole) + Console.Clear(); + Console.WriteLine(message); + return Console.ReadLine(); + } + } } \ No newline at end of file