From bb2a4e5a4e0f06a465fcaa5844eefdd8ca874e1d Mon Sep 17 00:00:00 2001 From: "T. Thiery" Date: Sat, 3 Apr 2021 22:54:39 +0200 Subject: [PATCH] Extend Host and Hub with alternative methods - DiscoverAsync with Type instead of generics parameter - Hub Deployment Verificatio with model provided #161 non-breaking --- .../Deployment/HubExtensions.cs | 12 ++++++++++++ src/SharpBrick.PoweredUp/PoweredUpHost.cs | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/SharpBrick.PoweredUp/Deployment/HubExtensions.cs b/src/SharpBrick.PoweredUp/Deployment/HubExtensions.cs index 56e2462..ee41fb6 100644 --- a/src/SharpBrick.PoweredUp/Deployment/HubExtensions.cs +++ b/src/SharpBrick.PoweredUp/Deployment/HubExtensions.cs @@ -24,6 +24,18 @@ public static async Task VerifyDeploymentModelAsync(this Hub self, Action + /// Verifies the deployment model and waits till it reaches zero deployment errors. + /// + /// + /// Builder infrastructure for the deployment model + /// + public static async Task VerifyDeploymentModelAsync(this Hub self, DeploymentModel model) + { + var awaitable = self.VerifyObservable(model) .Do(LogErrors(self)) .Where(x => x.Length == 0) diff --git a/src/SharpBrick.PoweredUp/PoweredUpHost.cs b/src/SharpBrick.PoweredUp/PoweredUpHost.cs index 16a941d..5b681b2 100644 --- a/src/SharpBrick.PoweredUp/PoweredUpHost.cs +++ b/src/SharpBrick.PoweredUp/PoweredUpHost.cs @@ -67,15 +67,23 @@ public void Discover(Func onDiscovery, CancellationToken token = defa }, token); } - public async Task DiscoverAsync(CancellationToken token = default) + public async Task DiscoverAsync(CancellationToken token = default) where THub : class + => await DiscoverInternalAsync(typeof(THub), token) as THub; + + public async Task DiscoverAsync(Type hubType, CancellationToken token = default) + => await DiscoverInternalAsync(hubType, token); + + private async Task DiscoverInternalAsync(Type hubType, CancellationToken token) { - var tcs = new TaskCompletionSource(); + var tcs = new TaskCompletionSource(); Discover(hub => { - if (hub is THub tHub) + var currentHubType = hub.GetType(); + + if (currentHubType == hubType) { - tcs.SetResult(tHub); + tcs.SetResult(hub); } return Task.CompletedTask; @@ -83,8 +91,7 @@ public async Task DiscoverAsync(CancellationToken token = default) var hub = await tcs.Task; - _logger.LogInformation($"End DiscoveryAsync for {typeof(THub).Name}"); - + _logger.LogInformation($"End DiscoveryAsync for {hubType.Name}"); return hub; }