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); 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); mobileOperator.PersistJson(); mobileOperator.RestoreJson(); }
static void Main(string[] args) { MobileOperator mobileOperator = new MobileOperator(); MobileAccount mobileAccount1 = new MobileAccount(123, "Alex"); MobileAccount 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); }
public MobileAccount CreateAccount(int number) { var acc = new MobileAccount(number, this); _accounts.Add(number, acc); acc.OnMessagePost += RouteMessage; acc.OnCall += RouteCall; return(acc); }
public void AddNumber(MobileAccount mobileAccount) { var phoneNumber = GenPhoneNumber(); while (_mobileAccounts.ContainsKey(phoneNumber)) { phoneNumber = GenPhoneNumber(); } mobileAccount.Number = phoneNumber; _mobileAccounts.Add(phoneNumber, mobileAccount); mobileAccount.CallEvent += MobileAccount_CallEvent; mobileAccount.MessageEvent += MobileAccount_MessageEvent; }
public void AddNumber(MobileAccount mobileAccount) { if (_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); }
static void Main(string[] args) { MobileOperator mobileOperator = new MobileOperator(); MobileAccount mobileAccount1 = new MobileAccount(123, "Alex"); MobileAccount mobileAccount2 = new MobileAccount(456, "Max"); mobileOperator.AddNumber(mobileAccount1); mobileOperator.AddNumber(mobileAccount2); mobileAccount1.AddContact(456, "Max"); mobileAccount2.MakeCall(123); mobileAccount2.SendMessage(123, "Hello"); }
private void 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) { throw new Exception(error.ErrorMessage); } } else { Console.WriteLine("User '{0} {1}' is Valid", mobileAccount.FirstName, mobileAccount.LastName); } }
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); }
public Log(MobileAccount sender, MobileAccount receiver, double rate) { Sender = sender; Receiver = receiver; Rate = rate; }
public void AddNumber(MobileAccount mobileAccount) { mobileAccounts.Add(mobileAccount); mobileAccount.CallEvent += MobileAccount_CallEvent; mobileAccount.MessageEvent += MobileAccount_MessageEvent; }