public static async Task <OmniPySshClient> Connect(string host, string password, ISubject <bool> canConnectSubject) { var client = new OmniPySshClient(host, "pi", password) { CanConnectSubject = canConnectSubject }; canConnectSubject.OnNext(false); try { var connectTask = Task.Run(() => { client.Connect(); }); var which = await Task.WhenAny(connectTask, Task.Delay(15000)); if (which == connectTask) { return(client); } throw new OperationCanceledException(); } catch (Exception) { canConnectSubject.OnNext(true); client.Dispose(); throw; } }
private Task <OmniPySshClient> GetSshClient() { return(OmniPySshClient.Connect(Host, Password, ClientCanConnectSubject)); }