|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.ComponentModel.Design; |
| 7 | +using System.IO; |
| 8 | +using System.Threading; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using Microsoft.Extensions.Configuration; |
| 11 | +using Microsoft.Extensions.DependencyInjection; |
| 12 | +using Microsoft.Extensions.Logging; |
| 13 | +using Microsoft.Extensions.Options; |
| 14 | +using Autofac; |
| 15 | +using Azure.Storage.Blobs; |
| 16 | +using NuGet.Jobs; |
| 17 | +using NuGet.Jobs.Validation; |
| 18 | +using NuGet.Services.Entities; |
| 19 | +using NuGet.Services.Storage; |
| 20 | +using NuGetGallery; |
| 21 | + |
| 22 | +namespace UpdateBlobProperties |
| 23 | +{ |
| 24 | + public class Job : ValidationJobBase |
| 25 | + { |
| 26 | + private const string UpdateBlobPropertiesConfigurationSectionName = "UpdateBlobProperties"; |
| 27 | + |
| 28 | + public override void Init(IServiceContainer serviceContainer, IDictionary<string, string> jobArgsDictionary) |
| 29 | + { |
| 30 | + base.Init(serviceContainer, jobArgsDictionary); |
| 31 | + } |
| 32 | + |
| 33 | + public override async Task Run() |
| 34 | + { |
| 35 | + var processor = _serviceProvider.GetRequiredService<IProcessor>(); |
| 36 | + |
| 37 | + await processor.ExecuteAsync(CancellationToken.None); |
| 38 | + } |
| 39 | + |
| 40 | + protected override void ConfigureAutofacServices(ContainerBuilder containerBuilder, IConfigurationRoot configurationRoot) |
| 41 | + { |
| 42 | + } |
| 43 | + |
| 44 | + protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) |
| 45 | + { |
| 46 | + // Update blob properties of package version index in FlatContainer |
| 47 | + services.AddTransient<BlobInfo, BlobInfoOfPackageVersionIndexInFlatContainer>(); |
| 48 | + |
| 49 | + services.Configure<UpdateBlobPropertiesConfiguration>(configurationRoot.GetSection(UpdateBlobPropertiesConfigurationSectionName)); |
| 50 | + services.AddTransient<IProcessor, Processor>(); |
| 51 | + services.AddTransient<ICollector, Collector>(); |
| 52 | + services.AddTransient<IEntityRepository<Package>, EntityRepository<Package>>(); |
| 53 | + |
| 54 | + services.AddTransient(s => |
| 55 | + { |
| 56 | + var address = new Uri("http://localhost"); |
| 57 | + var fileStorageFactory = new FileStorageFactory( |
| 58 | + address, |
| 59 | + Directory.GetCurrentDirectory(), |
| 60 | + s.GetRequiredService<ILogger<FileStorage>>()); |
| 61 | + |
| 62 | + return new Cursor(new Uri(address, "cursor.json"), fileStorageFactory.Create(), defaultValue: 0); |
| 63 | + }); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments