public static void SetCountriesToFile(DictionaryCountries dictionaryCountries) { if (File.Exists(Const.Path)) { File.Delete(Const.Path); try { Console.WriteLine("Writting Countries to File\n"); StringBuilder str = new StringBuilder(); using (StreamWriter sw = new StreamWriter(Const.Path, true, System.Text.Encoding.Default)) { sw.Write($"Country\t\tIsTelenorSupported"); foreach (int k in dictionaryCountries.countries.Keys) { str.Append($"\r\n{dictionaryCountries.countries[k].Name}\t\t{dictionaryCountries.countries[k].IsTelenorSupported}"); } Console.WriteLine(str.ToString()); sw.Write(str.ToString()); } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public static void GetCountriesFromFile(DictionaryCountries dictionaryCountries) { try { Console.WriteLine("Reading Countries:\n"); int i = 0; using (StreamReader sr = new StreamReader(Const.Path, System.Text.Encoding.Default)) { string LineFromFile; while ((LineFromFile = sr.ReadLine()) != null) { if (i == 0) { i++; continue; } List<string> tmp = LineFromFile.Split('\t').ToList(); Console.WriteLine($"{i, 3}. {tmp.First(), -20} {tmp.Last(), -20}"); dictionaryCountries.countries.Add(i, new Country(tmp.First(), bool.Parse(tmp.Last()))); i++; } } } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void DisplayCountries(DictionaryCountries dictionaryCountries, bool isTelenorSupport = false) { StringToPrint += $"\nIsTelenorSupported = {isTelenorSupport} for: \n"; int i = 1; string stringShown; Console.Clear(); foreach (KeyValuePair <int, Country> keyValue in dictionaryCountries.countries) { if (keyValue.Value.IsTelenorSupported == isTelenorSupport) { stringShown = $"{i++}. {keyValue.Value.Name} - {keyValue.Value.IsTelenorSupported}\n"; Console.Write(stringShown); StringToPrint += stringShown; } } }