コード例 #1
0
        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);
        }
コード例 #2
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);
        }