private Tuple <int, string> FindTuppleByKey(string key) { return(OutgoingCallHistory .Where( x => x.Item2.Equals(key) ).SingleOrDefault()); }
public BulgarianPhoneBook(string filePathAndName) : base() { StreamReader file = GetFileFromFilePathAndName(filePathAndName); string line; while ((line = file.ReadLine()) != null) { KeyValuePair <string, string> pair; try { pair = GetDataFromRecord(line); string normalizedName = NormalizeName(pair.Key); string value = GetValueByKey(normalizedName); if (value == null) { ContactsList.Add(normalizedName, pair.Value); OutgoingCallHistory.Add(new Tuple <int, string>(0, normalizedName)); } } catch (InvalidDataException) { continue; } } file.Close(); ChachedHasToChange = true; }
public string ListTopCalledCalls() { int counter = TopOutgoingCallsListCount; StringBuilder builder = new StringBuilder(""); var enumerator = OutgoingCallHistory.GetEnumerator(); while (enumerator.MoveNext()) { Tuple <int, string> current = enumerator.Current; string phoneNumber = GetValueByKey(current.Item2); builder.Append(current.Item2) .Append(' ') .Append(phoneNumber) .Append(" - ") .Append(current.Item1) .Append(" times") .Append('\n'); if (--counter <= 0) { break; } } return(builder.ToString()); }
public void DeletePairByName(string name) { string normalizedName = NormalizeName(name); string value = GetValueByKey(normalizedName); if (value == null) { throw new KeyNotFoundException(); } ContactsList.Remove(normalizedName); OutgoingCallHistory.Remove(FindTuppleByKey(normalizedName)); ChachedHasToChange = true; }
public void AddOutgoingCall(string name) { string normalizedName = NormalizeName(name); Tuple <int, string> current = FindTuppleByKey(normalizedName); if (current == null) { throw new Exception("The key does not exist."); } OutgoingCallHistory.Remove(current); Tuple <int, string> newTupple = new Tuple <int, string>(current.Item1 + 1, current.Item2); OutgoingCallHistory.Add(newTupple); }
public void AddNewPair(string name, string phoneNumber) { string normalizedName = NormalizeName(name); string value = GetValueByKey(normalizedName); if (value != null) { throw new Exception("Key already exist"); } int counter = phoneNumber.Length - 1; StringBuilder data = GetPhoneNumberFromRecord(ref counter, phoneNumber); ContactsList.Add(normalizedName, data.ToString()); OutgoingCallHistory.Add(new Tuple <int, string>(0, normalizedName)); ChachedHasToChange = true; }