コード例 #1
0
ファイル: Program.cs プロジェクト: kostya-sus/ShkolaSoftheme
        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("");

            Serialization.SerializationCompare();



            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kostya-sus/ShkolaSoftheme
        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();
        }
コード例 #3
0
        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();
        }