Пример #1
0
 protected virtual Action <Exception> GetErrorHandler(EncoderItem encoderItem)
 {
     return(e =>
     {
         Logger.Write(this, LogLevel.Warn, "Encoder background thread for file \"{0}\" error: {1}", encoderItem.InputFileName, e.Message);
         encoderItem.AddError(e.Message);
     });
 }
Пример #2
0
        protected virtual Process CreateProcess(EncoderItem encoderItem, IBassStream stream, string executable, string directory, string arguments, bool redirectStandardInput, bool redirectStandardOutput, bool redirectStandardError)
        {
            if (!File.Exists(executable))
            {
                throw new InvalidOperationException(string.Format("A required utility was not found: {0}", executable));
            }
            var processStartInfo = new ProcessStartInfo()
            {
                FileName               = executable,
                WorkingDirectory       = directory,
                Arguments              = arguments,
                RedirectStandardInput  = redirectStandardInput,
                RedirectStandardOutput = redirectStandardOutput,
                RedirectStandardError  = redirectStandardError,
                UseShellExecute        = false,
                CreateNoWindow         = true
            };
            var process = Process.Start(processStartInfo);

            try
            {
                process.PriorityClass = ProcessPriorityClass.BelowNormal;
            }
            catch
            {
                //Nothing can be done, probably access denied.
            }
            process.ErrorDataReceived += (sender, e) =>
            {
                if (string.IsNullOrEmpty(e.Data))
                {
                    return;
                }
                Logger.Write(this, LogLevel.Trace, "{0}: {1}", executable, e.Data);
                encoderItem.AddError(e.Data);
            };
            process.BeginErrorReadLine();
            return(process);
        }