public static void contactsBook(MobileAccount account) { foreach (var contact in account.Contacts) { Console.WriteLine("{0}: {1}", contact.Name, contact.Account); } }
public void SendSMS(MobileAccount forWhom, string message) { if (SentSMS != null) { SentSMS(this, new MobileEventArgs(MobileOperation.SMS, forWhom, message)); } }
public void MakeCall(MobileAccount forWhom) { if (MadeCall != null) { MadeCall(this, new MobileEventArgs(MobileOperation.Call, forWhom)); } }
public void AddAccount(MobileAccount account) { if (!IsExistAccount(account)) { _storage.Add(account.ToString().GetHashCode(), account); } }
private void IncomingCall(MobileAccount from) { var existNumber = Contacts.Where(i => i.Account == from).ToArray(); Console.WriteLine("Incoming Call to {0}!", this); Console.WriteLine("From: {0}", existNumber.Length != 0 ? existNumber[0].Name : from.ToString()); }
static void Main(string[] args) { MobileOperator mOperator1 = new MobileOperator("096", "Kievstar"); MobileOperator mOperator2 = new MobileOperator("097", "Kievstar"); MobileOperator mOperator3 = new MobileOperator("098", "Kievstar"); MobileOperator mOperator4 = new MobileOperator("093", "Life"); MobileOperator mOperator5 = new MobileOperator("063", "Life"); MobileAccount account1 = new MobileAccount(mOperator1); MobileAccount account2 = new MobileAccount(mOperator1); MobileAccount account3 = new MobileAccount(mOperator1); MobileAccount account4 = new MobileAccount(mOperator2); MobileAccount account5 = new MobileAccount(mOperator3); MobileAccount account6 = new MobileAccount(mOperator4); MobileAccount account7 = new MobileAccount(mOperator5); account1.AddContact(account2.Name, account2); account1.AddContact(account3.Name, account3); account2.AddContact(account1.Name, account1); account2.AddContact(account3.Name, account3); account3.AddContact(account1.Name, account1); account3.AddContact(account2.Name, account2); account4.AddContact(account1.Name, account1); account4.AddContact(account2.Name, account2); account4.AddContact(account3.Name, account3); account4.AddContact(account4.Name, account4); account4.AddContact(account5.Name, account5); account4.AddContact(account6.Name, account6); account4.AddContact(account7.Name, account7); Console.WriteLine("Contacts {0}", account1.Name); MobileAccount.contactsBook(account1); Console.WriteLine("Contacts {0}", account2.Name); MobileAccount.contactsBook(account2); Console.WriteLine("Contacts {0}", account3.Name); MobileAccount.contactsBook(account3); Console.WriteLine("Contacts {0}", account4.Name); MobileAccount.contactsBook(account4); Console.WriteLine(""); account1.SendSMS(account2, "Message"); Console.WriteLine(""); account3.MakeCall(account1); Console.WriteLine(""); account2.SendSMS(account1, "Message1"); Console.WriteLine(""); account4.SendSMS(account2, "Message2"); Console.WriteLine(""); Console.ReadKey(); }
private void IncomingSMS(MobileAccount from, string message) { var existNumber = Contacts.Where(i => i.Account == from).ToArray(); Console.WriteLine("{0} received SMS!", this); Console.WriteLine("From: {0}", existNumber.Length != 0 ? existNumber[0].Name : from.ToString()); Console.WriteLine("Text: {0}", message); }
public static void SerializationCompare() { BinarySerialization <MobileAccount> binarySerialization = new BinarySerialization <MobileAccount>(); XmlSerialization <MobileAccount> xmlSerialization = new XmlSerialization <MobileAccount>(); JsonSerialization <MobileAccount> jsonSerialization = new JsonSerialization <MobileAccount>(); ProtoBufSerialization <MobileAccount> protoBufSerialization = new ProtoBufSerialization <MobileAccount>(); MobileOperator mOperator3 = new MobileOperator("098", "Kievstar"); MobileOperator mOperator4 = new MobileOperator("093", "Life"); MobileAccount account1 = new MobileAccount(mOperator3); MobileAccount account2 = new MobileAccount(mOperator4); account1.AddContact(account2.Name, account2); account2.AddContact(account1.Name, account1); List <MobileAccount> testList = new List <MobileAccount>(); for (int i = 0; i < 100000; i++) { testList.Add(account1); testList.Add(account2); } Console.WriteLine("Serialization"); Stopwatch watchBinary = Stopwatch.StartNew(); binarySerialization.Serialize(testList); watchBinary.Stop(); Console.WriteLine("Binary: {0} ms", watchBinary.ElapsedMilliseconds); Stopwatch watchXml = Stopwatch.StartNew(); xmlSerialization.Serialize(testList); watchXml.Stop(); Console.WriteLine("XML: {0} ms", watchXml.ElapsedMilliseconds); Stopwatch watchJson = Stopwatch.StartNew(); jsonSerialization.Serialize(testList); watchJson.Stop(); Console.WriteLine("JSON: {0} ms", watchJson.ElapsedMilliseconds); Stopwatch watchProtoBuf = Stopwatch.StartNew(); protoBufSerialization.Serialize(testList); watchProtoBuf.Stop(); Console.WriteLine("Protobuf: {0} ms", watchProtoBuf.ElapsedMilliseconds); }
public void SendMessage(MobileAccount forWhom, string message) { MethodBase method = MethodBase.GetCurrentMethod(); Level level = OperatorMessageAttribute.GetAttributeInfo(method); if (Balance >= _messagePrice) { if (SentSMS != null) { SentSMS(this, new MobileEventArgs(MobileOperation.Message, forWhom, message)); Balance -= _messagePrice; } } else { if (level == Level.Warn) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("It's not enought money to send message to {0}!", forWhom); Console.ForegroundColor = ConsoleColor.White; } } }
public void MakeCall(MobileAccount forWhom) { MethodBase method = MethodBase.GetCurrentMethod(); Level level = OperatorMessageAttribute.GetAttributeInfo(method); if (Balance >= _callPrice) { if (MadeCall != null) { MadeCall(this, new MobileEventArgs(MobileOperation.Call, forWhom)); Balance -= _callPrice; } } else { if (level == Level.Warn) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("It's not enought money to make call to {0}!", forWhom); Console.ForegroundColor = ConsoleColor.White; } } }
public MobileEventArgs(MobileOperation operation, MobileAccount forWhom) { Operation = operation; ForWhom = forWhom; }
public void DeleteContact(MobileAccount account) { Contacts.Remove(Contacts.Where(i => i.Account == account).ToArray()[0]); }
public void AccountRegistration(MobileAccount account) { account.SentSMS += SMS; account.MadeCall += Call; _storage.AddAccount(account); }
public static void SerializationCompare() { BinarySerialization <MobileAccount> binarySerialization = new BinarySerialization <MobileAccount>(); XmlSerialization <MobileAccount> xmlSerialization = new XmlSerialization <MobileAccount>(); MobileOperator mOperator3 = new MobileOperator("098", "Kievstar"); MobileOperator mOperator4 = new MobileOperator("093", "Life"); MobileAccount account1 = new MobileAccount(mOperator3); MobileAccount account2 = new MobileAccount(mOperator4); MobileAccount account3 = new MobileAccount(mOperator3); MobileAccount account4 = new MobileAccount(mOperator4); account1.AddContact(account2.Name, account2); account2.AddContact(account1.Name, account1); account1.AddContact(account3.Name, account3); account2.AddContact(account4.Name, account4); List <MobileAccount> testList = new List <MobileAccount>(); for (int i = 0; i < 5; i++) { testList.Add(account1); testList.Add(account2); } binarySerialization.Serialize(testList); xmlSerialization.Serialize(testList); var des = binarySerialization.Deserialize(); XmlDocument xDoc = new XmlDocument(); xDoc.Load("xml.xml"); XmlElement xRoot = xDoc.DocumentElement; foreach (XmlNode xnode in xRoot) { foreach (XmlNode childnode in xnode.ChildNodes) { foreach (XmlNode node in childnode.ChildNodes) { if (node.Name == "Contact") { foreach (XmlNode last in node.ChildNodes) { if (last.Name == "Name") { Console.WriteLine(" Name of Contact: {0}", last.InnerText); } if (last.Name == "AccountName") { Console.WriteLine(" AccountName of Contact : {0}", last.InnerText); } } } } if (childnode.Name == "Name") { Console.WriteLine("Name: {0}", childnode.InnerText); } if (childnode.Name == "Number") { Console.WriteLine("Number: {0}", childnode.InnerText); } } Console.WriteLine(); } Console.Read(); }
public void AddContact(string name, MobileAccount account) { Contacts.Add(new Contact { Name = name, Account = account }); }
static void Main(string[] args) { History history = new History(); MobileOperator mOperator1 = new MobileOperator("096","Kievstar"); MobileOperator mOperator2 = new MobileOperator("097", "Kievstar"); MobileOperator mOperator3 = new MobileOperator("098", "Kievstar"); mOperator1.StartHistory(history); mOperator2.StartHistory(history); mOperator3.StartHistory(history); MobileAccount account1 = new MobileAccount(mOperator1,40,5,5); MobileAccount account2 = new MobileAccount(mOperator1,40, 5, 5); MobileAccount account3 = new MobileAccount(mOperator1, 15, 5, 5); MobileAccount account4 = new MobileAccount(mOperator2, 10, 5, 5); MobileAccount account5 = new MobileAccount(mOperator3, 40, 5, 5); MobileAccount account6 = new MobileAccount(mOperator3, 40, 5, 5); MobileAccount account7 = new MobileAccount(mOperator3, 40, 5, 5); account4.AddBalance(50); account1.AddContact(account2.Name, account2); account1.AddContact(account3.Name, account3); account2.AddContact(account1.Name, account1); account2.AddContact(account3.Name, account3); account3.AddContact(account1.Name, account1); account3.AddContact(account2.Name, account2); account4.AddContact(account1.Name, account1); account4.AddContact(account2.Name, account2); account4.AddContact(account3.Name, account3); account4.AddContact(account4.Name, account4); account4.AddContact(account5.Name, account5); account4.AddContact(account6.Name, account6); account4.AddContact(account7.Name, account7); Console.WriteLine("Contacts {0}",account1.Name); MobileAccount.contactsBook(account1); Console.WriteLine("Contacts {0}", account2.Name); MobileAccount.contactsBook(account2); Console.WriteLine("Contacts {0}", account3.Name); MobileAccount.contactsBook(account3); Console.WriteLine("Contacts {0}", account4.Name); MobileAccount.contactsBook(account4); Console.WriteLine(""); account1.SendMessage(account2, "Message"); Console.WriteLine(""); account3.MakeCall(account1); Console.WriteLine(""); account2.SendMessage(account1, "Message1"); Console.WriteLine(""); account4.SendMessage(account2, "Message2"); Console.WriteLine(""); account4.SendMessage(account2, "Message2"); Console.WriteLine(""); account4.SendMessage(account2, "Message2"); Console.WriteLine(""); account3.MakeCall(account1); Console.WriteLine(""); account3.MakeCall(account4); Console.WriteLine(""); account3.MakeCall(account2); Console.WriteLine(""); Console.WriteLine("Most frequently called numbers:"); foreach (var account in history.TopCalledNumbers(5)) { Console.WriteLine(account); } Console.WriteLine("Most active subscribers:"); foreach (var account in history.FrequentlyActiveSubscribers(5)) { Console.WriteLine(account); } Console.ReadKey(); }
public Messages(MobileAccount from, MobileAccount forWhom) { From = from; ForWhom = forWhom; }
public MobileEventArgs(MobileOperation operation, MobileAccount forWhom, string message) : this(operation, forWhom) { Message = message; }
public bool IsExistAccount(MobileAccount account) { return(_storage.ContainsKey(account.ToString().GetHashCode())); }
public void RemoveAccount(MobileAccount account) { _storage.Remove(account.ToString().GetHashCode()); }