Пример #1
0
        static void Main(string[] args)
        {
            Magazine magazine = new Magazine("Daily Buglees", Frequency.Monthly, new DateTime(2010, 12, 12), 250000);

            magazine.AddArticles(new Article(new Person("Nick", "Back", new DateTime(1990, 10, 20)),
                                             "Corona-Time", 2.2));
            magazine.AddEditors(new Person("Kek", "lol", new DateTime(1988, 8, 7)));
            magazine.Save("file.txt");
            Console.WriteLine("Оригінал: ");
            Console.WriteLine(magazine);
            Magazine newMagazine = magazine.DeepCopy();

            Console.WriteLine("Копія");
            Console.WriteLine(newMagazine.ToString());
            Console.WriteLine("Введіть адресу файлу звідки потрібно зчитати:");
            string path = Console.ReadLine();

            if (!File.Exists(path))
            {
                File.Create(path);
                Console.WriteLine("Файл було створено, будь ласка заповність його.");

                return;
            }

            if (!magazine.Load(path))
            {
                return;
            }

            Console.WriteLine(magazine);
            magazine.AddFromConsole();
            magazine.Save(path);
            Console.WriteLine(magazine);
            Console.WriteLine("Робота статичних методів серіалізації/десеріалізації");
            Magazine.Load(path, magazine);
            magazine.AddFromConsole();
            Magazine.Save(path, magazine);
            Console.WriteLine(magazine);


            Console.WriteLine(newMagazine.ToString());
        }
Пример #2
0
        public static void Main(string[] args)
        {
            string   fileName = "NewFile";
            Magazine m1       = new Magazine();
            Magazine m2       = (Magazine)m1.DeepCopy();

            Console.WriteLine("Original is \n{0} \nCopy is \n {1}", m1, m2);

            Console.WriteLine("Please enter file name:");
            fileName = Console.ReadLine();

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File not exist. Creating new file...");
                File.Create(fileName);
            }
            else
            {
                m1.Load(fileName);
            }

            Console.WriteLine("-------------------------------");
            Console.WriteLine(m1);

            m1.AddFromConsole();
            m1.Save(fileName);

            Console.WriteLine("-------------------------------");
            Console.WriteLine(m1);

            Magazine.Load(fileName, m1);
            m1.AddFromConsole();
            Magazine.Save(fileName, m1);

            Console.WriteLine("-------------------------------");
            Console.WriteLine(m1);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            Magazine magazine1 = new Magazine();
            Magazine magazine2 = (Magazine)magazine1.DeepCopy();

            Console.WriteLine("Original is \n{0} \nCopy is \n {1}", magazine1, magazine2);

            Console.WriteLine("Enter file name:");
            string fileName = Console.ReadLine();

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File not exists. Creating new file...");
                File.Create(fileName);
            }
            else
            {
                magazine1.Load(fileName);
            }

            Console.WriteLine("-------------------------------");
            Console.WriteLine(magazine1);

            magazine1.AddFromConsole();
            magazine1.Save(fileName);

            Console.WriteLine("-------------------------------");
            Console.WriteLine(magazine1);

            Magazine.Load(fileName, magazine1);
            magazine1.AddFromConsole();
            Magazine.Save(fileName, magazine1);

            Console.WriteLine("-------------------------------");
            Console.WriteLine(magazine1);
        }
Пример #4
0
 public static bool Save(string filename, Magazine obj)
 {
     return(obj.Save(filename));
 }