internal BookEventArgs(BookDescriptor book) { Contract.Requires(book != null); _book = book; }
public void Add(string filename, string targetFolder, string targetFormat) { Contract.Requires(File.Exists(filename)); Contract.Requires(Directory.Exists(targetFolder)); Contract.Requires(!string.IsNullOrWhiteSpace(targetFormat)); if (!IsReady) { _logger.Error("Cannot convert file"); return; } BookDescriptor book = new BookDescriptor(filename, targetFolder, targetFormat); FireBookAdded(book); _books.Add(book); }
private void FireBookRemoved(BookDescriptor book) { Contract.Requires(book != null); if (BookRemoved != null) { BookRemoved(this, new BookEventArgs(book)); } }
public void Remove(BookDescriptor book) { Contract.Requires(book != null); _removedBooks.TryAdd(book, book); FireBookRemoved(book); }
private string CreateProcessArguments(BookDescriptor book) { FileInfo fi = book.FileInfo; string outFilename = Path.ChangeExtension(fi.Name, book.TargetFormat); string outFolder; if (_configuration.OutputInSourceFolder) { outFolder = fi.DirectoryName; } else { outFolder = book.TargetFolder; } string args = string.Format(@"""{0}"" ""{1}\{2}""", fi.FullName, outFolder, outFilename); return args; }
private void StartConverterProcess(BookDescriptor book, ExecutionContext context) { string converterBinary = Path.Combine(_configuration.ConverterPath, Constants.ConverterBinaryFile); string args = CreateProcessArguments(book); Process prc = new Process(); prc.StartInfo = new ProcessStartInfo(converterBinary, args); prc.StartInfo.CreateNoWindow = true; prc.StartInfo.ErrorDialog = false; prc.StartInfo.RedirectStandardError = true; prc.StartInfo.RedirectStandardInput = true; prc.StartInfo.RedirectStandardOutput = true; prc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; prc.StartInfo.UseShellExecute = false; // must be 'false' if redirecting IO streams if (prc.Start()) { context.Stream = prc.StandardOutput; book.Status = ConversionStatus.Finished; FireBookChanged(book); _logger.Info("processing book... finished '{0}' => '.{1}'", book.FileInfo.Name, book.TargetFormat.ToUpper()); } else { _logger.Error("Failed to start process. book: '{0}'", book.FileInfo.Name); } }