Ejemplo n.º 1
0
        private static void VerifyNpc(INonPlayerCharacter npc)
        {
            VerifyMob(npc);

            string type = "NPC";

            VerifyNpcType(npc, type);
            VerifyNpcLevel(npc, type);

            foreach (IPersonality personality in npc.Personalities)
            {
                IMerchant merchant = personality as IMerchant;
                if (merchant != null)
                {
                    foreach (IItem item in merchant.Sellables)
                    {
                        VerifyItem(item);
                    }
                }

                IPhase phase = personality as IPhase;
                if (phase != null)
                {
                    if (!npc.God)
                    {
                        ThrowConfigException(npc, type, string.Format($"Npc {npc.ShortDescription} needs to have God mode turned on."));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static BinaryFileSchema CheckBfs(BinaryFileSchema schema, IBfsErrorHandler errorHandler)
        {
            handler = errorHandler;

            IPhase[] phases = new IPhase[] {
                new Environments(),
                new TypeLinking(),
                new Hierarchy(),
                new TypeChecking(),
                new DefiniteAssignment()
            };

            gotError = false;

            foreach (IPhase phase in phases)
            {
                phase.Check(schema);

                if (gotError && errorHandler != null)
                {
                    errorHandler.HandleMessage("Schema has errors. Compilation stopped.");
                    return null;
                }
            }

            return schema;
        }
        public void TakeTurn()
        {
            if (currentPhase.HasEnteredPhase == false)
            {
                currentPhase.RaisePhaseComplete += HandleOnPhaseCompleted;
                currentPhase.EnterPhase( );
            }

            currentPhase.ExecutePhase( );

            if (currentPhase.HasCompletedPhase == false)
            {
                return;
            }

            currentPhase = nextPhase;

            if (nextPhase == null)
            {
                OnTurnCompleted( );
                return;
            }

            nextPhase = null;

            currentPhase.RaisePhaseComplete -= HandleOnPhaseCompleted;
        }
        public EliminationPhaseViewVm(IPhase phase)
        {
            if (!(phase.GameStepList.First() is IEliminationStep firsStep))
            {
                throw  new NotSupportedException();
            }
            EliminationStepList = new ObservableCollection <EliminationStepView>();
            var countGameStep = EliminationStep.CountStep(firsStep.Type);

            for (var i = 0; i < countGameStep; i++)
            {
                EliminationStepList.Add(null);
            }
            for (var i = 0; i < phase.GameStepList.Count; i++)
            {
                var temp = phase.GameStepList[i] as EliminationStep;
                EliminationStepList[EliminationStep.IndexStep(temp.Type)] = new EliminationStepView(temp, i == 0, i + 1 == countGameStep);
            }

            phase.NextStepStarted += (sender, step) =>
            {
                var temp = step as EliminationStep;
                var i    = EliminationStep.IndexStep(temp.Type);
                EliminationStepList[i] = new EliminationStepView(temp, i + 1 == countGameStep, i == 0);
            };
        }
Ejemplo n.º 5
0
        protected GameStep(IPhase phase, IList <ITeam> teamList, IMatchSetting currentMatchSetting)
            : this()
        {
            if (teamList == null)
            {
                throw new ArgumentNullException(nameof(teamList));
            }

            FlippingContainer.Instance.ComposeParts(this);

            foreach (var team in teamList)
            {
                var count = teamList.Count(item => item == team);
                if (count != 1)
                {
                    throw new ArgumentException(
                              $"La liste des équipes ne peut pas contenir plus deux fois la même équipe. Equipe:{team.Id}. Count:{count}.");
                }
            }

            Phase               = phase ?? throw new ArgumentNullException(nameof(phase));
            TeamList            = teamList;
            CurrentMatchSetting = currentMatchSetting;
            MatchList           = new List <IMatch>();
        }
Ejemplo n.º 6
0
    //funzione chiamata dall'OnClick del bottone next o registrata nel costruttore all'evento relativo
    public void ChangePhase()
    {
        this._currentPhaseManager.Unregister();

        if (!this._preturnoPerTutti)
        {
            this._phaseIndex          = (this._phaseIndex + 1) % Settings.PhaseManagers.Count();
            this._currentPhaseManager = (IPhase)MainManager.GetManagerInstance(Settings.PhaseManagers.ElementAt(_phaseIndex));
        }

        if (this._phaseIndex == 0 || this._preturnoPerTutti)
        {
            this.ChangeTurn();
        }

        if (this._playerIndex == 0 && this._preturnoPerTutti)
        {
            this._preturnoPerTutti = false;
        }

        if (this.phaseChanged != null)
        {
            this.phaseChanged(this._currentPhaseManager.PhaseName);
        }

        this._currentPhaseManager.Register();
    }
Ejemplo n.º 7
0
        /// <summary>
        ///     Create a new instance (in memory and database) of <see cref="T:Business.EliminationStep" /> with specified param
        /// </summary>
        /// <param name="phase">Phase linked to this new step</param>
        /// <param name="teamList">Team involved in this new step</param>
        /// <param name="matchSetting">Set setting match for new Elimination phase</param>
        /// <param name="firstStep">Set first step for elimination step</param>
        /// <returns>EliminationStep's instance</returns>
        public static IEliminationStep Create(IPhase phase, IList <ITeam> teamList, IMatchSetting matchSetting,
                                              EliminationType firstStep)
        {
            if (phase == null)
            {
                throw new ArgumentNullException(nameof(phase));
            }
            if (teamList == null)
            {
                throw new ArgumentNullException(nameof(teamList));
            }
            if (matchSetting == null)
            {
                throw new ArgumentNullException(nameof(matchSetting));
            }

            var requiredTeam = (ushort)firstStep * 2;

            if (teamList.Count != requiredTeam)
            {
                throw new ArgumentException(
                          $"La première étape de la phase éliminatoire ne correspond pas au nombre équipe fourni. Nombre d'équipe requise:{requiredTeam}. Nombre d'équipe:{teamList.Count}");
            }

            var result = new EliminationStep(phase, teamList, matchSetting)
            {
                Type = firstStep
            };

            return(result);
        }
        private IPhase CreatePhaseInstance(PhaseDescriptor phaseDescriptor, IDictionary <string, string> parameterPool)
        {
            IPhase instance = Activator.CreateInstance(phaseDescriptor.Type) as IPhase;

            foreach (var parameter in phaseDescriptor.Parameters)
            {
                if (parameterPool.ContainsKey(parameter.Name))
                {
                    var value        = parameterPool[parameter.Name];
                    var propertyInfo = parameter.PropertyInfo;

                    if (propertyInfo.PropertyType == typeof(string))
                    {
                        propertyInfo.SetValue(instance, value, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(string[]))
                    {
                        propertyInfo.SetValue(instance, value.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries), null);
                    }
                    else
                    {
                        throw new SawPhaseException($"Unable to inject the value for parameter `{parameter.Name}`of phase `{phaseDescriptor.Name}`");
                    }
                }
                else
                {
                    if (parameter.Required)
                    {
                        throw new SawPhaseException($"Missing required parameter `{parameter.Name}`");
                    }
                }
            }

            return(instance);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public ScreenBattle(IScreenLoader screenLoader, IWindowQueuer windowQueuer, IPhase startPhase, BattleData battleData) : base(screenLoader)
 {
     this.windowQueuer = windowQueuer;
     this.battleData   = battleData;
     currentPhase      = startPhase;
     windowBattle      = new WindowBattle(new Vector2(0, 113), 240, 45);
 }
Ejemplo n.º 10
0
 private void OnStartOfSimulation(object sender, EventArgs e)
 {
     stage         = phenology.Stage;
     uptakeModels  = Apsim.ChildrenRecursively(Parent, typeof(IUptake));
     zones         = Apsim.ChildrenRecursively(this.Parent, typeof(Zone));
     previousPhase = phenology.CurrentPhase;
     DMPlantMax    = 9999;
 }
Ejemplo n.º 11
0
 private void OnStartOfSimulation(object sender, EventArgs e)
 {
     stage         = phenology.Stage;
     uptakeModels  = Apsim.ChildrenRecursively(Parent, typeof(IUptake));
     zones         = Apsim.ChildrenRecursively(this.Parent, typeof(Zone));
     DaysTotal     = new List <double>();
     previousPhase = phenology.CurrentPhase;
 }
 public override void Update(double gameTime)
 {
     currentPhase.Update(gameTime);
     if (currentPhase.IsDone)
     {
         currentPhase = currentPhase.GetNextPhase();
         currentPhase.LoadContent(contentLoader, windowQueuer, battleData);
     }
 }
Ejemplo n.º 13
0
        public IPhase ChangePhase(Situation situation, IPhase phase)
        {
            var oldPhase = _phaseStack.Pop();
            oldPhase.Exit(situation);

            _phaseStack.Push(phase);
            phase.Start(situation);

            return oldPhase;
        }
Ejemplo n.º 14
0
        public EliminationPhaseView(IPhase phase)
        {
            if (phase == null)
            {
                throw new ArgumentNullException(nameof(phase));
            }

            InitializeComponent();
            DataContext = new EliminationPhaseViewVm(phase);
        }
Ejemplo n.º 15
0
        public PhaseExecutionHost(string workflowUniqueName, IPhase hostedPhase)
        {
            _workflowUniqueName = workflowUniqueName;
            _hostedPhase        = hostedPhase;
            _predecessors       = new List <PhaseExecutionHost>();
            _successors         = new List <PhaseExecutionHost>();
            _predecessorIRs     = new Dictionary <PhaseExecutionHost, IIR>();

            ExecutionStarted  = false;
            ExecutionComplete = false;
        }
Ejemplo n.º 16
0
        public PhaseExecutionHost(string workflowUniqueName, IPhase hostedPhase)
        {
            _workflowUniqueName = workflowUniqueName;
            _hostedPhase = hostedPhase;
            _predecessors = new List<PhaseExecutionHost>();
            _successors = new List<PhaseExecutionHost>();
            _predecessorIRs = new Dictionary<PhaseExecutionHost, IIR>();

            ExecutionStarted = false;
            ExecutionComplete = false;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Immediately ends the current phase, as stored in GamePhaseSequencer.
        /// </summary>
        public void EndCurrentTurnPhase(IPhase nextPhase)
        {
            if (nextPhase == null)
            {
                Log.LogMsg("[" + GameID.ToString() + "] couldn't determine which phase should come after [" + nextPhase.PhaseName + "|" + nextPhase.PhaseID.ToString() + "]. Game is likely stuck now.");
                return;
            }

            GamePhaseSequencer.ClearSequence();
            GamePhaseSequencer.AddItem(nextPhase as Phase, GetTurnPhaseDelay(nextPhase as Phase));
            GamePhaseSequencer.ActivateNextItem();
        }
Ejemplo n.º 18
0
    private void PushPhase(string phaseID)
    {
        System.Runtime.Remoting.ObjectHandle handle = System.Activator.CreateInstance(_appProxyConfig.m_assemblyPrimary, phaseID);
        IPhase phase = handle.Unwrap() as IPhase;

        if (LoggingManager.Instance.Filter(LoggingManager.Domain.Phases))
        {
            Debug.Log("(AppManager) Entering phase: " + phaseID + " (" + _phases.Count + ")");
        }
        _phases.Add(phase);
        phase.Setup(this);
    }
Ejemplo n.º 19
0
        public PhaseExecutionHost AddPhase(string WorkflowUniqueName, IPhase Phase)
        {
            if (this._PhaseExecutionHostsByWorkflowUniqueName.ContainsKey(WorkflowUniqueName))
            {
                Message.Trace(Severity.Error, Resources.ErrorAttemptedWorkflowDuplicateUniquePhaseName, WorkflowUniqueName);
                return null;
            }
            PhaseExecutionHost Host = new PhaseExecutionHost(WorkflowUniqueName, Phase);
            this._PhaseExecutionHostsByWorkflowUniqueName.Add(WorkflowUniqueName, Host);
            this._PhaseWorkflow.Add(Host);

            return Host;
        }
Ejemplo n.º 20
0
        public PhaseExecutionHost(string WorkflowUniqueName, IPhase HostedPhase)
        {
            this._WorkflowUniqueName = WorkflowUniqueName;
            this._HostedPhase        = HostedPhase;
            this._Predecessors       = new List <PhaseExecutionHost>();
            this._Successors         = new List <PhaseExecutionHost>();
            this._PredecessorIRs     = new Dictionary <PhaseExecutionHost, IIR>();

            this.ExecutionStarted  = false;
            this.ExecutionComplete = false;

            this.Message = MessageEngine.Create(String.Format("__PHASE EXECUTION HOST: {0}", WorkflowUniqueName));
        }
Ejemplo n.º 21
0
    private void Setup()
    {
        userInterface  = GameObject.Find("UserInterface").GetComponent <IUserInterface>();
        battlePhase    = new BattlePhase();
        itemStorePhase = new ItemStorePhase();
        itemManager    = new ItemManager();
        playerStatus   = new PlayerStatus();

        userInterface.Setup(itemManager);
        battlePhase.Setup(userInterface, itemManager, playerStatus);
        itemStorePhase.Setup(userInterface, itemManager, playerStatus);
        itemManager.Setup(playerStatus);
    }
Ejemplo n.º 22
0
        public PhaseExecutionHost AddPhase(string WorkflowUniqueName, IPhase Phase)
        {
            if (this._PhaseExecutionHostsByWorkflowUniqueName.ContainsKey(WorkflowUniqueName))
            {
                Message.Trace(Severity.Error, Resources.ErrorAttemptedWorkflowDuplicateUniquePhaseName, WorkflowUniqueName);
                return(null);
            }
            PhaseExecutionHost Host = new PhaseExecutionHost(WorkflowUniqueName, Phase);

            this._PhaseExecutionHostsByWorkflowUniqueName.Add(WorkflowUniqueName, Host);
            this._PhaseWorkflow.Add(Host);

            return(Host);
        }
Ejemplo n.º 23
0
        public Turn(IPlayer player)
        {
            this.player = player;

            State.GetInstance.CurrentPlayer = this.player;

            this.Phases.Add(new BeginningPhase(this.player));
            this.Phases.Add(new MainPhase(this.player));
            this.Phases.Add(new CombatPhase(this.player));
            this.Phases.Add(new MainPhase(this.player));
            this.Phases.Add(new EndingPhase(this.player));

            this.currentPhase = this.Phases[0];
        }
Ejemplo n.º 24
0
        public void SupersedePhase(IPhase newPhase)
        {
            Clock.Stop();

            CurrentPhase.SupersededBy = newPhase;
            newPhase.Supersedes       = CurrentPhase;

            CurrentPhase.Pause();

            CurrentPhase = newPhase;
            CurrentPhase.Start();

            Clock.Start(CurrentPhase.Duration);
        }
Ejemplo n.º 25
0
        public PhaseExecutionHost AddPhase(string workflowUniqueName, IPhase phase)
        {
            if (_phaseExecutionHostsByWorkflowUniqueName.ContainsKey(workflowUniqueName))
            {
                MessageEngine.Trace(Severity.Error, Resources.ErrorAttemptedWorkflowDuplicateUniquePhaseName, workflowUniqueName);
                return(null);
            }

            var host = new PhaseExecutionHost(workflowUniqueName, phase);

            _phaseExecutionHostsByWorkflowUniqueName.Add(workflowUniqueName, host);
            _phaseWorkflow.Add(host);

            return(host);
        }
Ejemplo n.º 26
0
        /// <summary>Gets the value.</summary>
        /// <value>The value.</value>
        /// <exception cref="System.Exception">Something is a miss here.  Specifically, the number of values in your StageCode function don't match the number of stage names.  Sort it out numb nuts!!</exception>
        public double Value(int arrayIndex = -1)
        {
            if (StageCodes == null)
            {
                StageCodes = new int[Stages.Length];
                for (int i = 0; i < Stages.Length; i++)
                {
                    IPhase p = Phenology.PhaseStartingWith(Stages[i]);
                    StageCodes[i] = Phenology.IndexFromPhaseName(p.Name) + 1;
                }
            }

            //Fixme.  For some reason this error message won't cast properly??
            if (Codes.Length != StageCodes.Length)
            {
                throw new Exception("Something is a miss here.  Specifically, the number of values in your StageCode function don't match the number of stage names.  Sort it out numb nuts!!");
            }

            for (int i = 0; i < StageCodes.Length; i++)
            {
                if (Phenology.Stage <= StageCodes[i])
                {
                    if (i == 0)
                    {
                        return(Codes[0]);
                    }
                    if (Phenology.Stage == StageCodes[i])
                    {
                        return(Codes[i]);
                    }

                    if (Proportional)
                    {
                        double slope = MathUtilities.Divide(Codes[i] - Codes[i - 1],
                                                            StageCodes[i] - StageCodes[i - 1],
                                                            Codes[i]);
                        return(Codes[i] + slope * (Phenology.Stage - StageCodes[i]));
                    }
                    else
                    {
                        // Simple lookup.
                        return(Codes[i - 1]);
                    }
                }
            }
            return(Codes[StageCodes.Length - 1]);
        }
Ejemplo n.º 27
0
        public void NextPhase()
        {
            var currentPhaseNum = this.Phases.IndexOf(this.currentPhase);

            if (currentPhaseNum == this.Phases.Count - 1)
            {
                this.turnEnded = true;
                if (State.GetInstance.Me().HitPoints < 1 || State.GetInstance.Opponent().HitPoints < 1)
                {
                    //Console.WriteLine("Game is over.");
                    //Console.ReadLine();
                }
            }
            else
            {
                this.currentPhase = this.Phases[currentPhaseNum + 1];
            }
        }
Ejemplo n.º 28
0
        /// <summary>A function that resets phenology to a specified stage</summary>
        public void ReSetToStage(double NewStage)
        {
            if (NewStage == 0)
            {
                throw new Exception(this + "Must pass positive stage to set to");
            }
            int SetPhaseIndex = Convert.ToInt32(Math.Floor(NewStage)) - 1;

            CurrentPhase = phases[SetPhaseIndex];
            IPhase Current           = phases[CurrentPhaseIndex];
            double proportionOfPhase = NewStage - CurrentPhaseIndex - 1;

            Current.FractionComplete = proportionOfPhase;
            if (PhaseRewind != null)
            {
                PhaseRewind.Invoke(this, new EventArgs());
            }
        }
Ejemplo n.º 29
0
    private PhaseManager()
    {
        this._players             = MainManager.GetInstance().Players;
        this._currentPhaseManager = (IPhase)MainManager.GetManagerInstance(Settings.PhaseManagers.ElementAt(_phaseIndex));
        this._currentPlayer       = this._players.ElementAt(_playerIndex);

        if (this.phaseChanged != null)
        {
            this.phaseChanged(this._currentPhaseManager.PhaseName);
        }

        if (this.turnChanged != null)
        {
            this.turnChanged(this._currentPlayer);
        }

        GameObject.Find("MainScene/GUI").GetComponent <GUIController>().nextClicked += ChangePhase;
    }
Ejemplo n.º 30
0
 /// <summary>
 ///     Create a new instance (in memory and database) of <see cref="T:Business.QualificationStep" /> with specified param
 /// </summary>
 /// <param name="phase">Phase linked to this new step</param>
 /// <param name="teamList">Team involved in this new step</param>
 /// <param name="setting">Set setting for new qualification step</param>
 /// <param name="number">Number of qualification group</param>
 /// <returns>QualificationStep's instance</returns>
 public static IGameStep Create(IPhase phase, List <ITeam> teamList, IQualificationStepSetting setting,
                                int number)
 {
     if (setting == null)
     {
         throw new ArgumentNullException(nameof(setting));
     }
     if (teamList.Count < setting.MinTeamRegister)
     {
         throw new ArgumentException(
                   $"Le nombre d'équipe enregistré est insuffisant. Minimum:{setting.MinTeamRegister}. Fourni:{teamList.Count}.", nameof(teamList));
     }
     return(new QualificationStep(phase, teamList, setting.MatchSetting)
     {
         Number = number,
         MatchWithRevenge = setting.MatchWithRevenche,
         NumberOfQualifiedTeam = setting.CountTeamQualified
     });
 }
Ejemplo n.º 31
0
        private async Task TickAsync(UpdateContext context, CancellationToken cancellationToken)
        {
            if (_activePhase == null)
            {
                // Start with the spinning phase
                _activePhase = _spinningPhase;
                await _activePhase.StartAsync();

                _phaseTimer.Reset();
            }

            _phaseTimer.Update(_gameTime);

            if (_phaseTimer.HasElapsed)
            {
                // Stop the active phase
                await _activePhase.StopAsync();

                // Swap phases
                if (ReferenceEquals(_activePhase, _spinningPhase))
                {
                    _activePhase = _shootingPhase;
                }
                else
                {
                    _activePhase = _spinningPhase;
                }

                // Start the next phase
                await _activePhase.StartAsync();

                _phaseTimer.Reset();
            }

            // Tick the active phase
            await _activePhase.TickAsync(_gameTime);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Immediately ends the current phase, as stored in GamePhaseSequencer.
        /// </summary>
        public void EndCurrentTurnPhase(IPhase nextPhase)
        {
            if (nextPhase == null)
            {
                Log.LogMsg("[" + GameID.ToString() + "] couldn't determine which phase should come after [" + nextPhase.PhaseName + "|" + nextPhase.PhaseID.ToString() + "]. Game is likely stuck now.");
                return;
            }

            GamePhaseSequencer.ClearSequence();
            GamePhaseSequencer.AddItem(nextPhase as Phase, GetTurnPhaseDelay(nextPhase as Phase));
            GamePhaseSequencer.ActivateNextItem();
        }
Ejemplo n.º 33
0
 public R01MountGroupPhase(IPhase phase)
 {
     _phase = phase ?? throw new ArgumentNullException();
 }
Ejemplo n.º 34
0
        public PhaseExecutionHost AddPhase(string workflowUniqueName, IPhase phase)
        {
            if (_phaseExecutionHostsByWorkflowUniqueName.ContainsKey(workflowUniqueName))
            {
                MessageEngine.Trace(Severity.Error, Resources.ErrorAttemptedWorkflowDuplicateUniquePhaseName, workflowUniqueName);
                return null;
            }

            var host = new PhaseExecutionHost(workflowUniqueName, phase);
            _phaseExecutionHostsByWorkflowUniqueName.Add(workflowUniqueName, host);
            _phaseWorkflow.Add(host);

            return host;
        }
Ejemplo n.º 35
0
 protected EliminationStep(IPhase phase, IList <ITeam> teamList, IMatchSetting currentMatchSetting)
     : base(phase, teamList, currentMatchSetting)
 {
 }
Ejemplo n.º 36
0
 public void StartPhase(Situation situation, IPhase phase)
 {
     _phaseStack.Push(phase);
     phase.Start(situation);
 }
Ejemplo n.º 37
0
        public PhaseExecutionHost(string WorkflowUniqueName, IPhase HostedPhase)
        {
            this._WorkflowUniqueName = WorkflowUniqueName;
            this._HostedPhase = HostedPhase;
            this._Predecessors = new List<PhaseExecutionHost>();
            this._Successors = new List<PhaseExecutionHost>();
            this._PredecessorIRs = new Dictionary<PhaseExecutionHost, IIR>();

            this.ExecutionStarted = false;
            this.ExecutionComplete = false;

            this.Message = MessageEngine.Create(String.Format("__PHASE EXECUTION HOST: {0}", WorkflowUniqueName));
        }
Ejemplo n.º 38
0
 public PhaseResult(IPhase phase)
 {
     PhaseName = phase.GetType().AssemblyQualifiedName;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Fires after the phase start delay, if any, elapses
 /// </summary>
 public virtual void OnNextTurnPhase(IPhase itm)
 {
     Log.LogMsg("At " + itm.PhaseName + " for [" + CurrentPlayer.CharacterName + "]");
 }
        internal static void WritePhase(IEmitter emitter, IPhase phase, Boolean noBootstrap = false)
        {
            if (!noBootstrap)
            {
                emitter.Emit(new MappingStart());
            }

            if (phase is PhasesTemplateReference)
            {
                var reference = phase as PhasesTemplateReference;
                if (!noBootstrap)
                {
                    emitter.Emit(new Scalar(YamlConstants.Template));
                    emitter.Emit(new Scalar(reference.Name));
                    if (reference.Parameters != null && reference.Parameters.Count > 0)
                    {
                        emitter.Emit(new Scalar(YamlConstants.Parameters));
                        WriteMapping(emitter, reference.Parameters);
                    }
                }

                if (reference.PhaseSelectors != null && reference.PhaseSelectors.Count > 0)
                {
                    emitter.Emit(new Scalar(YamlConstants.Phases));
                    emitter.Emit(new SequenceStart(null, null, true, SequenceStyle.Block));
                    foreach (PhaseSelector selector in reference.PhaseSelectors)
                    {
                        emitter.Emit(new MappingStart());
                        if (!String.IsNullOrEmpty(selector.Name))
                        {
                            emitter.Emit(new Scalar(YamlConstants.Name));
                            emitter.Emit(new Scalar(selector.Name));
                        }

                        if (selector.StepOverrides != null && selector.StepOverrides.Count > 0)
                        {
                            emitter.Emit(new Scalar(YamlConstants.Steps));
                            WriteStepOverrides(emitter, selector.StepOverrides);
                        }

                        emitter.Emit(new MappingEnd());
                    }

                    emitter.Emit(new SequenceEnd());
                }

                WriteStep(emitter, reference as StepsTemplateReference, noBootstrap: true);
            }
            else
            {
                var p = phase as Phase;
                if (!noBootstrap)
                {
                    emitter.Emit(new Scalar(YamlConstants.Name));
                    emitter.Emit(new Scalar(p.Name ?? String.Empty));
                }

                if (p.DependsOn != null && p.DependsOn.Count > 0)
                {
                    emitter.Emit(new Scalar(YamlConstants.DependsOn));
                    if (p.DependsOn.Count == 1)
                    {
                        emitter.Emit(new Scalar(p.DependsOn[0]));
                    }
                    else
                    {
                        WriteSequence(emitter, p.DependsOn);
                    }
                }

                if (!String.IsNullOrEmpty(p.Condition))
                {
                    emitter.Emit(new Scalar(YamlConstants.Condition));
                    emitter.Emit(new Scalar(p.Condition));
                }

                if (!String.IsNullOrEmpty(p.ContinueOnError))
                {
                    emitter.Emit(new Scalar(YamlConstants.ContinueOnError));
                    emitter.Emit(new Scalar(p.ContinueOnError));
                }

                if (!String.IsNullOrEmpty(p.EnableAccessToken))
                {
                    emitter.Emit(new Scalar(YamlConstants.EnableAccessToken));
                    emitter.Emit(new Scalar(p.EnableAccessToken));
                }

                if (p.Target != null)
                {
                    QueueTarget queueTarget = null;
                    DeploymentTarget deploymentTarget = null;
                    ServerTarget serverTarget = null;
                    if ((queueTarget = p.Target as QueueTarget) != null)
                    {
                        emitter.Emit(new Scalar(YamlConstants.Queue));

                        // Test for the simple case "queue: name".
                        if (!String.IsNullOrEmpty(queueTarget.Name) &&
                            String.IsNullOrEmpty(queueTarget.ContinueOnError) &&
                            String.IsNullOrEmpty(queueTarget.Parallel) &&
                            String.IsNullOrEmpty(queueTarget.TimeoutInMinutes) &&
                            (queueTarget.Demands == null || queueTarget.Demands.Count == 0) &&
                            (queueTarget.Matrix == null || queueTarget.Matrix.Count == 0))
                        {
                            emitter.Emit(new Scalar(queueTarget.Name));
                        }
                        else // Otherwise write the mapping.
                        {
                            emitter.Emit(new MappingStart());
                            if (!String.IsNullOrEmpty(queueTarget.Name))
                            {
                                emitter.Emit(new Scalar(YamlConstants.Name));
                                emitter.Emit(new Scalar(queueTarget.Name));
                            }

                            if (!String.IsNullOrEmpty(queueTarget.ContinueOnError))
                            {
                                emitter.Emit(new Scalar(YamlConstants.ContinueOnError));
                                emitter.Emit(new Scalar(queueTarget.ContinueOnError));
                            }

                            if (!String.IsNullOrEmpty(queueTarget.Parallel))
                            {
                                emitter.Emit(new Scalar(YamlConstants.Parallel));
                                emitter.Emit(new Scalar(queueTarget.Parallel));
                            }

                            if (!String.IsNullOrEmpty(queueTarget.TimeoutInMinutes))
                            {
                                emitter.Emit(new Scalar(YamlConstants.TimeoutInMinutes));
                                emitter.Emit(new Scalar(queueTarget.TimeoutInMinutes));
                            }

                            if (queueTarget.Demands != null && queueTarget.Demands.Count > 0)
                            {
                                emitter.Emit(new Scalar(YamlConstants.Demands));
                                if (queueTarget.Demands.Count == 1)
                                {
                                    emitter.Emit(new Scalar(queueTarget.Demands[0]));
                                }
                                else
                                {
                                    WriteSequence(emitter, queueTarget.Demands);
                                }
                            }

                            if (queueTarget.Matrix != null && queueTarget.Matrix.Count > 0)
                            {
                                emitter.Emit(new Scalar(YamlConstants.Matrix));
                                emitter.Emit(new MappingStart());
                                foreach (KeyValuePair<String, IDictionary<String, String>> pair in queueTarget.Matrix.OrderBy(x => x.Key, StringComparer.OrdinalIgnoreCase))
                                {
                                    emitter.Emit(new Scalar(pair.Key));
                                    WriteMapping(emitter, pair.Value);
                                }

                                emitter.Emit(new MappingEnd());
                            }

                            emitter.Emit(new MappingEnd());
                        }
                    }
                    else if ((deploymentTarget = p.Target as DeploymentTarget) != null)
                    {
                        emitter.Emit(new Scalar(YamlConstants.Deployment));

                        // Test for the simple case "deployment: group".
                        if (!String.IsNullOrEmpty(deploymentTarget.Group) &&
                            String.IsNullOrEmpty(deploymentTarget.ContinueOnError) &&
                            String.IsNullOrEmpty(deploymentTarget.HealthOption) &&
                            String.IsNullOrEmpty(deploymentTarget.Percentage) &&
                            String.IsNullOrEmpty(deploymentTarget.TimeoutInMinutes) &&
                            (deploymentTarget.Tags == null || deploymentTarget.Tags.Count == 0))
                        {
                            emitter.Emit(new Scalar(deploymentTarget.Group));
                        }
                        else // Otherwise write the mapping.
                        {
                            emitter.Emit(new MappingStart());
                            if (!String.IsNullOrEmpty(deploymentTarget.Group))
                            {
                                emitter.Emit(new Scalar(YamlConstants.Group));
                                emitter.Emit(new Scalar(deploymentTarget.Group));
                            }

                            if (!String.IsNullOrEmpty(deploymentTarget.ContinueOnError))
                            {
                                emitter.Emit(new Scalar(YamlConstants.ContinueOnError));
                                emitter.Emit(new Scalar(deploymentTarget.ContinueOnError));
                            }

                            if (!String.IsNullOrEmpty(deploymentTarget.HealthOption))
                            {
                                emitter.Emit(new Scalar(YamlConstants.HealthOption));
                                emitter.Emit(new Scalar(deploymentTarget.HealthOption));
                            }

                            if (!String.IsNullOrEmpty(deploymentTarget.Percentage))
                            {
                                emitter.Emit(new Scalar(YamlConstants.Percentage));
                                emitter.Emit(new Scalar(deploymentTarget.Percentage));
                            }

                            if (!String.IsNullOrEmpty(deploymentTarget.TimeoutInMinutes))
                            {
                                emitter.Emit(new Scalar(YamlConstants.TimeoutInMinutes));
                                emitter.Emit(new Scalar(deploymentTarget.TimeoutInMinutes));
                            }

                            if (deploymentTarget.Tags != null && deploymentTarget.Tags.Count > 0)
                            {
                                emitter.Emit(new Scalar(YamlConstants.Tags));
                                if (deploymentTarget.Tags.Count == 1)
                                {
                                    emitter.Emit(new Scalar(deploymentTarget.Tags[0]));
                                }
                                else
                                {
                                    WriteSequence(emitter, deploymentTarget.Tags);
                                }
                            }

                            emitter.Emit(new MappingEnd());
                        }
                    }
                    else if ((serverTarget = p.Target as ServerTarget) != null)
                    {
                        emitter.Emit(new Scalar(YamlConstants.Server));

                        // Test for the simple case "server: true".
                        if (String.IsNullOrEmpty(serverTarget.ContinueOnError) &&
                            String.IsNullOrEmpty(serverTarget.Parallel) &&
                            String.IsNullOrEmpty(serverTarget.TimeoutInMinutes) &&
                            (serverTarget.Matrix == null || serverTarget.Matrix.Count == 0))
                        {
                            emitter.Emit(new Scalar("true"));
                        }
                        else // Otherwise write the mapping.
                        {
                            emitter.Emit(new MappingStart());
                            if (!String.IsNullOrEmpty(serverTarget.ContinueOnError))
                            {
                                emitter.Emit(new Scalar(YamlConstants.ContinueOnError));
                                emitter.Emit(new Scalar(serverTarget.ContinueOnError));
                            }

                            if (!String.IsNullOrEmpty(serverTarget.Parallel))
                            {
                                emitter.Emit(new Scalar(YamlConstants.Parallel));
                                emitter.Emit(new Scalar(serverTarget.Parallel));
                            }

                            if (!String.IsNullOrEmpty(serverTarget.TimeoutInMinutes))
                            {
                                emitter.Emit(new Scalar(YamlConstants.TimeoutInMinutes));
                                emitter.Emit(new Scalar(serverTarget.TimeoutInMinutes));
                            }

                            if (serverTarget.Matrix != null && serverTarget.Matrix.Count > 0)
                            {
                                emitter.Emit(new Scalar(YamlConstants.Matrix));
                                emitter.Emit(new MappingStart());
                                foreach (KeyValuePair<String, IDictionary<String, String>> pair in serverTarget.Matrix.OrderBy(x => x.Key, StringComparer.OrdinalIgnoreCase))
                                {
                                    emitter.Emit(new Scalar(pair.Key));
                                    WriteMapping(emitter, pair.Value);
                                }

                                emitter.Emit(new MappingEnd());
                            }

                            emitter.Emit(new MappingEnd());
                        }
                    }
                    else
                    {
                        throw new NotSupportedException($"Unexpected target type: '{p.Target.GetType().FullName}'");
                    }
                }

                if (p.Variables != null && p.Variables.Count > 0)
                {
                    emitter.Emit(new Scalar(YamlConstants.Variables));
                    WriteVariables(emitter, p.Variables);
                }

                if (p.Steps != null && p.Steps.Count > 0)
                {
                    emitter.Emit(new Scalar(YamlConstants.Steps));
                    WriteSteps(emitter, p.Steps);
                }
            }

            if (!noBootstrap)
            {
                emitter.Emit(new MappingEnd());
            }
        }
Ejemplo n.º 41
0
 private void RunPhase(IPhase phase)
 {
     PhaseResult pr = phase.Run(_context);
     _context.PushResult(pr);
 }