using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using GitHub.Core.WebApi;
//using GitHub.Core.WebApi;
using GitHub.Services.WebApi;
namespace GitHub.Build.WebApi
{
///
/// Data representation of a build.
///
[DataContract]
public class Build : ISecuredObject
{
public Build()
{
Reason = BuildReason.Manual;
Priority = QueuePriority.Normal;
}
#region BuildReference members
// these are also present in BuildReference. ideally this class would inherit from that.
// however, moving them to a base class changes the order in which they are serialized to xml
// which breaks compat with subscribers (like RM) who may not be on the same milestone
// TODO: remove these when we figure out how to version service bus events
///
/// The ID of the build.
///
[DataMember(EmitDefaultValue = false)]
[Key]
public Int32 Id
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The build number/name of the build.
///
[DataMember(EmitDefaultValue = false)]
public String BuildNumber
{
get;
set;
}
///
/// The status of the build.
///
[DataMember(EmitDefaultValue = false)]
public BuildStatus? Status
{
get;
set;
}
///
/// The build result.
///
[DataMember(EmitDefaultValue = false)]
public BuildResult? Result
{
get;
set;
}
///
/// The time that the build was queued.
///
[DataMember(EmitDefaultValue = false)]
public DateTime? QueueTime
{
get;
set;
}
///
/// The time that the build was started.
///
[DataMember(EmitDefaultValue = false)]
public DateTime? StartTime
{
get;
set;
}
///
/// The time that the build was completed.
///
[DataMember(EmitDefaultValue = false)]
public DateTime? FinishTime
{
get;
set;
}
///
/// The links to other objects related to this object.
///
public ReferenceLinks Links
{
get
{
if (m_links == null)
{
m_links = new ReferenceLinks();
}
return m_links;
}
}
[DataMember(Name = "_links", EmitDefaultValue = false)]
private ReferenceLinks m_links;
#endregion
///
/// The REST URL of the build.
///
[DataMember(EmitDefaultValue = false)]
public String Url
{
get;
set;
}
///
/// The definition associated with the build.
///
[DataMember(EmitDefaultValue = false)]
public DefinitionReference Definition
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The build number revision.
///
[DataMember(EmitDefaultValue = false)]
public Int32? BuildNumberRevision
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The team project.
///
[DataMember(EmitDefaultValue = false)]
public TeamProjectReference Project
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The URI of the build.
///
[DataMember(EmitDefaultValue = false)]
public Uri Uri
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The source branch.
///
[DataMember(EmitDefaultValue = false)]
public String SourceBranch
{
get;
set;
}
///
/// The source version.
///
[DataMember(EmitDefaultValue = false)]
public String SourceVersion
{
get;
set;
}
///
/// The queue. This is only set if the definition type is Build.
///
[DataMember(EmitDefaultValue = false)]
public AgentPoolQueue Queue
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The agent specification for the build.
///
[DataMember(EmitDefaultValue = false)]
public AgentSpecification AgentSpecification
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The current position of the build in the queue.
///
[DataMember(EmitDefaultValue = false)]
public Int32? QueuePosition
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The build's priority.
///
[DataMember(EmitDefaultValue = false)]
public QueuePriority Priority
{
get;
set;
}
///
/// The reason that the build was created.
///
[DataMember(EmitDefaultValue = false)]
public BuildReason Reason
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The identity on whose behalf the build was queued.
///
[DataMember(EmitDefaultValue = false)]
public IdentityRef RequestedFor
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The identity that queued the build.
///
[DataMember(EmitDefaultValue = false)]
public IdentityRef RequestedBy
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The date the build was last changed.
///
[DataMember(EmitDefaultValue = false)]
public DateTime LastChangedDate
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The identity representing the process or person that last changed the build.
///
[DataMember(EmitDefaultValue = false)]
public IdentityRef LastChangedBy
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The date the build was deleted.
///
[DataMember(EmitDefaultValue = false)]
public DateTime? DeletedDate
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The identity of the process or person that deleted the build.
///
[DataMember(EmitDefaultValue = false)]
public IdentityRef DeletedBy
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The description of how the build was deleted.
///
[DataMember(EmitDefaultValue = false)]
public String DeletedReason
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The parameters for the build.
///
[DataMember(EmitDefaultValue = false)]
public String Parameters
{
get;
set;
}
///
/// A list of demands that represents the agent capabilities required by this build.
///
[DataMember(EmitDefaultValue = false)]
public List Demands
{
get;
set;
}
///
/// The orchestration plan for the build.
///
[DataMember(EmitDefaultValue = false)]
public TaskOrchestrationPlanReference OrchestrationPlan
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The list of Orchestration plans associated with the build.
///
///
/// The build may have plans in addition to the main plan. For example, the cleanup job may have an orchestration plan associated with it.
///
public List Plans
{
get
{
if (m_plans == null)
{
m_plans = new List();
}
return m_plans;
}
set
{
m_plans = value;
}
}
///
/// Information about the build logs.
///
[DataMember(EmitDefaultValue = false)]
public BuildLogReference Logs
{
get;
[EditorBrowsable(EditorBrowsableState.Never)]
set;
}
///
/// The repository.
///
[DataMember(EmitDefaultValue = false)]
public BuildRepository Repository
{
get;
set;
}
///
/// Additional options for queueing the build.
///
[DataMember(EmitDefaultValue = false)]
public QueueOptions QueueOptions
{
get;
set;
}
///
/// Indicates whether the build has been deleted.
///
[DataMember(EmitDefaultValue = false)]
public Boolean Deleted
{
get;
set;
}
///
/// A collection of properties which may be used to extend the storage fields available
/// for a given build.
///
public PropertiesCollection Properties
{
get
{
if (m_properties == null)
{
m_properties = new PropertiesCollection();
}
return m_properties;
}
internal set
{
m_properties = value;
}
}
///
/// A collection of tags associated with the build.
///
public List Tags
{
get
{
if (m_tags == null)
{
m_tags = new List();
}
return m_tags;
}
internal set
{
m_tags = value;
}
}
///
/// The list of validation errors and warnings.
///
public List ValidationResults
{
get
{
if (m_validationResults == null)
{
m_validationResults = new List();
}
return m_validationResults;
}
}
///
/// Indicates whether the build should be skipped by retention policies.
///
[DataMember(EmitDefaultValue = false)]
public Boolean? KeepForever
{
get;
set;
}
///
/// The quality of the xaml build (good, bad, etc.)
///
///
/// This is only used for XAML builds.
///
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public String Quality
{
get;
set;
}
///
/// Indicates whether the build is retained by a release.
///
[DataMember(EmitDefaultValue = false)]
public Boolean? RetainedByRelease
{
get;
set;
}
///
/// The build that triggered this build via a Build completion trigger.
///
[DataMember]
public Build TriggeredByBuild { get; set; }
///
/// Trigger-specific information about the build.
///
public IDictionary TriggerInfo
{
get
{
if (m_triggerInfo == null)
{
m_triggerInfo = new Dictionary(StringComparer.OrdinalIgnoreCase);
}
return m_triggerInfo;
}
internal set
{
if (value != null)
{
m_triggerInfo = new Dictionary(value, StringComparer.OrdinalIgnoreCase);
}
}
}
[DataMember(EmitDefaultValue = false, Name = "Properties")]
private PropertiesCollection m_properties;
[DataMember(EmitDefaultValue = false, Name = "Tags")]
private List m_tags;
[DataMember(EmitDefaultValue = false, Name = "ValidationResults")]
private List m_validationResults;
///
/// Orchestration plans associated with the build (build, cleanup)
///
[DataMember(EmitDefaultValue = false, Name = "Plans")]
private List m_plans;
///
/// Sourceprovider-specific information about what triggered the build
///
/// Added in 3.2-preview.3
[DataMember(EmitDefaultValue = false, Name = "TriggerInfo")]
private Dictionary m_triggerInfo;
#region ISecuredObject implementation
Guid ISecuredObject.NamespaceId => Security.BuildNamespaceId;
Int32 ISecuredObject.RequiredPermissions => BuildPermissions.ViewBuilds;
String ISecuredObject.GetToken()
{
if (!String.IsNullOrEmpty(m_nestingToken))
{
return m_nestingToken;
}
return ((ISecuredObject)this.Definition)?.GetToken();
}
internal void SetNestingSecurityToken(String tokenValue)
{
// Spike: investigate imposing restrictions on the amount of information being returned
// when a nesting security token is being used.
m_nestingToken = tokenValue;
}
private String m_nestingToken = String.Empty;
#endregion
}
}