refactor(AuthClient): Entfernen von ConnectionError und Aktualisierung von tryStartAsync zur Protokollierung
This commit is contained in:
parent
36891b5abb
commit
4e3448b4d4
@ -4,10 +4,6 @@ public interface IAuthClient : IAuthListenHandler, IAuthSenderHandler
|
|||||||
{
|
{
|
||||||
bool IsConnected { get; }
|
bool IsConnected { get; }
|
||||||
|
|
||||||
Exception? ConnectionError { get; }
|
|
||||||
|
|
||||||
bool IsConnectionFailed => ConnectionError is not null;
|
|
||||||
|
|
||||||
Task StartAsync();
|
Task StartAsync();
|
||||||
|
|
||||||
Task<bool> TryStartAsync();
|
Task<bool> TryStartAsync();
|
||||||
|
|||||||
@ -29,38 +29,27 @@ public class AuthClient : IAuthClient, IAsyncDisposable
|
|||||||
|
|
||||||
_connection.On<string, string, string>(nameof(ReceivePublicKeyAsync), ReceivePublicKeyAsync);
|
_connection.On<string, string, string>(nameof(ReceivePublicKeyAsync), ReceivePublicKeyAsync);
|
||||||
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_lazyInitiator = new(async () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _connection.StartAsync();
|
|
||||||
IsConnected = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
ConnectionError = ex;
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsConnected { get; private set; } = false;
|
public bool IsConnected { get; private set; } = false;
|
||||||
|
|
||||||
public Exception? ConnectionError { get; private set; }
|
public async Task StartAsync()
|
||||||
|
{
|
||||||
public async Task StartAsync() => await _lazyInitiator.Value;
|
await _connection.StartAsync();
|
||||||
|
IsConnected = true;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> TryStartAsync()
|
public async Task<bool> TryStartAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return await _lazyInitiator.Value;
|
await StartAsync();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
_logger?.LogError(ex, "{message}", ex.Message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user