-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'webwatcher' of https://github.com/ElfoCompany/Elfo.Wardein
- Loading branch information
Showing
4 changed files
with
91 additions
and
104 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
Elfo.Wardein.Abstractions/WebWatcher/IAmUrlResponseManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
78
Elfo.Wardein.Core/ServiceManager/HttpClientUrlResponseManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters