// Deep-copy constructor not provided by generated code public BuildData(BuildData buildData) { Commit = buildData.Commit; AzureDevOpsBuildId = buildData.AzureDevOpsBuildId; AzureDevOpsBuildDefinitionId = buildData.AzureDevOpsBuildDefinitionId; AzureDevOpsAccount = buildData.AzureDevOpsAccount; AzureDevOpsProject = buildData.AzureDevOpsProject; AzureDevOpsBuildNumber = buildData.AzureDevOpsBuildNumber; AzureDevOpsRepository = buildData.AzureDevOpsRepository; AzureDevOpsBranch = buildData.AzureDevOpsBranch; GitHubRepository = buildData.GitHubRepository; GitHubBranch = buildData.GitHubBranch; Released = buildData.Released; Stable = buildData.Stable; // Assets deep copy if (buildData.Assets != null) { List <AssetData> assetList = new List <AssetData>(); foreach (AssetData asset in buildData.Assets) { List <AssetLocationData> locationsList = new List <AssetLocationData>(); foreach (AssetLocationData location in asset.Locations) { locationsList.Add(new AssetLocationData(location.Type) { Location = location.Location, }); } assetList.Add(new AssetData(asset.NonShipping) { Name = asset.Name, Version = asset.Version, Locations = locationsList.ToImmutableList <AssetLocationData>() }); } Assets = assetList.ToImmutableList <AssetData>(); } //Dependencies deep copy if (buildData.Dependencies != null) { List <BuildRef> dependenciesList = new List <BuildRef>(); foreach (BuildRef dep in buildData.Dependencies) { dependenciesList.Add(new BuildRef(dep.BuildId, dep.IsProduct, dep.TimeToInclusionInMinutes)); } Dependencies = dependenciesList.ToImmutableList <BuildRef>(); } //Incoherencies deep copy if (buildData.Incoherencies != null) { List <BuildIncoherence> incoherenciesList = new List <BuildIncoherence>(); foreach (BuildIncoherence incoherence in buildData.Incoherencies) { incoherenciesList.Add(new BuildIncoherence() { Commit = incoherence.Commit, Name = incoherence.Name, Repository = incoherence.Repository, Version = incoherence.Version }); } Incoherencies = incoherenciesList.ToImmutableList <BuildIncoherence>(); } }
public async Task <Models.Build> CreateAsync( Models.BuildData body, CancellationToken cancellationToken = default ) { if (body == default(Models.BuildData)) { throw new ArgumentNullException(nameof(body)); } if (!body.IsValid) { throw new ArgumentException("The parameter is not valid", nameof(body)); } const string apiVersion = "2019-01-16"; var _baseUri = Client.Options.BaseUri; var _url = new RequestUriBuilder(); _url.Reset(_baseUri); _url.AppendPath( "/api/builds", false); _url.AppendQuery("api-version", Client.Serialize(apiVersion)); using (var _req = Client.Pipeline.CreateRequest()) { _req.Uri = _url; _req.Method = RequestMethod.Post; if (body != default(Models.BuildData)) { _req.Content = RequestContent.Create(Encoding.UTF8.GetBytes(Client.Serialize(body))); _req.Headers.Add("Content-Type", "application/json; charset=utf-8"); } using (var _res = await Client.SendAsync(_req, cancellationToken).ConfigureAwait(false)) { if (_res.Status < 200 || _res.Status >= 300) { await OnCreateFailed(_req, _res).ConfigureAwait(false); } if (_res.ContentStream == null) { await OnCreateFailed(_req, _res).ConfigureAwait(false); } using (var _reader = new StreamReader(_res.ContentStream)) { var _content = await _reader.ReadToEndAsync().ConfigureAwait(false); var _body = Client.Deserialize <Models.Build>(_content); return(_body); } } } }