Пример #1
0
        public void Save(ScheduledRenewal renewal, RenewResult result)
        {
            var renewals = Renewals.ToList();

            if (renewal.New)
            {
                renewal.History = new List <RenewResult>();
                renewals.Add(renewal);
                renewal.New = false;
                _log.Information(true, "Adding renewal for {target}", renewal.Binding.Host);
            }
            else if (result.Success)
            {
                _log.Information(true, "Renewal for {host} succeeded", renewal.Binding.Host);
            }
            else
            {
                _log.Error("Renewal for {host} failed, will retry on next run", renewal.Binding.Host);
            }

            // Set next date
            if (result.Success)
            {
                renewal.Date = DateTime.UtcNow.AddDays(RenewalPeriod);
                _log.Information(true, "Next renewal scheduled at {date}", renewal.Date.ToUserString());
            }
            renewal.Updated = true;
            renewal.History.Add(result);
            Renewals = renewals;
        }
        public ScheduledRenewal CreateOrUpdate(Target target, RenewResult result)
        {
            if (!_options.NoTaskScheduler)
            {
                _taskScheduler.EnsureTaskScheduler();
            }

            var renewals = Renewals.ToList();
            var renewal  = Find(target);

            if (renewal == null)
            {
                renewal         = new ScheduledRenewal();
                renewal.History = new List <RenewResult>();
                renewals.Add(renewal);
                _log.Information(true, "Adding renewal for {target}", target);
            }
            else
            {
                _log.Debug("Updating existing renewal");
            }

            renewal.Binding          = target;
            renewal.CentralSsl       = _options.CentralSslStore;
            renewal.Date             = DateTime.UtcNow.AddDays(RenewalPeriod);
            renewal.KeepExisting     = _options.KeepExisting.ToString();
            renewal.Script           = _options.Script;
            renewal.ScriptParameters = _options.ScriptParameters;
            renewal.Warmup           = _options.Warmup;
            renewal.History.Add(result);

            Renewals = renewals;
            _log.Information(true, "Next renewal scheduled at {date}", renewal.Date.ToUserString());
            return(renewal);
        }
Пример #3
0
        public void Save(Renewal renewal, RenewResult result)
        {
            var renewals = Renewals.ToList();

            if (renewal.New)
            {
                renewal.History = new List <RenewResult>();
                renewals.Add(renewal);
                _log.Information(true, "Adding renewal for {target}", renewal.FriendlyName);
            }
            else if (result.Success)
            {
                _log.Information(true, "Renewal for {host} succeeded", renewal.FriendlyName);
            }
            else
            {
                _log.Error("Renewal for {host} failed, will retry on next run", renewal.FriendlyName);
            }

            // Set next date
            renewal.History.Add(result);
            if (result.Success)
            {
                _log.Information(true, "Next renewal scheduled at {date}", renewal.Date.ToUserString());
            }
            renewal.Updated = true;
            Renewals        = renewals;
        }
Пример #4
0
 public OrderContext(ILifetimeScope executionScope, Order order, RunLevel runLevel, RenewResult result)
 {
     ExecutionScope = executionScope;
     Order          = order;
     RunLevel       = runLevel;
     Result         = result;
 }
Пример #5
0
 public ExecutionContext(ILifetimeScope scope, Order order, RunLevel runLevel, RenewResult result)
 {
     Scope    = scope;
     Order    = order;
     RunLevel = runLevel;
     Result   = result;
 }
Пример #6
0
        public void Save(Renewal renewal, RenewResult result)
        {
            var renewals = Renewals.ToList();

            if (renewal.New)
            {
                renewal.History = new List <RenewResult>();
                renewals.Add(renewal);
                _log.Information(true, "Adding renewal for {friendlyName}", renewal.LastFriendlyName);
            }

            // Set next date
            renewal.History.Add(result);
            if (result.Success)
            {
                _log.Information(true, "Next renewal scheduled at {date}", renewal.Date.ToUserString());
            }
            renewal.Updated = true;
            Renewals        = renewals;
        }
Пример #7
0
        public void Save(Renewal renewal, RenewResult result)
        {
            var renewals = Renewals.ToList();

            if (renewal.New)
            {
                renewal.History = new List <RenewResult>();
                renewals.Add(renewal);
                _log.Information(LogType.All, "Adding renewal for {friendlyName}", renewal.LastFriendlyName);
            }

            // Set next date
            renewal.History.Add(result);
            if (result.Success)
            {
                var date = renewal.GetDueDate();
                if (date != null)
                {
                    _log.Information(LogType.All, "Next renewal scheduled at {date}", _inputService.FormatDate(date.Value));
                }
            }
            renewal.Updated = true;
            Renewals        = renewals;
        }
Пример #8
0
        ///<summary>Renews a list of checkout items.</summary>
        ///<param name="listCheckoutIds">The list of checked out items that should be renewed.</param>
        ///<param name="userId">The account id for this account.</param>
        ///<returns>A result per checkout id.</returns>
        public async Task <RenewItemsResult> RenewItems(List <string> listCheckoutIds, long userId)
        {
            if (listCheckoutIds == null || listCheckoutIds.Count == 0)
            {
                throw new ArgumentException(nameof(userId));
            }
            HttpResponseMessage response = await _client.PatchAsync($"{CHECKED_OUT_URL}?locale=en-US", new StringContent(JsonConvert.SerializeObject(new {
                userId,
                checkoutIds = listCheckoutIds,
                renew = true,
            }), Encoding.UTF8, "application/json"));

            if (!response.IsSuccessStatusCode)
            {
                //All failed
                return(new RenewItemsResult {
                    DictionaryResponses = listCheckoutIds.ToDictionary(x => x, x => new RenewResult {
                        WasRenewed = false,
                        ErrorMessage = $"Bad Status Code: {(int)response.StatusCode} - {response.StatusCode}",
                    }),
                });
            }
            try {
                string json = await response.Content.ReadAsStringAsync();

                var result = JsonConvert.DeserializeAnonymousType(json, new {
                    failures = new[] {
                        new {
                            errorResponseDTO = new {
                                classification = "",
                                message        = "",
                            },
                            id         = "",
                            itemId     = "",
                            metadataId = "",
                        }
                    },
                });
                Dictionary <string, RenewResult> dictResults = new Dictionary <string, RenewResult>();
                //First add them all as successful.
                foreach (string id in listCheckoutIds)
                {
                    dictResults[id] = new RenewResult {
                        WasRenewed = true, ErrorMessage = ""
                    };
                }
                if (result?.failures != null)
                {
                    foreach (var failure in result.failures)
                    {
                        if (!dictResults.ContainsKey(failure?.id ?? ""))
                        {
                            continue;
                        }
                        RenewResult renewResult = dictResults[failure.id];
                        renewResult.WasRenewed   = false;
                        renewResult.ErrorMessage = failure?.errorResponseDTO?.message;
                    }
                }
                return(new RenewItemsResult {
                    DictionaryResponses = dictResults,
                });
            }
            catch (Exception e) {
                //All failed
                return(new RenewItemsResult {
                    DictionaryResponses = listCheckoutIds.ToDictionary(x => x, x => new RenewResult {
                        WasRenewed = false,
                        ErrorMessage = $"Bad Status Code: {(int)response.StatusCode} - {response.StatusCode}",
                    })
                });
            }
        }