Example #1
0
        private void RebuildHttpClient()
        {
            var timeout = _HttpClient.Timeout;

            _HttpClient?.Dispose();
            _WebRequestHandler?.Dispose();

            BuildHttpClient(timeout);
        }
Example #2
0
        public void ResetHandler()
        {
            if (requestHandler != null)
            {
                requestHandler.Dispose();
            }
            requestHandler = new WebRequestHandler
            {
                AutomaticDecompression = DecompressionMethods.GZip,
                AllowAutoRedirect      = false,
                UseDefaultCredentials  = false,
                UseCookies             = false
            };

            if (httpClient != null)
            {
                httpClient.Dispose();
            }

            httpClient = new HttpClient(requestHandler);
            httpClient.MaxResponseContentBufferSize = AppSettings.MaxResponseContentBufferSize;
            httpClient.Timeout = TimeSpan.FromSeconds(AppSettings.RequestTimeout);
            SetHttpRequestHeader("User-Agent", AppSettings.ClientUserAgentName);
            httpClient.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("Gzip"));
        }
Example #3
0
 private static async Task RunTaskAsync()
 {
     Trace.WriteLine("Start task", "ADBlocker");
     Trace.WriteLine($"Start Time: {DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm:ss.fff")}", "ADBlocker");
     try
     {
         InitializeHttpClient();
         await RunBlockingTaskAsync();
         await RunScheduledTaskAsync();
         await UpdateTaskRuntimeAsync();
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
     finally
     {
         Trace.WriteLine($"End Time: {DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm:ss.fff")}", "ADBlocker");
         Trace.WriteLine("End Task", "ADBlocker");
         Trace.WriteLine("");
         Trace.Close();
         _client?.Dispose();
         _handler?.Dispose();
     }
 }
Example #4
0
        public override void Dispose()
        {
            _requestHandler.Dispose();
            _httpClient.Dispose();
            _client.Dispose();

            base.Dispose();
        }
Example #5
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_client != null)
            {
                _client.Dispose();
                _client = null;
            }

            if (_handler != null)
            {
                _handler.Dispose();
                _handler = null;
            }

            _disposed = true;
        }
Example #6
0
 private static async Task RunTaskAsync()
 {
     _logger.Info("Start Task");
     try
     {
         InitializeHttpClient();
         await RunBlockingTaskAsync();
         await RunScheduledTaskAsync();
         await UpdateTaskRuntimeAsync();
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
     finally
     {
         _logger.Info("End Task");
         _client?.Dispose();
         _handler?.Dispose();
     }
 }
Example #7
0
        private static async Task RunTaskAsync()
        {
            Trace.WriteLine("Start task", "ADBlocker");
            Trace.WriteLine($"Start Time: {DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm:ss.fff")}", "ADBlocker");
            InitializeHttpClient();
            try
            {
                var response = await _client.GetAsync("api/blockedloginrequests/config");

                response.EnsureSuccessStatusCode();
                var responseContent = await response.Content.ReadAsStringAsync();

                var taskConfig = JsonConvert.DeserializeObject <TaskConfiguration>(responseContent);
                if (taskConfig == null)
                {
                    return;
                }
                if (MustRunDailyTask(taskConfig))
                {
                    await RunDailyTaskAsync();
                }
                await RunScheduledTaskAsync();
                await UpdateTaskRuntimeAsync();
            }
            catch (Exception ex)
            {
                Trace.WriteLine("ERROR", "ADBlocker");
                ex.TraceError();
                RaygunClient.Send(ex);
            }
            finally
            {
                Trace.WriteLine($"End Time: {DateTime.UtcNow.ToString("dd/MM/yyyy HH:mm:ss.fff")}", "ADBlocker");
                Trace.WriteLine("End Task", "ADBlocker");
                Trace.WriteLine("");
                Trace.Close();
                _client?.Dispose();
                _handler?.Dispose();
            }
        }
Example #8
0
 public void TestCleanup()
 {
     _client.Dispose();
     _handler.Dispose();
 }
 public void Dispose()
 {
     _serviceImpl.Dispose();
     _handler.Dispose();
 }
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public override void Dispose()
 {
     _handler.Dispose();
     _client.Dispose();
 }