Beispiel #1
0
        public bool Replace(int j, Magazine magazine)
        {
            if (_magazines.Count <= j)
            {
                return(false);
            }

            _magazines[j] = magazine;
            MagazineReplaced?.Invoke(this, new MagazineListHandlerEventArgs(CollectionName, "MagazineReplaced", j));
            return(true);
        }
 public bool Replace(int j, Magazine magazine)
 {
     if (Magazines.Count > j)
     {
         Magazines[j] = magazine;
         if (MagazineReplaced != null)
         {
             MagazineReplaced(this, new MagazineListHandlerEventArgs(CollectionName, "Element was replaced by Replace", j));
         }
         return(true);
     }
     return(false);
 }
        public TestCollections(int count)
        {
            Editions        = new List <Edition>();
            Text            = new List <string>();
            EdMagDictionary = new Dictionary <Edition, Magazine>();
            StMagDictionary = new Dictionary <string, Magazine>();

            for (int i = 0; i < count; i++)
            {
                Magazine magazine = GetMegazine(i);
                Edition  edition  = magazine.EditionBase;

                Editions.Add(edition);
                Text.Add(edition.ToString());
                EdMagDictionary.Add(edition, magazine);
                StMagDictionary.Add(edition.ToString(), magazine);
            }
        }
        public static Magazine GetMegazine(int index)
        {
            Magazine magazine = new Magazine(
                new Edition(
                    "editionName " + index,
                    DateTime.Today.AddDays(index),
                    index),
                "magazineName " + index,
                Frequency.Montly,
                DateTime.Today.AddDays(index + 1),
                index,
                new List <Person>
            {
                new Person("personName " + index + 1,
                           "personLast " + index + 1,
                           DateTime.Today.AddDays(index + 2)),
                new Person("personName " + index + 2,
                           "personLast " + index + 2,
                           DateTime.Today.AddDays(index + 3)),
                new Person("personName " + index + 3,
                           "personLast " + index + 3,
                           DateTime.Today.AddDays(index + 4))
            },
                new List <Article>
            {
                new Article(new Person("personName " + index + 1,
                                       "personLast " + index + 1,
                                       DateTime.Today.AddDays(index + 5)),
                            "articleName " + index,
                            index),
                new Article(new Person("personName " + index + 2,
                                       "personLast " + index + 2,
                                       DateTime.Today.AddDays(index + 6)),
                            "articleName " + index + 2,
                            index),
                new Article(new Person("personName " + index + 3,
                                       "personLast " + index + 3,
                                       DateTime.Today.AddDays(index + 7)),
                            "articleName " + index + 3,
                            index)
            });

            return(magazine);
        }
Beispiel #5
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());
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
 protected bool Equals(Magazine other)
 {
     return(string.Equals(_magazineName, other._magazineName) && _timing == other._timing &&
            _magazineDate.Equals(other._magazineDate) && _magazineCirculation == other._magazineCirculation &&
            _articleList.SequenceEqual(other._articleList) && _personsList.SequenceEqual(other._personsList));
 }
Beispiel #9
0
 public static bool Load(string filename, Magazine obj)
 {
     return(obj.Load(filename));
 }
Beispiel #10
0
 public static bool Save(string filename, Magazine obj)
 {
     return(obj.Save(filename));
 }