Skip to content

Commit

Permalink
handle the case where the ssh command refuses to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
popcorn9499 committed Dec 28, 2020
1 parent 3c78c7b commit ed2730c
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions ProcessAudiobooks-UI/AudiobookProcesser.cs
Expand Up @@ -34,6 +34,7 @@ public AudiobookProcesser(TextBox tbCommand, TextBox tbLocalPath, TextBox tbRemo

public async Task StartProcess(ssh sshClient)
{
bool failed = false; //if any error occurs during this loop proceed to make it to the bottom and the the user it failed
if (this.processing == Processing.Stopped) //if not started start.
{
this.processing = Processing.Started;
Expand Down Expand Up @@ -78,8 +79,31 @@ public async Task StartProcess(ssh sshClient)
string commandDestFolder = tbRemotePath.Text + "/" + book.outputName;

//Run Command
ConsoleWindow.WriteInfo("Copying book to its output directory");
await sshClient.RunCommand("cd \"" + commandDestFolder + "\" && " + command);
ConsoleWindow.WriteInfo("Processing the audiobook");
MessageBoxResult retryConnection = MessageBoxResult.No; //handle retrying to connect if for whatever reason the ssh server refuses to respond.
do //loop over this code until either the user gives up or
{
try
{
//handle running a ssh command with the sshClient
await sshClient.RunCommand("cd \"" + commandDestFolder + "\" && " + command);
}
catch (SSHConnectionFailed)
{
retryConnection = MessageBox.Show("Do you wish to retry connecting to the ssh server?",
"ProcessAudioBook Prompt", MessageBoxButton.YesNo, MessageBoxImage.Error);
if (retryConnection == MessageBoxResult.No) //indicate that this loop has failed and that we should give up processing audiobooks.
{
failed = true;
}
}
} while (retryConnection == MessageBoxResult.Yes);

if (failed)
{ //we must exit this existing foreach loop and proceed to reset some of the program
book.Status = DataObjects.AudiobookProcessingStatus.Ready;
break;
}

//copy files back
string finalOutputPath = this.addVariables(book.outputPath, cmdOutputPath, book);
Expand All @@ -97,7 +121,12 @@ public async Task StartProcess(ssh sshClient)
this.processing = Processing.Stopped;
this.btnStartCreateAudiobooks.IsEnabled = true;
this.btnStopCreateAudiobooks.IsEnabled = false;
MessageBox.Show("Completed the audiobooks!");
if (!failed)
{
MessageBox.Show("Completed the audiobooks!");
} else {
MessageBox.Show("Failure occured. some audiobooks never finished being processed");
}
}

private void CopyDirectory(string file, string trueDestFolder)
Expand Down

0 comments on commit ed2730c

Please sign in to comment.