protected async Task <DateTime?> AddProductArtifactAsync(string key, string value, Guid productId, ProductBuild productBuild) { var productArtifact = new ProductArtifact { ProductId = productId, ProductBuildId = productBuild.Id, ArtifactType = key, Url = value }; var updatedArtifact = WebRequestWrapper.GetFileInfo(productArtifact); await ProductArtifactRepository.CreateAsync(updatedArtifact); #pragma warning disable RECS0061 // Warns when a culture-aware 'EndsWith' call is used by default. if (key == "version" && updatedArtifact.ContentType == "application/json") #pragma warning restore RECS0061 // Warns when a culture-aware 'EndsWith' call is used by default. { var contents = WebClient.DownloadString(value); var version = JsonConvert.DeserializeObject <Dictionary <string, string> >(contents); if (version.ContainsKey("version")) { productBuild.Version = version["version"]; await ProductBuildRepository.UpdateAsync(productBuild); } } return(updatedArtifact.LastModified); }
/// <summary> /// Remove any artifacts from previous build with this product. /// Cancel any current Hangfire recurring job still in progress /// </summary> /// <param name="product">Product.</param> protected async Task ResetPreviousBuildAsync(Product product) { ClearRecurringJob(product.Id); if (product.WorkflowBuildId != 0) { product.WorkflowBuildId = 0; await ProductRepository.UpdateAsync(product); var artifacts = ProductArtifactRepository.Get() .Where(p => p.ProductId == product.Id) .AsEnumerable(); foreach (var artifact in artifacts) { await ProductArtifactRepository.DeleteAsync(artifact.Id); } } }
public async Task <int> GetVersionCodeAsync(Guid productId) { var product = await ProductRepository.Get() .Where(p => p.Id == productId) .Include(p => p.Project) .ThenInclude(pr => pr.Organization) .FirstOrDefaultAsync(); if ((product == null) || (product.WorkflowJobId == 0) || (product.WorkflowBuildId == 0)) { return(0); } var productBuild = await ProductBuildRepository.Get() .Where(pb => pb.ProductId == product.Id && pb.BuildId == product.WorkflowBuildId) .FirstOrDefaultAsync(); if (productBuild == null) { return(0); } var versionCodeArtifact = await ProductArtifactRepository .Get().Where(a => a.ProductId == product.Id && a.ProductBuildId == productBuild.Id && a.ArtifactType == "version") .FirstOrDefaultAsync(); var versionJson = WebClient.DownloadString(versionCodeArtifact.Url); var version = JsonConvert.DeserializeObject <Dictionary <string, object> >(versionJson); if (version.ContainsKey("versionCode")) { var versionCode = version["versionCode"] as String; return(int.Parse(versionCode)); } return(0); }
protected async Task <DateTime?> AddProductArtifactAsync(string key, string value, Product product, ProductBuild productBuild, bool successful) { var productArtifact = new ProductArtifact { ProductId = product.Id, ProductBuildId = productBuild.Id, ArtifactType = key, Url = value }; var updatedArtifact = WebRequestWrapper.GetFileInfo(productArtifact); var existingArtifact = await ProductArtifactRepository .Get().Where(a => a.ProductId == product.Id && a.ProductBuildId == productBuild.Id && a.ArtifactType == key && a.Url == value) .FirstOrDefaultAsync(); if (existingArtifact != null) { // Not sure why we are getting multiple of these, but we don't want multiple entries. // Should we ignore it or update? Ignore for now. Updating threw exceptions Log.Information($"Updating Artifact: Id={existingArtifact.Id}"); updatedArtifact.Id = existingArtifact.Id; // await ProductArtifactRepository.UpdateAsync(updatedArtifact); } else { var newArtifact = await ProductArtifactRepository.CreateAsync(updatedArtifact); Log.Information($"Created Artifact: Id={newArtifact.Id}"); } // On version.json, update the ProductBuild.Version if (key == "version" && updatedArtifact.ContentType == "application/json") { try { var contents = WebClient.DownloadString(value); var version = JsonConvert.DeserializeObject <Dictionary <string, object> >(contents); if (version.ContainsKey("version")) { productBuild.Version = version["version"] as String; await ProductBuildRepository.UpdateAsync(productBuild); if (successful) { product.VersionBuilt = version["version"] as String; await ProductRepository.UpdateAsync(product); } } } catch (Exception ex) { Log.Error(ex, $"Parsing {key}: {value}"); } } // On play-listing-manifest.json, update the Project.DefaultLanguage if (key == "play-listing-manifest" && updatedArtifact.ContentType == "application/json") { try { var contents = WebClient.DownloadString(value); var manifest = JsonConvert.DeserializeObject <Dictionary <string, object> >(contents); if (manifest.ContainsKey("default-language")) { var languageName = manifest["default-language"] as String; StoreLanguage storeLanguage = await LanguageRepository.Get().Where(lang => lang.Name == languageName).FirstOrDefaultAsync(); if (storeLanguage != null) { product.StoreLanguageId = storeLanguage.Id; await ProductRepository.UpdateAsync(product); } } } catch (Exception ex) { Log.Error(ex, $"Parsing {key}: {value}"); } } return(updatedArtifact.LastModified); }