private CSVDocument AddDJVUToCsv(string file, int requestedDPI, CancellationTokenSource source, string rootFolder) { try { LogWriter.LogMessage($"Reading file {file}", LogDepth.UserLevel); CSVDocument csvDocument = null; try { csvDocument = CSVDocument.FromFile(file); } catch (FileNotFoundException ex) { LogWriter.LogMessage(ex.Message); } CSVRow anyRow = csvDocument.Rows[0]; var imagesForDJVU = csvDocument.Rows.Select(s => { if (s.Content.ContainsKey("DJVUIMAGES")) { return(s.Content["DJVUIMAGES"]); } else if (s.Content.ContainsKey("FILES")) { return(s.Content["FILES"]); } else { throw new Exception("Columns in CSV are incorrect."); } }); var outputDJVUPath = Regex.Replace(csvDocument.Rows.FirstOrDefault().PathToPDF, "[.]pdf", ".djvu"); try { bool singlePDFInput = imagesForDJVU.Distinct().Count() == 1; if (singlePDFInput) { PDFToDJVU.Executor.NewPrepareDJVU(imagesForDJVU.FirstOrDefault(), outputDJVUPath, source, requestedDPI); } else { PDFToDJVU.Executor.PrepareDJVU(imagesForDJVU.ToArray(), outputDJVUPath, source, rootFolder, requestedDPI); } } catch (Exception) { source.Cancel(); throw; } CSVRow DJVUFullDocument = (CSVRow)anyRow.Clone(); DJVUFullDocument.Content["PAGES"] = "0"; DJVUFullDocument.PathToPDF = outputDJVUPath; LogWriter.LogMessage($"Adding a row with DJVUDocument {outputDJVUPath}", LogDepth.Debug); csvDocument.Add(DJVUFullDocument); return(csvDocument); } catch (Exception ex) { LogWriter.LogMessage(ex.Message, LogDepth.Debug); throw; } }