Esempio n. 1
0
        /// <summary>
        /// Отправить в улей отчет о действии, если работа еще не остановлена.
        /// </summary>
        /// <param name="args">Описание действия.</param>
        protected void SafePerformAction(BeeActionNotification args)
        {
            if (!this.isWorking)
            {
                return;
            }

            this.actionPerformedInternal(this, args);
        }
        /// <summary>
        /// Обработка действий зарегистрированных пчёл.
        /// </summary>
        /// <param name="sender">Пчела-исполнитель действия.</param>
        /// <param name="actionNotification">Оповещение о действии пчелы.</param>
        private void BeeOnActionPerformed(
            object sender,
            BeeActionNotification actionNotification)
        {
            switch (actionNotification.ActionType)
            {
            case BeeActionType.LeftBeehiveToHarvestHoney:
                this.state.DecrementBeesInsideCount();
                break;

            case BeeActionType.EnterGuardPost:
                this.guardPostQueue.Enqueue(actionNotification.SenderBee);
                break;

            case BeeActionType.EnterBeehiveWithHoney:
                this.state.IncrementHoneyCount();
                this.state.IncrementBeesInsideCount();
                this.acceptedList.ResetBeeAcceptedState(actionNotification.SenderBee);
                break;

            case BeeActionType.AcceptBeeToEnter:
                this.acceptedList.AcceptBeeToEnter(actionNotification.RelatedBee);
                break;

            case BeeActionType.ProduceBee:
                this.RegisterBee(actionNotification.RelatedBee);
                actionNotification.RelatedBee.StartWork();
                this.ChangeStateAccordingToNewBee(actionNotification.RelatedBee.Type);
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          $"Неизвестное действие пчелы - {actionNotification.ActionType}",
                          nameof(actionNotification));
            }
        }