Exemple #1
0
        public static async Task <OmniPySftpClient> Connect(string host, string password, ISubject <bool> canConnectSubject)
        {
            var client = new OmniPySftpClient(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;
            }
        }
Exemple #2
0
 private Task <OmniPySftpClient> GetSftpClient()
 {
     return(OmniPySftpClient.Connect(Host, Password, ClientCanConnectSubject));
 }