namespace TeamCity.Docker.Model { using System; using System.Collections.Generic; using System.Linq; using IoC; internal readonly struct Dockerfile: IComparable { [NotNull] public readonly string Path; [NotNull] public readonly string ImageId; [NotNull] public readonly string Platform; [NotNull] public readonly string Description; [NotNull] public readonly IEnumerable Tags; [NotNull] public readonly IEnumerable Components; [NotNull] public readonly IEnumerable Repositories; [NotNull] public readonly IReadOnlyCollection Comments; [NotNull] public readonly IReadOnlyCollection References; public readonly Weight Weight; [NotNull] public readonly IEnumerable Lines; [NotNull] public readonly IReadOnlyCollection Ignores; [NotNull] public readonly IReadOnlyCollection Requirements; public Dockerfile( [NotNull] string path, [NotNull] string imageId, [NotNull] string platform, [NotNull] string description, [NotNull] IReadOnlyCollection tags, [NotNull] IReadOnlyCollection components, [NotNull] IReadOnlyCollection repositories, [NotNull] IReadOnlyCollection comments, [NotNull] IReadOnlyCollection references, Weight weight, [NotNull] IReadOnlyCollection lines, [NotNull] IReadOnlyCollection ignore, [NotNull] IReadOnlyCollection requirements) { Path = path ?? throw new ArgumentNullException(nameof(path)); ImageId = imageId ?? throw new ArgumentNullException(nameof(imageId)); Platform = platform ?? throw new ArgumentNullException(nameof(platform)); Description = description ?? throw new ArgumentNullException(nameof(description)); Tags = tags ?? throw new ArgumentNullException(nameof(tags)); Components = components ?? throw new ArgumentNullException(nameof(components)); Repositories = repositories ?? throw new ArgumentNullException(nameof(repositories)); Comments = comments ?? throw new ArgumentNullException(nameof(comments)); References = references ?? throw new ArgumentNullException(nameof(references)); Weight = weight; Lines = lines ?? throw new ArgumentNullException(nameof(lines)); Ignores = ignore ?? throw new ArgumentNullException(nameof(ignore)); Requirements = requirements ?? throw new ArgumentNullException(nameof(requirements)); } public int CompareTo(Dockerfile other) => string.Compare(OrderKey(), other.OrderKey(), StringComparison.Ordinal); public override string ToString() => $"{ImageId}:{string.Join(",", Tags)}"; private string OrderKey() { var repoCount = Repositories.Count(i => !string.IsNullOrWhiteSpace(i)); var repoFlag = repoCount > 0 ? "1" : "2"; return $"{repoFlag}-{Platform}-{this}"; } } }