/// <summary> /// Determines whether this instance can shutdown based on the evaluated shutdown model. /// </summary> /// <param name="shutdownModel">The shutdown model.</param> /// <returns> /// <c>true</c> if this instance can shutdown; otherwise, <c>false</c>. /// </returns> bool ISupportCustomShutdown.CanShutdown(ISubordinate shutdownModel) { var container = (SubordinateContainer)shutdownModel; var custom = (ISupportCustomShutdown)_currentPresenter; return(custom.CanShutdown(container.Child)); }
public static void Main() { IKing king = SetupKing(); string input = Console.ReadLine(); while (input != "End") { string[] tokens = input.Split(); string command = tokens[0]; if (command == "Attack") { king.GetAttacked(); } else if (command == "Kill") { string subordinateName = tokens[1]; ISubordinate subordinate = king.Subordinates.First(s => s.Name == subordinateName); subordinate.Die(); } input = Console.ReadLine(); } }
public void AddSubordinate(ISubordinate subordinate) { this.BeingAttacked += subordinate.OnKingBeingAttacked; subordinate.Died += this.SubordinateDied; this.subordinates.Add(subordinate); }
public void Run() { string input = ""; while ((input = Console.ReadLine()) != "End") { string[] tokens = input.Split().ToArray(); string command = tokens[0]; string name = tokens[1]; switch (command) { case "Attack": king.GetAttacked(); break; case "Kill": ISubordinate subordinate = king.Subordinates.First(s => s.Name == name); subordinate.TakeDamage(); break; default: throw new ArgumentException("Invalid Command !"); } } }
public void SubordinateDies(string subordinateName) { ISubordinate subordinate = this.subordinates.First(s => s.Name == subordinateName); this.BeingAttacked -= subordinate.OnKingBeingAttacked; this.subordinates.Remove(subordinate); }
public void AddSubortinate(ISubordinate subordinate) { this.subordinates.Add(subordinate); subordinate.DeathSubordinate += this.OnSubordinateDeath; this.GetAttackedEvent += subordinate.ReactToAttack; }
protected override void ExecuteShutdownModel(ISubordinate model, Action completed) { var question = (Question)model; var dialogPresenter = _serviceLocator.GetInstance<IQuestionPresenter>(); dialogPresenter.Setup(new[] {question}, completed); _shellPresenter.ShowDialog(dialogPresenter); }
/// <summary> /// Executes the shutdown model. /// </summary> /// <param name="subordinate">The subordinate.</param><param name="completed">The completed.</param> protected override void ExecuteShutdownModel(ISubordinate subordinate, Action completed) { var shell = Container.GetInstance <IShellPresenter>(); var dialogPresenter = Container.GetInstance <IQuestionPresenter>(); var question = (Question)subordinate; dialogPresenter.Setup(question, completed); shell.ShowDialog(dialogPresenter); }
protected override void ExecuteShutdownModel(ISubordinate model, System.Action completed) { var shell = Container.GetInstance<IShellPresenter>(); var dialogPresenter = Container.GetInstance<IQuestionPresenter>(); var questions = AssembleQuestions(model); dialogPresenter.Setup(questions, completed); shell.ShowDialog(dialogPresenter); }
/// <summary> /// Inheritors should override this method if they intend to handle advanced shutdown scenarios. /// </summary> /// <param name="model">The model.</param><param name="completed">Called when the shutdown model is finished executing.</param> protected override void ExecuteShutdownModel(ISubordinate model, Action completed) { var dialogPresenter = serviceLocator.GetInstance <IQuestionPresenter>(); Question question = model as Question ?? new Question(this, Answer.No, "Shutdown application?", Answer.Yes, Answer.No); dialogPresenter.Setup(question, completed); ShowDialog(dialogPresenter); }
public void TransferEmployeeToAnotherDirector(ISubordinate subordinate, IDirector newDirector) { if (_subordinates.Remove(subordinate)) { newDirector.AddNewSubordinate(subordinate); } else { throw new SubordinateException(); } }
/// <summary> /// Determines whether this instance can shutdown based on the evaluated shutdown model. /// </summary> /// <param name="shutdownModel">The shutdown model.</param> /// <returns> /// <c>true</c> if this instance can shutdown; otherwise, <c>false</c>. /// </returns> bool ISupportCustomShutdown.CanShutdown(ISubordinate shutdownModel) { var subordinateGroup = (SubordinateGroup)shutdownModel; var presentersToRemove = new List <IPresenter>(); bool result = true; foreach (var presenter in _presenters) { var match = (from child in subordinateGroup where child.Master == presenter select child).FirstOrDefault(); if (match == null) { if (presenter.CanShutdown()) { presentersToRemove.Add(presenter); } else { result = false; } } else { var custom = (ISupportCustomShutdown)presenter; var canShutdown = custom.CanShutdown(match); if (canShutdown) { presentersToRemove.Add(presenter); } else { result = false; } } } FinalizeShutdown(result, presentersToRemove); if (_currentPresenter == null || !_presenters.Contains(_currentPresenter)) { if (_presenters.Count > 0) { _presenters[0].Activate(); ChangeCurrentPresenterCore(_presenters[0]); } } return(result); }
private static ISubordinate SearchSubordinate(IDirector director) { WriteLine("What is the id of your subordinate?"); var subordinateId = ReadLine(); ISubordinate resultSubordinate = null; foreach (var subordinate in director.Subordinates().Where(subordinate => subordinate.Id == subordinateId)) { resultSubordinate = subordinate; } return(resultSubordinate); }
private IEnumerable<Question> AssembleQuestions(ISubordinate model) { var composite = model as ISubordinateComposite; if(composite != null) { foreach(var child in composite.GetChildren()) { foreach(var item in AssembleQuestions(child)) { yield return item; } } } else { yield return (Question)model; } }
public void Run() { string input; while ((input = Console.ReadLine()) != "End") { string[] tokens = input.Split(); string command = tokens[0]; if (command == "Attack") { king.GetAttacket(); } else if (command == "Kill") { string name = tokens[1]; ISubordinate subordinate = king.Subordinates.First(n => n.Name == name); subordinate.Die(); } } }
public void Run() { string line; while ((line = Console.ReadLine()) != "End") { string[] tokens = line.Split(); string command = tokens[0]; if (command == "Attack") { king.ReceiveAttack(); } else { string subordinateName = tokens[1]; ISubordinate subordinate = king.Subordinates.First(s => s.Name == subordinateName); subordinate.Die(); } } }
static void Main(string[] args) { IKing king = KingSetter(); string input = String.Empty; while ((input = Console.ReadLine()) != "End") { string[] tokens = input.Split(); string cmd = tokens[0]; if (cmd == "Attack") { king.BeingAttacked(); } else if (cmd == "Kill") { string name = tokens[1]; ISubordinate unit = king.Army.First(u => u.Name == name); unit.Die(); } } }
public void Run() { string input = ""; while ((input = Console.ReadLine()) != "End") { var tokens = input.Split(); string command = tokens[0]; if (command == "Attack") { king.GetAttacked(); } else if (command == "Kill") { string name = tokens[1]; ISubordinate subordinate = king .Subordinate .First(s => s.Name == name); subordinate.TakeDmg(); } } }
public void Run() { string inputLine; while ((inputLine = Console.ReadLine()) != "End") { string[] commandArgs = inputLine.Split(); string command = commandArgs[0]; switch (command) { case "Attack": this.king.GetAttacked(); break; case "Kill": string subordinateName = commandArgs[1]; ISubordinate subordinate = this.king.GetSubordinate(subordinateName); subordinate.TakeHit(); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="SubordinateContainer"/> class. /// </summary> /// <param name="master">The master.</param> /// <param name="child">The child.</param> public SubordinateContainer(IPresenter master, ISubordinate child) { Master = master; Child = child; }
public ISubordinate GetSubordinate(string subordinateName) { ISubordinate subordinate = this.subordinates.First(s => s.Name == subordinateName); return(subordinate); }
private void ExecuteShutdownModel(ISubordinate subordinate, Action completed) { completed(); }
public void AddSubordinate(ISubordinate subordinate) { this.subordinates.Add(subordinate); this.GetAttackedEvent += subordinate.ReactToAttack; }
/// <summary> /// Inheritors should override this method if they intend to handle advanced shutdown scenarios. /// </summary> /// <param name="model">The model.</param> /// <param name="completed">Called when the shutdown model is finished executing.</param> protected virtual void ExecuteShutdownModel(ISubordinate model, Action completed) { completed(); }
public bool CanShutdown(ISubordinate shutdownModel) { var question = (Question)shutdownModel; if(IsValid) { if(question.Answer == Answer.Cancel) return false; if(question.Answer == Answer.Yes) SaveChanges(); return true; } if(question.Answer == Answer.Yes) return true; return false; }
protected override void ExecuteShutdownModel(ISubordinate model, Action completed) { model.Execute(completed); }
/// <summary> /// Initializes a new instance of the <see cref="SubordinateContainer"/> class. /// </summary> /// <param name="master">The master.</param> /// <param name="child">The child.</param> public SubordinateContainer(IPresenter master, ISubordinate child) { Master = master; Child = child; }
public void AddSubordinated(ISubordinate subordinate) { this.subordinates.Add(subordinate); this.GetAttackEvent += subordinate.ReactToAttack; subordinate.DeathEvent += this.OnSubordinateDeath; }
/// <summary> /// Determines whether this instance can shutdown based on the evaluated shutdown model. /// </summary> /// <param name="shutdownModel">The shutdown model.</param> /// <returns> /// <c>true</c> if this instance can shutdown; otherwise, <c>false</c>. /// </returns> bool ISupportCustomShutdown.CanShutdown(ISubordinate shutdownModel) { var container = (SubordinateContainer)shutdownModel; var custom = (ISupportCustomShutdown)_currentPresenter; return custom.CanShutdown(container.Child); }
public bool CanShutdown(ISubordinate shutdownModel) { var question = (Question)shutdownModel; if(Contact.IsValid) { if(question.Answer == Answer.Cancel) return false; if(question.Answer == Answer.Yes) Execute(Apply()); return true; } if(question.Answer == Answer.Yes) return true; return false; }
private void SubordinateDied(ISubordinate subordinate) { this.BeingAttacked -= subordinate.OnKingBeingAttacked; this.subordinates.Remove(subordinate); }
public void AddNewSubordinate(ISubordinate subordinate) { //if (subordinate.IsThereADirecter()) throw new DirecterException(); _subordinates.Add(subordinate); subordinate.GetNewDirector(this); }
/// <summary> /// Executes the shutdown model. /// </summary> /// <param name="subordinate">The subordinate.</param> /// <param name="completed">The completed.</param> protected virtual void ExecuteShutdownModel(ISubordinate subordinate, Action completed) { completed(); }
/// <summary> /// Determines whether this instance can shutdown based on the evaluated shutdown model. /// </summary> /// <param name="shutdownModel">The shutdown model.</param> /// <returns> /// <c>true</c> if this instance can shutdown; otherwise, <c>false</c>. /// </returns> bool ISupportCustomShutdown.CanShutdown(ISubordinate shutdownModel) { var subordinateGroup = (SubordinateGroup)shutdownModel; var presentersToRemove = new List<IPresenter>(); bool result = true; foreach (var presenter in _presenters) { var match = (from child in subordinateGroup where child.Master == presenter select child).FirstOrDefault(); if (match == null) { if (presenter.CanShutdown()) presentersToRemove.Add(presenter); else result = false; } else { var custom = (ISupportCustomShutdown)presenter; var canShutdown = custom.CanShutdown(match); if (canShutdown) presentersToRemove.Add(presenter); else result = false; } } FinalizeShutdown(result, presentersToRemove); if (_currentPresenter == null || !_presenters.Contains(_currentPresenter)) { if (_presenters.Count > 0) { _presenters[0].Activate(); ChangeCurrentPresenterCore(_presenters[0]); } } return result; }
public void RemoveSubortinate(ISubordinate subordinate) { this.subordinates.Remove(subordinate); this.GetAttackedEvent -= subordinate.ReactToAttack; }
private void ExecuteShutdownModel(ISubordinate subordinate, Action completed) { completed(); }
public void AddUnitToArmy(ISubordinate subordinate) { this.army.Add(subordinate); this.BeingAttackedEvent += subordinate.ReactToAttack; }
public void AddNewSubordinate(ISubordinate subordinate) { _subordinates.Add(subordinate); subordinate.GetNewDirector(this); }
/// <summary> /// Determines whether this instance can shutdown based on the evaluated shutdown model. /// </summary> /// <param name="shutdownModel">The shutdown model.</param> /// <returns> /// <c>true</c> if this instance can shutdown; otherwise, <c>false</c>. /// </returns> public bool CanShutdown(ISubordinate shutdownModel) { var question = (Question)shutdownModel; return(question.Answer == Answer.Yes); }
protected override void ExecuteShutdownModel(ISubordinate model, Action completed) { model.Execute(completed); }