コード例 #1
0
        public bool WriteInBook(List <Person> dataOfSomePeople)
        {
            if (dataOfSomePeople == null || dataOfSomePeople.Count < 1)
            {
                throw new ArgumentException("Null or empty list of personal data provided to WriteInBook(List<Person>)!");
            }

            if (this.aPhoneBook == null)
            {
                this.aPhoneBook = new PhoneBook();
            }
            this.aPhoneBook.people = dataOfSomePeople;
            return(true);
        }
コード例 #2
0
        public static bool ExecuteAddCommand(string[] command, PhoneBook onPhoneBook)
        {
            List <Person> aPersonToAdd = new List <Person>(1);

            aPersonToAdd.Add(new Person(command[1], command[2], command[3]));
            onPhoneBook.people = aPersonToAdd;
            if (command.Length > 4 &&
                (command[4] != null && command[4].Trim().Length > 0)
                )//If also to add this person to a specified .txt file representation of the phonebook
            {
                return(WriteBookContentIntoFile(aPersonToAdd, command[4], JSONFileType));
            }
            return(true);
        }
コード例 #3
0
        public static PhoneBook Open()
        {
            PhoneBook b = null;

            try
            {
                if (File.Exists(fileAddress))
                {
                    using (var stream = File.Open(@"..\..\Test\PhoneBook.dat", FileMode.Open))
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        b = (PhoneBook)bf.Deserialize(stream);          //convert file to object
                    }
                }
            }
            catch { }
            return(b);
        }