// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace MetadataTool { /// /// History of builds within a particular stream that contribute to an issue /// [DataContract] class BuildHealthJobHistory { /// /// The previous build before it started failing. This should be updated as new builds come in. /// [DataMember] public BuildHealthJobStep PrevSuccessfulBuild; /// /// List of failing builds contributing to this issue /// [DataMember] public List FailedBuilds = new List(); /// /// The first successful build after the failures. /// [DataMember] public BuildHealthJobStep NextSuccessfulBuild; /// /// Constructs a new history for a particular stream /// public BuildHealthJobHistory(BuildHealthJobStep PrevSuccessfulBuild) { this.PrevSuccessfulBuild = PrevSuccessfulBuild; } /// /// Adds a failed build to this object /// /// The failed build public void AddFailedBuild(BuildHealthJobStep Build) { int Index = FailedBuilds.BinarySearch(Build); if (Index < 0) { FailedBuilds.Insert(~Index, Build); } } /// /// Determines whether a given build can be added to an issue. This filters cases where an issue does not already have builds for the given stream, or where there is a successful build between the new build and known failures for this issue. /// /// The build to add public bool CanAddFailedBuild(int Change) { // Check that this build is not after a succesful build if(NextSuccessfulBuild != null && Change >= NextSuccessfulBuild.Change) { return false; } // Check that this build is not before the last known successful build if(PrevSuccessfulBuild != null && Change <= PrevSuccessfulBuild.Change) { return false; } // Otherwise allow it return true; } /// /// Enumerates all the builds in this stream /// public IEnumerable Builds { get { if(PrevSuccessfulBuild != null) { yield return PrevSuccessfulBuild; } foreach(BuildHealthJobStep FailedBuild in FailedBuilds) { yield return FailedBuild; } if(NextSuccessfulBuild != null) { yield return NextSuccessfulBuild; } } } } }