Пример #1
0
        /// <summary>
        /// setup the basic settings before we init the acme context
        /// </summary>
        /// <param name="acmeDirectoryUrl"></param>
        private void PreInitAcmeContext()
        {
            _lastInitDateTime = DateTime.Now;

            _loggingHandler = new LoggingHandler(new HttpClientHandler(), _log);
            var customHttpClient = new System.Net.Http.HttpClient(_loggingHandler);

            if (customHttpClient.DefaultRequestHeaders.Contains("User-Agent"))
            {
                customHttpClient.DefaultRequestHeaders.Remove("User-Agent");
            }
            customHttpClient.DefaultRequestHeaders.Add("User-Agent", _userAgentName);

#if DEBUG
            customHttpClient.Timeout = TimeSpan.FromSeconds(10);
#endif

            _httpClient = new AcmeHttpClient(_serviceUri, customHttpClient);
        }
        /// <summary>
        /// Initialise provider settings, loading current account key if present
        /// </summary>
        public async Task <bool> InitProvider(ILog log = null)
        {
            if (log != null)
            {
                _log = log;
            }

            _lastInitDateTime = DateTime.Now;

            _loggingHandler = new LoggingHandler(new HttpClientHandler(), _log);
            var customHttpClient = new System.Net.Http.HttpClient(_loggingHandler);

            customHttpClient.DefaultRequestHeaders.Add("User-Agent", _userAgentName);

            _httpClient = new AcmeHttpClient(_serviceUri, customHttpClient);

            LoadSettings();

            if (!string.IsNullOrEmpty(_settings.AccountKey))
            {
                if (System.IO.File.Exists(_settingsFolder + "\\c-acc.key"))
                {
                    //remove legacy key info
                    System.IO.File.Delete(_settingsFolder + "\\c-acc.key");
                }
                SetAcmeContextAccountKey(_settings.AccountKey);
            }
            else
            {
                // no account key in settings, check .key (legacy key file)
                if (System.IO.File.Exists(_settingsFolder + "\\c-acc.key"))
                {
                    var pem = System.IO.File.ReadAllText(_settingsFolder + "\\c-acc.key");
                    SetAcmeContextAccountKey(pem);
                }
            }

            _currentOrders = new Dictionary <string, IOrderContext>();

            return(await Task.FromResult(true));
        }