Example #1
0
 private Tuple <int, string> FindTuppleByKey(string key)
 {
     return(OutgoingCallHistory
            .Where(
                x => x.Item2.Equals(key)
                ).SingleOrDefault());
 }
Example #2
0
        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;
        }
Example #3
0
        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());
        }
Example #4
0
        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;
        }
Example #5
0
        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);
        }
Example #6
0
        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;
        }