-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
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,72 @@ | ||
namespace FunctionalLiving.Api.Infrastructure | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
internal class WriteTo | ||
{ | ||
public string Name { get; set; } | ||
|
||
public Dictionary<string, string> Args { get; set; } | ||
|
||
public WriteTo() | ||
{ | ||
Args = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); | ||
} | ||
} | ||
|
||
internal static class WaitFor | ||
{ | ||
public static async Task SeqToBecomeAvailable( | ||
IConfiguration configuration, | ||
CancellationToken token = default) | ||
{ | ||
var writeTos = configuration | ||
.GetSection("Serilog:WriteTo") | ||
.Get<WriteTo[]>(); | ||
|
||
var seq = writeTos.SingleOrDefault(to => "Seq".Equals(to.Name, StringComparison.InvariantCultureIgnoreCase)); | ||
if (seq == null) | ||
return; | ||
|
||
using (var client = new HttpClient { BaseAddress = new Uri(seq.Args["ServerUrl"]) }) | ||
{ | ||
var exit = false; | ||
while (!exit) | ||
{ | ||
Console.WriteLine("Waiting for Seq to become available..."); | ||
|
||
try | ||
{ | ||
using (var response = await client.GetAsync("/api", token)) | ||
{ | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(1), token); | ||
} | ||
else | ||
{ | ||
exit = true; | ||
} | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
Console.WriteLine( | ||
"Observed an exception while waiting for Seq to become available. Exception: {0}", | ||
exception); | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(1), token); | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine("Seq became available."); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/FunctionalLiving.Knx.Listener/Infrastructure/WaitFor.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,72 @@ | ||
namespace FunctionalLiving.Knx.Listener.Infrastructure | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
internal class WriteTo | ||
{ | ||
public string Name { get; set; } | ||
|
||
public Dictionary<string, string> Args { get; set; } | ||
|
||
public WriteTo() | ||
{ | ||
Args = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); | ||
} | ||
} | ||
|
||
internal static class WaitFor | ||
{ | ||
public static async Task SeqToBecomeAvailable( | ||
IConfiguration configuration, | ||
CancellationToken token = default) | ||
{ | ||
var writeTos = configuration | ||
.GetSection("Serilog:WriteTo") | ||
.Get<WriteTo[]>(); | ||
|
||
var seq = writeTos.SingleOrDefault(to => "Seq".Equals(to.Name, StringComparison.InvariantCultureIgnoreCase)); | ||
if (seq == null) | ||
return; | ||
|
||
using (var client = new HttpClient { BaseAddress = new Uri(seq.Args["ServerUrl"]) }) | ||
{ | ||
var exit = false; | ||
while (!exit) | ||
{ | ||
Console.WriteLine("Waiting for Seq to become available..."); | ||
|
||
try | ||
{ | ||
using (var response = await client.GetAsync("/api", token)) | ||
{ | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(1), token); | ||
} | ||
else | ||
{ | ||
exit = true; | ||
} | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
Console.WriteLine( | ||
"Observed an exception while waiting for Seq to become available. Exception: {0}", | ||
exception); | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(1), token); | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine("Seq became available."); | ||
} | ||
} | ||
} |
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
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,72 @@ | ||
namespace FunctionalLiving.Knx.Sender.Infrastructure | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
internal class WriteTo | ||
{ | ||
public string Name { get; set; } | ||
|
||
public Dictionary<string, string> Args { get; set; } | ||
|
||
public WriteTo() | ||
{ | ||
Args = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); | ||
} | ||
} | ||
|
||
internal static class WaitFor | ||
{ | ||
public static async Task SeqToBecomeAvailable( | ||
IConfiguration configuration, | ||
CancellationToken token = default) | ||
{ | ||
var writeTos = configuration | ||
.GetSection("Serilog:WriteTo") | ||
.Get<WriteTo[]>(); | ||
|
||
var seq = writeTos.SingleOrDefault(to => "Seq".Equals(to.Name, StringComparison.InvariantCultureIgnoreCase)); | ||
if (seq == null) | ||
return; | ||
|
||
using (var client = new HttpClient { BaseAddress = new Uri(seq.Args["ServerUrl"]) }) | ||
{ | ||
var exit = false; | ||
while (!exit) | ||
{ | ||
Console.WriteLine("Waiting for Seq to become available..."); | ||
|
||
try | ||
{ | ||
using (var response = await client.GetAsync("/api", token)) | ||
{ | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(1), token); | ||
} | ||
else | ||
{ | ||
exit = true; | ||
} | ||
} | ||
} | ||
catch (Exception exception) | ||
{ | ||
Console.WriteLine( | ||
"Observed an exception while waiting for Seq to become available. Exception: {0}", | ||
exception); | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(1), token); | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine("Seq became available."); | ||
} | ||
} | ||
} |