Exemple #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            ICertificateBotService certificateBot = _certificateBotFactory
                                                    .Create(CertificateBotServiceType.LinuxDaemon);

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("CertificateBot running at: {time}", DateTimeOffset.Now);

                try
                {
                    MessageResponse messageResponse = await certificateBot
                                                      .SaveCertificatesInServerAndScheduleRenewalAsync();

                    _logger.LogInformation($"{DateTime.Now} {messageResponse.message}");
                    _fileService.WriteTextToFile("log.txt",
                                                 _certificateBotOptions.Value.saveCertificatePath,
                                                 $"{DateTime.Now} {messageResponse.message}");
                }
                catch (Exception ex)
                {
                    _logger.LogError($"{DateTime.Now} {ex.Message}");
                }

                await Task.Delay(4 * 24 * 60 * 60 * 1000, stoppingToken);
            }
        }
Exemple #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            ICertificateBotService certificateBot = _certificateBotFactory
                                                    .Create(CertificateBotServiceType.WindowsService);

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("CertificateBot running at: {time}", DateTimeOffset.Now);

                string message = string.Empty;

                try
                {
                    MessageResponse messageResponse = await certificateBot
                                                      .SaveCertificatesInServerAndScheduleRenewalAsync();

                    message = messageResponse.message;

                    List <BindingInformation> bindings = _certificateBotOptions.Value.bindings;
                    if (bindings?.Count > 0)
                    {
                        MessageResponse messageResponseIIS = certificateBot
                                                             .AddBindingsWithCertificatesToSite(messageResponse.certificateResponses);

                        message = $"{message} {messageResponseIIS.message}";
                    }

                    _logger.LogInformation($"{DateTime.Now} {message}");

                    _fileService.WriteTextToFile("log.txt",
                                                 _certificateBotOptions.Value.saveCertificatePath,
                                                 $"{DateTime.Now} {message}");
                }
                catch (Exception ex)
                {
                    _logger.LogError($"{DateTime.Now} {ex.Message}");
                }

                await Task.Delay(4 * 24 * 60 * 60 * 1000, stoppingToken);
            }
        }