Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var mobileOperator = new MobileOperator();

            var mobileAccount1 = new MobileAccount(123, "Alex");
            var mobileAccount2 = new MobileAccount(456, "Max");

            mobileOperator.AddNumber(mobileAccount1);
            mobileOperator.AddNumber(mobileAccount2);
            mobileAccount1.AddContact(456, "Max");

            mobileAccount2.MakeCall(123);
            mobileAccount2.MakeCall(123);
            mobileAccount2.MakeCall(123);
            mobileAccount2.MakeCall(123);
            mobileAccount1.MakeCall(456);
            mobileAccount1.MakeCall(456);
            mobileAccount1.MakeCall(456);

            mobileAccount2.SendMessage(123, "Hello");


            Console.WriteLine("Most Frequently Receiving Numbers");
            mobileOperator.MostFrequentlyReceivingNumbers(5);

            Console.WriteLine("Most Frequently Sendering Numbers");
            mobileOperator.MostFrequentlySendingNumbers(5);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var mobileOperator = new MobileOperator();

            var mobileAccount1 = new MobileAccount("Max", "Kh", new DateTime(1998, 6, 23), new MailAddress("*****@*****.**"));

            var mobileAccount2 = new MobileAccount("Alex", "Kh", new DateTime(1992, 11, 27), new MailAddress("*****@*****.**"));

            mobileOperator.AddNumber(mobileAccount1);
            mobileOperator.AddNumber(mobileAccount2);

            mobileAccount1.AddContact(mobileAccount2.Number, new SubName("Alex"));

            mobileAccount1.MakeCall(mobileAccount2.Number);
            mobileAccount1.MakeCall(mobileAccount2.Number);
            mobileAccount1.MakeCall(mobileAccount2.Number);

            mobileAccount2.SendMessage(mobileAccount1.Number, "Hello");

            Console.WriteLine("Most Frequently Receiving Numbers");
            mobileOperator.Log.MostFrequentlyReceivingNumbers(5);

            Console.WriteLine("Most Frequently Sendering Numbers");
            mobileOperator.Log.MostFrequentlySendingNumbers(5);
        }
Exemplo n.º 3
0
        public void AddNumber(MobileAccount mobileAccount)
        {
            if (!Validate(mobileAccount) || _mobileAccounts.ContainsValue(mobileAccount))
            {
                return;
            }
            var phoneNumber = GenPhoneNumber();

            mobileAccount.Number = phoneNumber;

            mobileAccount.CallEvent    += MobileAccount_CallEvent;
            mobileAccount.MessageEvent += MobileAccount_MessageEvent;

            var document = new XmlDocument();

            document.Load("contacts.xml");

            var element = document.CreateElement("mobileAccount");

            document.DocumentElement.AppendChild(element);
            var attribute = document.CreateAttribute("number");

            attribute.Value = mobileAccount.Number.ToString();
            element.Attributes.Append(attribute);

            var firstNameElement = document.CreateElement("firstName");

            firstNameElement.InnerText = mobileAccount.FirstName;
            element.AppendChild(firstNameElement);

            var lastNameElement = document.CreateElement("lastName");

            lastNameElement.InnerText = mobileAccount.LastName;
            element.AppendChild(lastNameElement);

            var birthdayElement = document.CreateElement("birthday");

            birthdayElement.InnerText = mobileAccount.Birthday.ToString();
            element.AppendChild(birthdayElement);

            var emailElement = document.CreateElement("email");

            emailElement.InnerText = mobileAccount.Email;
            element.AppendChild(emailElement);

            document.Save("contacts.xml");
            _mobileAccounts.Add(phoneNumber, mobileAccount);
        }
Exemplo n.º 4
0
        public void AddNumber(MobileAccount mobileAccount)
        {
            if (!Validate(mobileAccount))
            {
                return;
            }
            var phoneNumber = GenPhoneNumber();

            while (_mobileAccounts.ContainsKey(phoneNumber))
            {
                phoneNumber = GenPhoneNumber();
            }
            mobileAccount.Number = phoneNumber;
            _mobileAccounts.Add(phoneNumber, mobileAccount);
            mobileAccount.CallEvent    += MobileAccount_CallEvent;
            mobileAccount.MessageEvent += MobileAccount_MessageEvent;
        }
Exemplo n.º 5
0
        private bool Validate(MobileAccount mobileAccount)
        {
            var results = new List <ValidationResult>();
            var context = new ValidationContext(mobileAccount);

            if (!Validator.TryValidateObject(mobileAccount, context, results, true))
            {
                foreach (var error in results)
                {
                    Console.WriteLine(error.ErrorMessage);
                }

                return(false);
            }

            Console.WriteLine("User '{0} {1}' is Valid", mobileAccount.FirstName, mobileAccount.LastName);
            return(true);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var mobileOperator = new MobileOperator();

            var mobileAccount1 = new MobileAccount("Max", "Kh", new DateTime(1998, 6, 23), "*****@*****.**");
            var mobileAccount2 = new MobileAccount("Alex", "Kh", new DateTime(1992, 11, 27), "*****@*****.**");

            mobileOperator.AddNumber(mobileAccount1);
            mobileOperator.AddNumber(mobileAccount2);

            Console.WriteLine(mobileAccount1.Number);
            Console.WriteLine(mobileAccount2.Number);

            mobileAccount1.MakeCall(mobileAccount2.Number);

            mobileAccount2.MakeCall(mobileAccount1.Number);

            mobileAccount1.SendMessage(mobileAccount2.Number, "Message text");

            mobileOperator.Log.MostFrequentlyReceivingNumbers(5);
        }
Exemplo n.º 7
0
 public void AddNumber(MobileAccount mobileAccount)
 {
     _mobileAccounts.Add(mobileAccount);
     mobileAccount.CallEvent    += MobileAccount_CallEvent;
     mobileAccount.MessageEvent += MobileAccount_MessageEvent;
 }