Skip to content

Commit

Permalink
fixes in the transcoding logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nakov committed Dec 2, 2020
1 parent 6699a82 commit d665909
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions Jobs/TranscodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ public override void Start()
{
FileName = cmdExecutable,
Arguments = cmdParams,
UseShellExecute = false,
UseShellExecute = true,
CreateNoWindow = false,
RedirectStandardOutput = false,
RedirectStandardError = false,
WindowStyle = ProcessWindowStyle.Minimized
}
};
this.AppendToLog(
this.transcodeProcess.OutputDataReceived += TranscodeProcess_OutputDataReceived;
this.transcodeProcess.ErrorDataReceived += TranscodeProcess_ErrorDataReceived;
this.AppendToLog(
cmdExecutable + " " + cmdParams + Environment.NewLine + Environment.NewLine);
try
{
Expand All @@ -72,7 +75,16 @@ public override void Start()
this.ExecutionState = ExecutionState.Failed;
this.OnErrorOccurred(ex);
}
this.UpdateLogFromProcessOutput();
}

private void TranscodeProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
this.AppendToLog(e.Data);
}

private void TranscodeProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
this.AppendToLog(e.Data);
}

private static string FindExecutableInSystemPath(string exeFileName)
Expand All @@ -95,10 +107,9 @@ public override void UpdateState()
if (this.ExecutionState != ExecutionState.Running)
return;

this.UpdateLogFromProcessOutput();

if (this.transcodeProcess.HasExited)
{
this.UpdateLogFromProcessOutput();
this.PercentsDone = 100;
if (this.transcodeProcess.ExitCode == 0)
this.ExecutionState = ExecutionState.CompletedSuccessfully;
Expand All @@ -112,6 +123,20 @@ public override void UpdateState()
}
}

private void UpdateLogFromProcessOutput()
{
if (this.transcodeProcess.StartInfo.RedirectStandardOutput)
{
string outputData = this.transcodeProcess.StandardOutput.ReadToEnd();
this.AppendToLog(outputData);
}
if (this.transcodeProcess.StartInfo.RedirectStandardError)
{
string errorData = this.transcodeProcess.StandardError.ReadToEnd();
this.AppendToLog(errorData);
}
}

public override void Cancel()
{
this.ExecutionState = ExecutionState.Canceled;
Expand All @@ -125,14 +150,5 @@ public override void Cancel()
$"Failed to stop process #{this.transcodeProcess.Id}: {ex}"));
}
}

private void UpdateLogFromProcessOutput()
{

//this.ExecutionLog +=
// this.transcodeProcess.StandardOutput.ReadToEnd();
//this.ExecutionLog +=
// this.transcodeProcess.StandardError.ReadToEnd();
}
}
}

0 comments on commit d665909

Please sign in to comment.