using System; using System.Collections.Generic; using System.Runtime.Serialization; using GitHub.Services.Common; using GitHub.Services.WebApi; namespace GitHub.Build.WebApi { /// /// A reference to a task definition. /// [DataContract] public class TaskDefinitionReference : BaseSecuredObject { public TaskDefinitionReference() { } public TaskDefinitionReference( ISecuredObject securedObject) : base(securedObject) { } /// /// The ID of the task. /// [DataMember(IsRequired = true)] public Guid Id { get; set; } /// /// The version of the task. /// [DataMember(IsRequired = true)] public String VersionSpec { get; set; } /// /// The type of task (task or task group). /// [DataMember(IsRequired = false)] public String DefinitionType { get; set; } /// /// A clone of this reference. /// /// public TaskDefinitionReference Clone() { return (TaskDefinitionReference)this.MemberwiseClone(); } } /// /// Represents a step in a build phase. /// [DataContract] public class BuildDefinitionStep : BaseSecuredObject { public BuildDefinitionStep() { } internal BuildDefinitionStep( ISecuredObject securedObject) : base(securedObject) { } private BuildDefinitionStep(BuildDefinitionStep toClone) { ArgumentUtility.CheckForNull(toClone, nameof(toClone)); this.Enabled = toClone.Enabled; this.ContinueOnError = toClone.ContinueOnError; this.AlwaysRun = toClone.AlwaysRun; this.DisplayName = toClone.DisplayName; this.TimeoutInMinutes = toClone.TimeoutInMinutes; this.Condition = toClone.Condition; this.RefName = toClone.RefName; // Cloning the reference type variables since memberwiseclone does a shallow copy if (toClone.TaskDefinition != null) { this.TaskDefinition = toClone.TaskDefinition.Clone(); } if (toClone.m_inputs != null) { foreach (var property in toClone.m_inputs) { this.Inputs.Add(property.Key, property.Value); } } if (toClone.m_environment != null) { foreach (var property in toClone.m_environment) { this.Environment.Add(property.Key, property.Value); } } } /// /// The task associated with this step. /// [DataMember(IsRequired = true, Order = 1, Name = "Task")] public TaskDefinitionReference TaskDefinition { get; set; } /// /// The inputs used by this step. /// public IDictionary Inputs { get { if (m_inputs == null) { m_inputs = new Dictionary(StringComparer.OrdinalIgnoreCase); } return m_inputs; } set { m_inputs = new Dictionary(value, StringComparer.OrdinalIgnoreCase); } } /// /// Indicates whether the step is enabled. /// [DataMember(EmitDefaultValue = true)] public Boolean Enabled { get; set; } /// /// Indicates whether the phase should continue even if this step fails. /// [DataMember(EmitDefaultValue = true)] public Boolean ContinueOnError { get; set; } /// /// Indicates whether this step should run even if a previous step fails. /// [DataMember(EmitDefaultValue = true)] public Boolean AlwaysRun { get; set; } /// /// The display name for this step. /// [DataMember(EmitDefaultValue = false)] public String DisplayName { get; set; } /// /// The time, in minutes, that this step is allowed to run. /// [DataMember(EmitDefaultValue = true)] public Int32 TimeoutInMinutes { get; set; } /// /// A condition that determines whether this step should run. /// [DataMember(EmitDefaultValue = false, IsRequired = false)] public String Condition { get; set; } /// /// The reference name for this step. /// [DataMember(EmitDefaultValue = false)] public String RefName { get; set; } /// /// The run-time environment for this step. /// public IDictionary Environment { get { if (m_environment == null) { m_environment = new Dictionary(StringComparer.Ordinal); } return m_environment; } set { m_environment = new Dictionary(value, StringComparer.Ordinal); } } /// /// A clone of this step. /// /// public BuildDefinitionStep Clone() { return new BuildDefinitionStep(this); } [DataMember(Name = "Environment", EmitDefaultValue = false)] private Dictionary m_environment; [DataMember(Name = "Inputs", EmitDefaultValue = false, Order = 2)] private Dictionary m_inputs; } }