|
| 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.Threading.Tasks; |
| 6 | +using Microsoft.Extensions.Logging; |
| 7 | +using Microsoft.Extensions.Options; |
| 8 | +using NuGetGallery; |
| 9 | +using NuGetGallery.Services; |
| 10 | + |
| 11 | +namespace NuGet.Services.Validation.Orchestrator |
| 12 | +{ |
| 13 | + public class PackageMessageService : IMessageService<Package> |
| 14 | + { |
| 15 | + private readonly ICoreMessageService _coreMessageService; |
| 16 | + private readonly ILogger<PackageMessageService> _logger; |
| 17 | + private readonly MessageServiceConfiguration _serviceConfiguration; |
| 18 | + |
| 19 | + public PackageMessageService( |
| 20 | + ICoreMessageService coreMessageService, |
| 21 | + IOptionsSnapshot<EmailConfiguration> emailConfigurationAccessor, |
| 22 | + ILogger<PackageMessageService> logger) |
| 23 | + { |
| 24 | + _serviceConfiguration = new MessageServiceConfiguration(emailConfigurationAccessor); |
| 25 | + _coreMessageService = coreMessageService ?? throw new ArgumentNullException(nameof(coreMessageService)); |
| 26 | + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); |
| 27 | + } |
| 28 | + |
| 29 | + public async Task SendPublishedMessageAsync(Package package) |
| 30 | + { |
| 31 | + package = package ?? throw new ArgumentNullException(nameof(package)); |
| 32 | + |
| 33 | + var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion); |
| 34 | + var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(package.PackageRegistration.Id, package.NormalizedVersion); |
| 35 | + |
| 36 | + await _coreMessageService.SendPackageAddedNoticeAsync(package, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.EmailSettingsUrl); |
| 37 | + } |
| 38 | + |
| 39 | + public async Task SendValidationFailedMessageAsync(Package package, PackageValidationSet validationSet) |
| 40 | + { |
| 41 | + package = package ?? throw new ArgumentNullException(nameof(package)); |
| 42 | + validationSet = validationSet ?? throw new ArgumentNullException(nameof(validationSet)); |
| 43 | + |
| 44 | + var galleryPackageUrl = _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion); |
| 45 | + var packageSupportUrl = _serviceConfiguration.PackageSupportUrl(package.PackageRegistration.Id, package.NormalizedVersion); |
| 46 | + |
| 47 | + await _coreMessageService.SendPackageValidationFailedNoticeAsync(package, validationSet, galleryPackageUrl, packageSupportUrl, _serviceConfiguration.EmailConfiguration.AnnouncementsUrl, _serviceConfiguration.EmailConfiguration.TwitterUrl); |
| 48 | + } |
| 49 | + |
| 50 | + public async Task SendValidationTakingTooLongMessageAsync(Package package) |
| 51 | + { |
| 52 | + package = package ?? throw new ArgumentNullException(nameof(package)); |
| 53 | + |
| 54 | + await _coreMessageService.SendValidationTakingTooLongNoticeAsync(package, _serviceConfiguration.GalleryPackageUrl(package.PackageRegistration.Id, package.NormalizedVersion)); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments