Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("///////// Partial Class in Different files test");
            Virus virus2 = new Virus("Chameleon", "Yura", "Data Base");

            virus2.Info();
            Console.WriteLine();
            Virus virus1 = new Virus("qwe", "Yura", "OS");

            virus1.Info();
            Console.Write("Are objects equal?  ");
            if (virus1.Equals(virus2))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No!");
            }

            Console.WriteLine();
            Console.WriteLine("///////// Enum test");
            Game Dota2 = new Game("Dota 2", "Valve", "MMORPG");

            Dota2.Info();
            Dota2.GetState();
            Console.WriteLine("Включаем программу...");
            Dota2.State = Program.ProgramState.Loading;
            Dota2.GetState();
            Dota2.State = Program.ProgramState.Ready;
            Dota2.GetState();


            Console.WriteLine();
            Console.WriteLine("///////// Struct test");

            Virus structVirus = new Virus();

            Virus.Properties props = new Virus.Properties
            {
                version        = "1.0.2",
                lastModifiedBy = "Kubarko"
            };
            props.Log();


            Console.WriteLine();
            Console.WriteLine("///////// Class-Container test");

            Word   wordProgram   = new Word();
            Sapper sapperProgram = new Sapper();
            Game   gameProgram   = new Game("Dota 2", "Valve", "MMORPG");

            Computer.Add(wordProgram);
            Computer.Add(sapperProgram);
            Computer.Add(gameProgram);
            Computer.Add(new Game("Crusader Kings 3", "Paradox", "Strategy"));
            Console.WriteLine("\n*** Printing all objects before deleting ***");
            Computer.Print();
            Computer.Delete(gameProgram);
            Console.WriteLine("\n*** Printing all objects after deleting ***");
            Computer.Print();



            Console.WriteLine("///////// Class-Controller test");
            Console.WriteLine();
            Game gameController1 = new Game("Dota 2", "Valve", "MMORPG");
            Game gameController2 = new Game("Dota 3", "Ubisoft", "MMORPG");
            Game gameController3 = new Game("Dota 15", "Paradox", "MMORPG");
            Game gameController4 = new Game("Counter-Strike", "Valve", "Shooter");

            Computer.Add(gameController1);
            Computer.Add(gameController2);
            Computer.Add(gameController3);
            Computer.Add(gameController4);


            List <Program> GamesSortedByGenre = Controller.FindGamesByType();

            foreach (Game p in GamesSortedByGenre)
            {
                p.Info();
                Console.WriteLine();
            }

            Console.WriteLine("///////// Class-Controller test 2");
            Console.WriteLine();
            TextProcessor tController1 = new TextProcessor("Texter", "Ivan", "1.0.0");
            TextProcessor tController2 = new TextProcessor("Edit Me", "Helen Frolova", "1.2.0");
            TextProcessor tController3 = new TextProcessor();
            Word          tController4 = new Word("John Worder", "1.0.1");
            Word          tController5 = new Word();

            Computer.Add(tController1);
            Computer.Add(tController2);
            Computer.Add(tController3);
            Computer.Add(tController4);
            Computer.Add(tController5);

            List <Program> TextProcessorsFilteredByVersion = Controller.TextProcessorVersion();

            foreach (TextProcessor t in TextProcessorsFilteredByVersion)
            {
                t.Info();
                Console.WriteLine();
            }
            Console.ReadKey();
            Console.WriteLine("//////////// Sorting Test");
            Console.WriteLine("Before Sorting: ");
            foreach (Program p in Computer.Programs)
            {
                p.Info();
                Console.WriteLine();
            }
            Console.WriteLine();
            Console.WriteLine("After Sorting: ");
            List <Program> SortedPrograms = Controller.SortByName();

            foreach (Program p in SortedPrograms)
            {
                p.Info();
                Console.WriteLine();
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Game  myGameException  = new Game();
            Game  myGameException2 = new Game("Dota 2", "Valve", "MMORPG");
            Game  myGameException3 = new Game("CK3", "Paradox", "Strategy");
            Virus myVirusException = new Virus();

            Computer.Programs.Add(myGameException);


            Console.WriteLine("\n   ####### Имитируем обработку кастомного исключения 1\n");
            try
            {
                Computer.DeleteByIndex(-1);//Вызовется кастомное исключение 1
            }
            catch (MyCustomOutOfRangeException ex)
            {
                Console.WriteLine($"Error Name: {ex.MyExcName()}");
                Console.WriteLine($"Reason: {ex.MyExcCause()}");
                Console.WriteLine($"Time: {ex.MyExcDate()}");
            }

            Console.WriteLine("\n   ####### Имитируем обработку кастомного исключения 2\n");
            try
            {
                Computer.UpdateGame(myVirusException);//Вызовется кастомное исключение 2
                //Computer.UpdateGame(myGameException);//Не вызовется кастомное исключение 2
            }
            catch (MyGameUpdateException ex)
            {
                ex.Info();
            }

            Console.WriteLine("\n   ####### Имитируем обработку исключения 1\n");
            try
            {
                Computer.Programs.Insert(-1, new Word());
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine($"Error: {ex.Message}\nErrored parameter: {ex.ParamName}\nTarget Site: {ex.TargetSite}");
            }



            Console.WriteLine("\n   ####### Имитируем обработку исключения 2\n");
            try
            {
                Console.WriteLine("Сколько раз Word запускался с ошибкой?");
                int numOfErrors = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Сколько всего раз вы запускали Word?");
                int  numOfOpens = Convert.ToInt32(Console.ReadLine());
                Word myWordDivideByZeroException = new Word(numOfOpens, numOfErrors);
                myWordDivideByZeroException.GetInfoAboutOpens();

                Console.WriteLine(myWordDivideByZeroException.PercentOfErroredOpens());//Вызовется если numOfOpens == 0
            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine($"Error: {ex.Message}\nTarget Site: {ex.TargetSite}");
            }
            catch (FormatException ex)
            {
                Console.WriteLine($"Error: {ex.Message}\nTarget Site: {ex.TargetSite}");
            }
            finally
            {
                Console.WriteLine("Блок Finally...");
            }

            Console.ReadKey();
        }