Exemple #1
0
        static void TestTask()
        {
            Task    task1    = new Task("drova");//create task
            Task    task2    = new Task("fish");
            Manager manager1 = new Manager {
                Name = "Jhon"
            };                                              //manager1.Name="Jhon"; Manager manager1 = new Manager(){ Name = "Jhon" };

            manager1.TaskList.Add(task1);
            manager1.TaskList.Add(task2);
            Worker worker1 = new Worker {
                Name = "Alex"
            };
            Worker worker2 = new Worker {
                Name = "Petr"
            };
            Worker worker3 = new Worker {
                Name = "Nick"
            };

            //Console.WriteLine(task2.Type);
            //Console.WriteLine(task2.Status);
            //TakeTaskDelegate takeTask = TakeTask2;
            ////takeTask = null;
            //takeTask(task1, worker1) ;
            //TakeTask2(task1, worker1);


            worker1.CloseTaskEvent += manager1.CloseTask;//manager1 подписался на событие CloseTaskEvent (cобытие закрытия task ),
            //worker1.CloseTaskEvent - у первого рабочего.
            worker2.CloseTaskEvent += manager1.CloseTask;
            worker3.CloseTaskEvent += manager1.CloseTask;



            manager1.TakeTaskEvent += worker1.TakeTask; // worker1 подписался на событие.
            manager1.TakeTaskEvent += worker2.TakeTask;
            manager1.TakeTaskEvent += worker3.TakeTask;
            //manager1.TakeTaskEvent += TakeTask1; // for example


            manager1.GiveTask(task1, worker1);//метод GiveTask вызывает TakeTaskEvent, который равен
            //группе методов [worker1.TakeTask, worker2.TakeTask,worker3.TakeTask,]

            worker1.CloseTask(task1);

            //worker1.TakeTask(task1, worker2); // this = worker1,this-кто вызывает метод TakeTask, если worker1!=worker2, то task не его,
            //TakeTask(task1, worker2) - передаем параметры worker2 кто должен выполнять работу task1
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var company = new CompanyModel();
            var manager = new Manager()
            {
                Name       = "Maxim",
                LastName   = "Grynyuk",
                MiddleName = "Alexandrovich"
            };

            var foreman = new Foreman()
            {
                Name       = "Alexandr",
                LastName   = "Ivanov",
                MiddleName = "Segeyevich"
            };

            var worker = new Worker()
            {
                Name       = "Alexandr",
                LastName   = "Ivanov",
                MiddleName = "Danilovich"
            };

            company.Employees.Add(manager);
            company.Employees.Add(foreman);
            company.Employees.Add(worker);

            var managers = company.Employees.GetAllEmployees <Manager>();
            var foremans = company.Employees.GetAllEmployees <Foreman>();
            var workers  = company.Employees.GetAllEmployees <Worker>();

            int managersCount = company.Employees.GetEmployeesCount <Manager>();
            int foremansCount = company.Employees.GetEmployeesCount <Foreman>();
            int workersCount  = company.Employees.GetEmployeesCount <Worker>();

            manager.GiveTask(foreman);
            foreman.CheckEmployees();
            worker.Work();
            manager.Work();
            foreman.Work();

            company.Employees += manager;
            company.Employees += foreman;
            company.Employees += worker;

            if (company.Employees.IsExists(manager))
            {
                WriteLine("Exists");
            }
            if (company.Employees.IsExists(worker))
            {
                WriteLine("Exists");
            }
            if (company.Employees.IsExists(foreman))
            {
                WriteLine("Exists");
            }

            managers.PrintEmployees();
            WriteLine($" Managers count : {managersCount}");
            foremans.PrintEmployees();
            WriteLine($" Foremans count : {foremansCount}");
            workers.PrintEmployees();
            WriteLine($" Workers count : {workersCount}");

            if (company.Employees - manager)
            {
                WriteLine("manager deleted");
            }
            if (company.Employees - manager)
            {
                WriteLine("Deleted");
            }
            if (company.Employees - foreman)
            {
                WriteLine("foreman deleted");
            }
            if (company.Employees - worker)
            {
                WriteLine("worker deleted");
            }

            ReadLine();
        }