/* ----------------------------------------------------------------- */ /// /// AssertRun /// /// <summary> /// Converter クラスの実行をチェックします。 /// </summary> /// /* ----------------------------------------------------------------- */ private void AssertRun(UserSetting setting, string suffix) { var basename = IoEx.Path.GetFileNameWithoutExtension(setting.InputPath); var extension = Parameter.GetExtension((Parameter.FileTypes)setting.FileType); setting.LibPath = IoEx.Path.Combine(_root, "Ghostscript"); setting.OutputPath = IoEx.Path.Combine(_results, basename + suffix + extension); if (setting.ExistedFile == Parameter.ExistedFiles.Overwrite) { IoEx.File.Delete(setting.OutputPath); } var converter = new Converter(); converter.Run(setting); var error = GetErrorMessage(converter); Assert.IsTrue(string.IsNullOrEmpty(error), string.Format("{0}:{1}", setting.InputPath, error)); if (!IoEx.File.Exists(setting.OutputPath)) { var dest = String.Format("{0}\\{1}-001{2}", IoEx.Path.GetDirectoryName(setting.OutputPath), IoEx.Path.GetFileNameWithoutExtension(setting.OutputPath), IoEx.Path.GetExtension(setting.OutputPath) ); Assert.IsTrue(IoEx.File.Exists(dest), setting.OutputPath); } else if (setting.FileType == Parameter.FileTypes.PDF) { AssertPdf(setting); } }
public void TestErrorInMerge(bool caused_by_security) { var setting = CreateSetting(); var suffix = "-error-in-merge"; var dest = IoEx.Path.Combine(_results, string.Format("example{0}.pdf", suffix)); if (caused_by_security) { setting.Permission.Password = "******"; AssertRun(setting, suffix); } else { IoEx.File.Copy(IoEx.Path.Combine(_examples, "dummy.txt"), dest, true); } var hash = GetHash(dest); setting.OutputPath = dest; setting.Permission.Password = string.Empty; setting.ExistedFile = Parameter.ExistedFiles.MergeTail; var converter = new Converter(); converter.Run(setting); var error = GetErrorMessage(converter); Assert.IsFalse(string.IsNullOrEmpty(error)); Assert.IsTrue(IoEx.File.Exists(dest)); Assert.AreEqual(hash, GetHash(dest)); }
/* ----------------------------------------------------------------- */ /// /// ConvertBackgroundWorker_DoWork /// /// <summary> /// BackgroundWorker オブジェクトが非同期での実行を開始した時に /// 実行されるイベントハンドラです。メインとなる変換処理を実行します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ConvertBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var converter = new Converter(); converter.Run(_setting); e.Result = converter.Messages; }
/* ----------------------------------------------------------------- */ // バックグラウンドワーカ(メイン処理) /* ----------------------------------------------------------------- */ #region Event handlers for background worker /* ----------------------------------------------------------------- */ /// /// ConvertBackgroundWorker_DoWork /// /// <summary> /// BackgroundWorker オブジェクトが非同期での実行を開始した時に /// 実行されるイベントハンドラです。メインとなる変換処理を実行します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ConvertBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { Converter converter = new Converter(); bool status = converter.Run(_setting); converter.Messages.Add(new Message(Message.Levels.Info, String.Format("CubePdf.Converter.Run: {0}", status.ToString()))); e.Result = converter.Messages; }
/* ----------------------------------------------------------------- */ /// /// ExecConvert /// /// <summary> /// 変換処理を実行します。このメソッドは、CubePDF メイン画面が表示 /// されない設定の場合に実行されます。 /// </summary> /// /* ----------------------------------------------------------------- */ private static void ExecConvert(UserSetting setting) { var converter = new Converter(); converter.Run(setting); foreach (var message in converter.Messages) Trace.WriteLine(message.ToString()); if (setting.DeleteOnClose && IoEx.File.Exists(setting.InputPath)) { IoEx.File.Delete(setting.InputPath); } }
/* ----------------------------------------------------------------- */ /// /// ExecConvert /// /// <summary> /// 変換処理を実行します。このメソッドは、CubePDF メイン画面が表示 /// されない設定の場合に実行されます。 /// </summary> /// /* ----------------------------------------------------------------- */ private static void ExecConvert(UserSetting setting) { var converter = new Converter(); converter.Run(setting); foreach (var message in converter.Messages) { Trace.WriteLine(message.ToString()); } if (setting.DeleteOnClose && IoEx.File.Exists(setting.InputPath)) { IoEx.File.Delete(setting.InputPath); } }
/* ----------------------------------------------------------------- */ /// /// ExecConvert /// /// <summary> /// Examples フォルダに存在する *.ps ファイルに対して Converter.Run /// メソッドを実行し、生成されたファイルを Results フォルダに保存 /// します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ExecConvert(UserSetting setting, string suffix) { string output = System.IO.Path.Combine(Environment.CurrentDirectory, "Results"); if (!System.IO.Directory.Exists(output)) { System.IO.Directory.CreateDirectory(output); } foreach (string file in Directory.GetFiles("Examples", "*.ps")) { string filename = Path.GetFileNameWithoutExtension(file); string extension = Parameter.Extension((Parameter.FileTypes)setting.FileType); setting.InputPath = Path.GetFullPath(file); setting.OutputPath = output + '\\' + filename + suffix + extension; if (File.Exists(setting.OutputPath) && setting.ExistedFile == Parameter.ExistedFiles.Overwrite) { File.Delete(setting.OutputPath); } var converter = new Converter(); Assert.IsTrue(converter.Run(setting), String.Format("Converter.Run() failed. source file: {0}", file)); bool status = File.Exists(setting.OutputPath); if (status) { if (setting.FileType == Parameter.FileTypes.PDF) { ValidatePdf(setting); } } else { string tmp = String.Format("{0}\\{1}-001{2}", Path.GetDirectoryName(setting.OutputPath), Path.GetFileNameWithoutExtension(setting.OutputPath), Path.GetExtension(setting.OutputPath) ); status = File.Exists(tmp); Assert.IsTrue(status, String.Format("{0}: file not found", setting.OutputPath)); } } }
public void TestErrorInGhostscript(Parameter.ExistedFiles existed) { var src = IoEx.Path.Combine(_examples, "dummy.txt"); var dest = IoEx.Path.Combine(_results, "dummy.pdf"); IoEx.File.Copy(src, dest, true); var hash = GetHash(dest); var setting = CreateSetting(); setting.InputPath = src; setting.OutputPath = dest; setting.ExistedFile = existed; var converter = new Converter(); converter.Run(setting); var error = GetErrorMessage(converter); Assert.IsFalse(string.IsNullOrEmpty(error)); Assert.IsTrue(IoEx.File.Exists(dest)); Assert.AreEqual(hash, GetHash(dest)); }
/* ----------------------------------------------------------------- */ /// /// AssertRun /// /// <summary> /// Converter クラスの実行をチェックします。 /// </summary> /// /* ----------------------------------------------------------------- */ private void AssertRun(UserSetting setting, string suffix) { var basename = IoEx.Path.GetFileNameWithoutExtension(setting.InputPath); var extension = Parameter.GetExtension((Parameter.FileTypes)setting.FileType); setting.LibPath = IoEx.Path.Combine(_root, "Ghostscript"); setting.OutputPath = IoEx.Path.Combine(_results, basename + suffix + extension); if (setting.ExistedFile == Parameter.ExistedFiles.Overwrite) IoEx.File.Delete(setting.OutputPath); var converter = new Converter(); converter.Run(setting); var error = GetErrorMessage(converter); Assert.IsTrue(string.IsNullOrEmpty(error), string.Format("{0}:{1}", setting.InputPath, error)); if (!IoEx.File.Exists(setting.OutputPath)) { var dest = String.Format("{0}\\{1}-001{2}", IoEx.Path.GetDirectoryName(setting.OutputPath), IoEx.Path.GetFileNameWithoutExtension(setting.OutputPath), IoEx.Path.GetExtension(setting.OutputPath) ); Assert.IsTrue(IoEx.File.Exists(dest), setting.OutputPath); } else if (setting.FileType == Parameter.FileTypes.PDF) AssertPdf(setting); }
public void TestErrorInMerge(bool caused_by_security) { var setting = CreateSetting(); var suffix = "-error-in-merge"; var dest = IoEx.Path.Combine(_results, string.Format("example{0}.pdf", suffix)); if (caused_by_security) { setting.Permission.Password = "******"; AssertRun(setting, suffix); } else IoEx.File.Copy(IoEx.Path.Combine(_examples, "dummy.txt"), dest, true); var hash = GetHash(dest); setting.OutputPath = dest; setting.Permission.Password = string.Empty; setting.ExistedFile = Parameter.ExistedFiles.MergeTail; var converter = new Converter(); converter.Run(setting); var error = GetErrorMessage(converter); Assert.IsFalse(string.IsNullOrEmpty(error)); Assert.IsTrue(IoEx.File.Exists(dest)); Assert.AreEqual(hash, GetHash(dest)); }
/* ----------------------------------------------------------------- */ /// /// ConvertBackgroundWorker_DoWork /// /// <summary> /// BackgroundWorker オブジェクトが非同期での実行を開始した時に /// 実行されるイベントハンドラです。メインとなる変換処理を実行します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ConvertBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { Converter converter = new Converter(); bool status = converter.Run(_setting); converter.Messages.Add(new Message(Message.Levels.Info, String.Format("CubePdf.Converter.Run: {0}", status.ToString()))); e.Result = converter.Messages; }
/* ----------------------------------------------------------------- */ /// /// ExecConvert /// /// <summary> /// Examples フォルダに存在する *.ps ファイルに対して Converter.Run /// メソッドを実行し、生成されたファイルを Results フォルダに保存 /// します。 /// </summary> /// /* ----------------------------------------------------------------- */ private void ExecConvert(UserSetting setting, string suffix) { string output = System.IO.Path.Combine(Environment.CurrentDirectory, "Results"); if (!System.IO.Directory.Exists(output)) System.IO.Directory.CreateDirectory(output); foreach (string file in Directory.GetFiles("Examples", "*.ps")) { string filename = Path.GetFileNameWithoutExtension(file); string extension = Parameter.Extension((Parameter.FileTypes)setting.FileType); setting.InputPath = Path.GetFullPath(file); setting.OutputPath = output + '\\' + filename + suffix + extension; if (File.Exists(setting.OutputPath) && setting.ExistedFile == Parameter.ExistedFiles.Overwrite) { File.Delete(setting.OutputPath); } var converter = new Converter(); Assert.IsTrue(converter.Run(setting), String.Format("Converter.Run() failed. source file: {0}", file)); bool status = File.Exists(setting.OutputPath); if (status) { if (setting.FileType == Parameter.FileTypes.PDF) ValidatePdf(setting); } else { string tmp = String.Format("{0}\\{1}-001{2}", Path.GetDirectoryName(setting.OutputPath), Path.GetFileNameWithoutExtension(setting.OutputPath), Path.GetExtension(setting.OutputPath) ); status = File.Exists(tmp); Assert.IsTrue(status, String.Format("{0}: file not found", setting.OutputPath)); } } }