Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
    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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        /// <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);
        }
Esempio n. 11
0
 public void TransferEmployeeToAnotherDirector(ISubordinate subordinate, IDirector newDirector)
 {
     if (_subordinates.Remove(subordinate))
     {
         newDirector.AddNewSubordinate(subordinate);
     }
     else
     {
         throw new SubordinateException();
     }
 }
Esempio n. 12
0
        /// <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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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;
            }
        }
Esempio n. 15
0
    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();
            }
        }
    }
Esempio n. 16
0
        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();
                }
            }
        }
Esempio n. 18
0
        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();
                }
            }
        }
Esempio n. 19
0
        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;
                }
            }
        }
Esempio n. 20
0
 /// <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);
        }
Esempio n. 22
0
 private void ExecuteShutdownModel(ISubordinate subordinate, Action completed)
 {
     completed();
 }
Esempio n. 23
0
 public void AddSubordinate(ISubordinate subordinate)
 {
     this.subordinates.Add(subordinate);
     this.GetAttackedEvent += subordinate.ReactToAttack;
 }
Esempio n. 24
0
 /// <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;
        }
Esempio n. 26
0
 protected override void ExecuteShutdownModel(ISubordinate model, Action completed)
 {
     model.Execute(completed);
 }
Esempio n. 27
0
 /// <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;
 }
Esempio n. 28
0
 public void AddSubordinated(ISubordinate subordinate)
 {
     this.subordinates.Add(subordinate);
     this.GetAttackEvent    += subordinate.ReactToAttack;
     subordinate.DeathEvent += this.OnSubordinateDeath;
 }
Esempio n. 29
0
        /// <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);
        }
Esempio n. 32
0
 public void AddNewSubordinate(ISubordinate subordinate)
 {
     //if (subordinate.IsThereADirecter()) throw new DirecterException();
     _subordinates.Add(subordinate);
     subordinate.GetNewDirector(this);
 }
Esempio n. 33
0
 /// <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();
 }
Esempio n. 34
0
        /// <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;
        }
Esempio n. 35
0
        public void RemoveSubortinate(ISubordinate subordinate)
        {
            this.subordinates.Remove(subordinate);

            this.GetAttackedEvent -= subordinate.ReactToAttack;
        }
Esempio n. 36
0
 private void ExecuteShutdownModel(ISubordinate subordinate, Action completed)
 {
     completed();
 }
Esempio n. 37
0
 public void AddUnitToArmy(ISubordinate subordinate)
 {
     this.army.Add(subordinate);
     this.BeingAttackedEvent += subordinate.ReactToAttack;
 }
Esempio n. 38
0
 public void AddNewSubordinate(ISubordinate subordinate)
 {
     _subordinates.Add(subordinate);
     subordinate.GetNewDirector(this);
 }
Esempio n. 39
0
        /// <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);
        }
Esempio n. 40
0
 protected override void ExecuteShutdownModel(ISubordinate model, Action completed)
 {
     model.Execute(completed);
 }