Beispiel #1
0
 /// <summary>
 /// Run anything inside a protected envelope that will restart if possible.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="execute"></param>
 /// <returns></returns>
 private T ExecuteInConnection <T>(Func <ISSHConnection, T> execute)
 {
     if (_lockCount > 0)
     {
         return(InternalExecuteInConnection(execute));
     }
     else
     {
         return(Policy
                .Handle <SshConnectionException>(e => e.Message.Contains("Client not connected"))
                .Or <SSHConnectionDroppedException>()
                .Or <NoLinuxShellPromptSeenException>()
                .Or <SshOperationTimeoutException>()
                .Or <TimeoutException>(e => e.Message.Contains("back from host"))
                .WaitAndRetryForever(index => RetryWaitPeriod, (except, cnt) => { Trace.WriteLine($"Failed In Connection to {_connection.MachineName}: {except.Message}");  _connection.Dispose(); _connection = null; })
                .Execute(() =>
         {
             return InternalExecuteInConnection(execute);
         }));
     }
 }