Skip to content

Commit

Permalink
Merge branch 'webwatcher' of https://github.com/ElfoCompany/Elfo.Wardein
Browse files Browse the repository at this point in the history
 into webwatcher
  • Loading branch information
mrksoftware committed Mar 20, 2020
2 parents e175ece + fe4e82c commit 8978e8c
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 104 deletions.
10 changes: 10 additions & 0 deletions Elfo.Wardein.Abstractions/WebWatcher/IAmUrlResponseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;

namespace Elfo.Firmenich.Wardein.Abstractions.WebWatcher
{
public interface IAmUrlResponseManager
{
Task<bool> IsHealty(bool assertWithStatusCode, string assertWithRegex);
void RestartPool(string poolName);
}
}
78 changes: 78 additions & 0 deletions Elfo.Wardein.Core/ServiceManager/HttpClientUrlResponseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Elfo.Firmenich.Wardein.Abstractions.WebWatcher;
using Elfo.Wardein.Core.ServiceManager;
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace Elfo.Firmenich.Wardein.Core.ServiceManager
{
public class HttpClientUrlResponseManager : IAmUrlResponseManager
{

public Task<bool> IsHealty(bool assertWithStatusCode, string assertWithRegex)
{
var endPoint = "";
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("http://localhost:55587/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("Keep-Alive"));

var response = client.GetAsync(endPoint);
HttpResponseMessage httpWebResponse = response.Result;

if (!assertWithStatusCode)
{
if (!string.IsNullOrEmpty(assertWithRegex))
{
var isMatch = false;
//check if html content matches the regex
if (isMatch)
{
return Task.FromResult(false);
}
else
{
return Task.FromResult(true);
}
}
else
{
return Task.FromResult(true);
}
}
else
{
if (httpWebResponse.StatusCode != HttpStatusCode.OK)
{
return Task.FromResult(false);
}
else
{
if (!string.IsNullOrEmpty(assertWithRegex))
{
var isMatch = false;
//check if html content matches the regex
if (isMatch)
{
return Task.FromResult(false);
}
else
{
return Task.FromResult(true);
}
}
}

}
return Task.FromResult(false);
}
}

public void RestartPool(string poolName)
=> new IISPoolManager(poolName).Restart();
}
}
101 changes: 0 additions & 101 deletions Elfo.Wardein.Core/ServiceManager/WebWatcherManager.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Elfo.Wardein.Watchers/WebWatcher/WebWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal virtual async Task RunCheck()
{
using (var persistenceService = ServicesContainer.PersistenceService(Const.DB_PATH))
{
IAmServiceManager serviceManager = GetServiceManager();
IAmResponceManager serviceManager = GetServiceManager();
if (serviceManager == null)
continue; // If the service doesn't exist, skip the check

Expand All @@ -168,9 +168,9 @@ internal virtual async Task RunCheck()

#region Local Functions

IAmServiceManager GetServiceManager()
IAmResponceManager GetServiceManager()
{
IAmServiceManager svc = null;
IAmResponceManager svc = null;
try
{
svc = ServicesContainer.ServiceManager(service.ServiceName, service.ServiceManagerType);
Expand Down

0 comments on commit 8978e8c

Please sign in to comment.