public IEmployable CreateEmployee(string[] data) { string employeeType = data[0]; string name = data[1]; Type type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(t => t.Name == employeeType); if (type == null) { throw new ArgumentException("Invalid employee type!"); } if (!typeof(IEmployable).IsAssignableFrom(type)) { throw new ArgumentException("This is not an employee type!"); } IEmployable employee = (IEmployable)Activator.CreateInstance(type, new object[] { name }); return(employee); }
public void Run() { string input = string.Empty; while ((input = Console.ReadLine()) != "End") { string[] tokens = input.Split(); string cmd = tokens[0]; try { if (cmd.EndsWith("Employee")) { IEmployable employee = this.employeeFactory.CreateEmployee(tokens); this.office.AddEmployee(employee); } else if (cmd == "Job") { string employeeName = tokens[3]; IEmployable employee = this.office.Employees.First(e => e.Name == employeeName); IJob task = this.jobFactory.CreateJob(tokens, employee); this.office.AddTask(task); } else if (cmd == "Pass") { this.office.WeekPass(); } else if (cmd == "Status") { this.office.Status(); } } catch (ArgumentException e) { Console.WriteLine(e.Message); } } }
public IJob CreateJob(string[] data, IEmployable employee) { string taskType = data[0]; string name = data[1]; int requiredHours = int.Parse(data[2]); Type type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(t => t.Name == taskType); if (type == null) { throw new ArgumentException("Invalid task type!"); } if (!typeof(IJob).IsAssignableFrom(type)) { throw new ArgumentException("This is not a task type"); } object[] ctorArgs = new object[] { requiredHours, name, employee }; IJob job = (IJob)Activator.CreateInstance(type, ctorArgs); return(job); }
public Job(string name, int hoursOfWorkRequired, IEmployable employee) { this.name = name; this.HoursOfWorkRequired = hoursOfWorkRequired; this.employee = employee; }
public Job(int requiredHours, string name, IEmployable employee) { this.RemainingHours = requiredHours; this.Name = name; this.Employee = employee; }
public void AddEmployee(IEmployable employee) { this.employees.Add(employee); }