Esempio n. 1
0
        public bool AddFromConsole()
        {
            int K = 0;

            while (K == 0)
            {
                try
                {
                    Console.WriteLine("Введите необходимые поля используя пробелы как разделители");
                    Console.WriteLine("1.Название статьи");
                    Console.WriteLine("2.Имя");
                    Console.WriteLine("3.Фамилия");
                    Console.WriteLine("4.Дата рождения(день)");
                    Console.WriteLine("5.Дата рождения(месяц)");
                    Console.WriteLine("6.Дата рождения(год)");
                    Console.WriteLine("7.Рейтинг статьи");
                    string argument;
                    argument = Console.ReadLine();
                    List <string> args;
                    args = argument.Split(new char[] { ' ', '.', ',', ':', '\t', '?', '!', '"', '\n', ';', '/', '-', }).ToList();
                    Magazine magazine = new Magazine();
                    magazine.AddArticles(new Article(new Person(args[1], args[2], new DateTime(int.Parse(args[5]), int.Parse(args[4]), int.Parse(args[4]))), args[0], double.Parse(args[6])));
                    K = 1;
                    ListArt.Add(new Article(new Person(args[1], args[2], new DateTime(int.Parse(args[5]), int.Parse(args[4]), int.Parse(args[4]))), args[0], double.Parse(args[6])));
                    return(true);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Невеноезначение даты рождения");
                    return(false);
                }
                catch (ArgumentNullException)
                {
                    Console.WriteLine("Нет входного значения");
                    return(false);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Недопустимый формат входных данных");
                    return(false);
                }
                catch (OverflowException)
                {
                    Console.WriteLine("Выход за пределы памяти ");
                    return(false);
                }
                catch (Exception)
                {
                    Console.WriteLine("Другая ошибка");
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        public bool Replace(Magazine mold, Magazine mnew)
        {
            TKey key1 = myKaySelector(mold);
            TKey key2 = myKaySelector(mnew);

            if (MgDict.ContainsKey(key1) == true)
            {
                MgDict[key1] = MgDict[key2];
                MagazinesChanged(Update.Replace, "collection", key1);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
 public static bool Load(string filename, Magazine obj)
 {
     try
     {
         using (var Fstreem = File.OpenRead(filename))
         {
             BinaryFormatter formatter = new BinaryFormatter();
             obj = (Magazine)formatter.Deserialize(Fstreem);
             return(true);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("AAAAAAAAAAAAAAAAAAAAAAAAA");
         return(false);
     }
 }
Esempio n. 4
0
 public static bool Save(string filename, Magazine obj)
 {
     try
     {
         BinaryFormatter formatter = new BinaryFormatter();
         using (var Fstreem = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None))
         {
             formatter.Serialize(Fstreem, obj);
             return(true);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("RUUUUUUUUUUUUUUUN");
         return(false);
     }
 }
Esempio n. 5
0
        public Magazine DepCopy()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (var Mstreem = new MemoryStream())
            {
                formatter.Serialize(Mstreem, this);
                Mstreem.Position = 0;
                byte[] bytes = Mstreem.GetBuffer();
                Mstreem.Write(bytes, 0, bytes.Length);


                Mstreem.Position = 0;
                Magazine magazine = (Magazine)formatter.Deserialize(Mstreem);
                return(magazine);
            }
        }
Esempio n. 6
0
        public virtual Magazine DeepCopy()
        {
            Magazine obj = new Magazine(this.NameI, this.Pereod, this.Dateend, this.Tir1);

            foreach (var item in this.ListArt)
            {
                obj.listArt.Add(item);
            }


            foreach (var item in this.ListPerson)
            {
                obj.ListPerson.Add(item);
            }

            return(obj);
        }
Esempio n. 7
0
 public bool Save(string filename)
 {
     try
     {
         Magazine        obj       = new Magazine(this.NameI, this.Pereod, this.Dateend, this.Tir1);
         BinaryFormatter formatter = new BinaryFormatter();
         using (var Fstreem = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None))
         {
             formatter.Serialize(Fstreem, obj);
             return(true);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("RUUUUUUUUUUUUUUUN");
         return(false);
     }
 }
Esempio n. 8
0
 public bool Load(string filename)
 {
     try
     {
         using (var Fstreem = File.OpenRead(filename))
         {
             BinaryFormatter formatter = new BinaryFormatter();
             Magazine        magazine  = new Magazine();
             magazine = (Magazine)formatter.Deserialize(Fstreem);
             //this.ListArt.Add(magazine.ListArt[0]);
             return(true);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("AAAAAAAAAAAAAAAAAAAAAAAAA");
         return(false);
     }
 }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            #region
            //Edition Myedition1 = new Edition();
            //Edition Myedition2 = new Edition();

            //if ((object)Myedition1 == (object)Myedition2)
            //    Console.WriteLine("Ссылки равны. " + "\n");
            //else
            //    Console.WriteLine("Ссылки не равны. " + "\n");

            //if (Myedition1 == Myedition2)
            //    Console.WriteLine("Объекты равны. " + "\n");
            //else
            //    Console.WriteLine("Объекты не равны. " + "\n");

            //Console.WriteLine("Хеш-код 1: " + Myedition1.GetHashCode().ToString() + "\n");
            //Console.WriteLine("Хеш-код 2: " + Myedition2.GetHashCode().ToString() + "\n");
            //try
            //{
            //    Edition Myedition3 = new Edition();
            //    Myedition3.Tir1 = -100;
            //}
            //catch (ArgumentException e)
            //{
            //    Console.WriteLine(e.Message + "\n");
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message + "\n");
            //}
            //Magazine myMagazine = new Magazine("jurnal", new Frequency(), new DateTime(1999, 10, 10), 60000);
            //myMagazine.AddArticles(new Article(new Person("igor", "igor", new DateTime()), "titulnik", 45.2));
            //myMagazine.AddEditors(new Person());

            //Console.WriteLine(myMagazine.ToShortString() + "\n" + "\n");

            //Console.WriteLine(myMagazine.MyEdition.ToString() + " \n" + "\n");

            //Magazine myMagazineCopy = myMagazine.DeepCopy();

            //if (myMagazine == myMagazineCopy)
            //    Console.WriteLine("Объекты равны. " + "\n");
            //else
            //    Console.WriteLine("Объекты не равны. " + "\n");

            //Console.WriteLine(myMagazine.ToString() + " \n" + "\n");
            //Console.WriteLine(myMagazineCopy.ToString() + " \n" + "\n");


            //Console.WriteLine("список всех статей с рейтингом  больше 30");
            //foreach (var item in myMagazine.STRating(30.2))
            //{
            //    Console.WriteLine(item.ToString() + "\n");
            //}

            //Console.WriteLine("список всех статей с названием jurnal");
            //foreach (var item in myMagazine.STname("ju"))
            //{
            //    Console.WriteLine(item.ToString() + "\n");
            //}

            //Console.WriteLine("список редакторов журнала не являющиеся авторами");
            //foreach (var item in myMagazine.STArt())
            //{
            //    Console.WriteLine(item.ToString() + "\n");
            //}
            //Console.WriteLine("список редакторов журнала являющиеся авторами");
            //foreach (var item in myMagazine.STperson())
            //{
            //    Console.WriteLine(item.ToString() + "\n");
            //}
            //Console.WriteLine("список редакторов журнала являющиеся авторами и редакторами");

            //myMagazine.AddArticles(new Article(new Person("Your", "Mom", new DateTime(2228, 4, 20)), "Ha ha, benis", 9.11));
            //foreach (Article art in myMagazine)
            //{
            //    Console.WriteLine(art.ToString());
            //}
            #endregion
            #region

            /*Magazine mag = new Magazine();
             * mag.AddArticles(new Article());
             * mag.AddArticles(new Article(new Person(), "jfsjk", 78.6));
             * mag.AddArticles(new Article(new Person("People", "not", new DateTime(1991, 11, 11)), "ooooooop", 78.3));
             * mag.AddArticles(new Article(new Person("alibaba", "i 40 db", new DateTime()), "phahahah", 99.9));
             *
             *
             * mag.SortByTitle();
             * Console.WriteLine(mag.ToString() + "\n");
             * mag.SortBySurname();
             * Console.WriteLine(mag.ToString() + "\n");
             * mag.SortByRating();
             * Console.WriteLine(mag.ToString() + "\n");
             *
             * KeySelector<string> selector = delegate (Magazine input)
             * {
             *  return input.GetHashCode().ToString();
             * };
             *
             * var obj = new MagazineCollection<string>(selector);
             *
             * Magazine mag1 = new Magazine("hfshrgdfb", new Frequency(), new DateTime(), 636);
             * Magazine mag2 = new Magazine("hf", new Frequency(), new DateTime(), 2563);
             * Magazine mag3 = new Magazine("hfsh", new Frequency(), new DateTime(), 600);
             * obj.AddMagazines(mag1, mag2, mag3, mag);
             * Console.WriteLine(obj.ToString() + "\n");
             *
             *
             * Console.WriteLine("ВЫЗОВ МЕТОДОВ MagazineCollection");
             *
             * Console.WriteLine(obj.MaxAverageRat + "\n");
             *
             * foreach (var item in obj.FrequencyGroup(Frequency.Monthly))
             *  Console.WriteLine(item.ToString() + "\n");
             *
             *
             * foreach (var item in obj.GoupEl)
             * {
             *  Console.WriteLine(item.Key);
             *  Console.WriteLine();
             *  foreach (var name in item)
             *      Console.WriteLine(name);
             * }
             * GenerateElement<Edition, Magazine> d = delegate (int j)
             * {
             *  var key = new Edition("tron" + j, new DateTime(), 212);
             *  var value = new Magazine("fwgehdg" + j, new Frequency(), new DateTime(), 212);
             *  return new KeyValuePair<Edition, Magazine>(key, value);
             * };
             * Console.WriteLine("Введите колличество элементов");
             * bool f = false;
             * while (f == false)
             * {
             *  try
             *  {
             *      int c = int.Parse(Console.ReadLine());
             *      f = true;
             *      var testObj = new TestCollections<Edition, Magazine>(c, d);
             *      testObj.SearchInTKeyList();
             *      testObj.SearchInStrList();
             *      testObj.SearcInTKeyDictionary();
             *      testObj.SearcInStrDictionary();
             *      testObj.SearcInTKeyDictionaryByValue();
             *      testObj.SearcInStrDictionaryByValue();
             *  }
             *  catch (Exception ex)
             *  {
             *      Console.WriteLine("Ошибка :" + ex.Message + "\n" + "Допустимы только целочисленные значения");
             *  }
             * }
             * }*/
            #endregion
            #region
            //    KeySelector<string> selector = delegate (Magazine input)
            //    {
            //        return input.GetHashCode().ToString();
            //    };

            //    Magazine m1 = new Magazine("dsvetugv", new Frequency(), new DateTime(), 100);
            //    Magazine m2 = new Magazine("dsvev",new Frequency(),new DateTime(),110);
            //    Magazine m3 = new Magazine("dksdjozfnf", new Frequency(), new DateTime(), 115);
            //    Magazine m4 = new Magazine("kollllloook", new Frequency(), new DateTime(), 120);



            //    var col1 = new MagazineCollection<string>(selector);
            //    col1.CollectionName = "Collection 1";
            //    var col2 = new MagazineCollection<string>(selector);
            //    col2.CollectionName = "Collection 2";

            //    Listener listener = new Listener();

            //    //Устанавливаем слушателей событий в коллекциях
            //    col1.MgChanged += listener.NewListEntry;
            //    col2.MgChanged += listener.NewListEntry;


            //    //Устанавливаем слушателей событий в классе Magazine
            //    m1.PropertyChanged += listener.NewListEntry2;
            //    m2.PropertyChanged += listener.NewListEntry2;
            //    m3.PropertyChanged += listener.NewListEntry2;
            //    m4.PropertyChanged += listener.NewListEntry2;

            //    col1.AddDefaults();
            //    col1.AddMagazines(m1, m2);
            //    col2.AddDefaults();
            //    col2.AddMagazines(m3, m4);


            //    m3.Tir1 = 150;
            //    m4.MyEdition =new Edition();

            //    col1.Replace(m1, m2);
            //    m1.Tir1 = 150;

            //    Console.WriteLine(listener.ToString());

            //}
            #endregion
            Magazine myMagazine = new Magazine("jurnal", new Frequency(), new DateTime(1999, 10, 10), 60000);
            myMagazine.AddArticles(new Article());
            Magazine myMagazine1 = myMagazine.DepCopy();
            Console.WriteLine(myMagazine.ToString());
            Console.WriteLine(myMagazine1.ToString());
            Console.WriteLine("Введите Имя Файла");
            string   Filename1 = Console.ReadLine();
            Magazine magazine  = new Magazine("jurnal", new Frequency(), new DateTime(1999, 10, 10), 60000);
            magazine.AddFromConsole();
            magazine.Save(Filename1);
            bool ff = Magazine.Save(Filename1, magazine);
            Console.WriteLine(magazine.ToString());
            Console.WriteLine("Введите Имя Файла");
            string Filename = Console.ReadLine();
            string dirName  = @"C:\Users\Acer\source\repos\Laba2sharp\Laba2sharp\bin\Debug";
            if (Directory.Exists(dirName))
            {
                string[] files = Directory.GetFiles(dirName);
                foreach (string s in files)
                {
                    if (s.Contains(Filename))
                    {
                        Magazine magazine2 = new Magazine();
                        magazine2.Load(Filename);
                        Console.WriteLine(magazine2.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("директории нет");
            }
        }