Commit 75aec1ee authored by tsuji's avatar tsuji

検版実行中のキャンセル処理を追加

parent 6c87f8dd
......@@ -146,7 +146,8 @@ namespace CSRender
//指定先にレポートを移動
internal static void moveReport(string resultPath, string workPath)
{
string reportPath = System.IO.Path.Combine(resultPath, "report", "Log");
//string reportPath = System.IO.Path.Combine(resultPath, "report", "Log");
string reportPath = System.IO.Path.Combine(resultPath, "Log");
if (!Directory.Exists(reportPath))//指定先にreportフォルダがあるか
{
Directory.CreateDirectory(reportPath);//なければ新規でreportフォルダを作成
......
......@@ -338,5 +338,25 @@ namespace CSRender
Directory.CreateDirectory(inDirPath);//同名のディレクトリを作成
}
//キャンセルが実行されたときに、途中で生成したファイル群を削除
private void DelDirCancel(string inWorkPath)
{
try
{
if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "OUT_DIFF")))
{
Directory.Delete(System.IO.Path.Combine(inWorkPath, "OUT_DIFF"), true);//OUT_DIFFを削除
}
if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "work")))
{
Directory.Delete(System.IO.Path.Combine(inWorkPath, "work"), true);//作業(work)ディレクトリを削除
}
}
catch(Exception ex)
{
return;
}
}
}
}
......@@ -62,9 +62,9 @@
</ComboBox.Background>
</ComboBox>
</StackPanel>
<Label Content="出力形式:" Margin="41,0,11,1.667" VerticalAlignment="Bottom" RenderTransformOrigin="0.544,1.949" FontSize="14" Grid.Row="9" Height="29" Grid.RowSpan="2"/>
<Label Content="出力形式:" Margin="9,0,43,2" VerticalAlignment="Bottom" RenderTransformOrigin="0.544,1.949" FontSize="14" Grid.Row="9" Height="29" Grid.RowSpan="2"/>
<Label x:Name="pageLabel" Content="指定ページ:" Margin="1,27.667,91.667,0" VerticalAlignment="Top" RenderTransformOrigin="0.544,1.949" FontSize="14" Grid.Row="5" Height="29" IsEnabled="{Binding PageRange_SelectionChanged}" Grid.RowSpan="3" Grid.Column="1"/>
<StackPanel HorizontalAlignment="Left" Margin="119,2.333,0,0.333" Grid.Row="10" Width="71" Grid.RowSpan="2" Grid.ColumnSpan="2" >
<StackPanel HorizontalAlignment="Left" Margin="84,2,0,0" Grid.Row="10" Width="71" Grid.RowSpan="2" Grid.ColumnSpan="2" >
<ComboBox x:Name="FileSelect" SelectedValuePath="Id" DisplayMemberPath="Item" Height="21" SelectedValue="1" Margin="0,0,9.667,0" BorderBrush="#FF3A3A3A" >
<ComboBox.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
......@@ -78,9 +78,10 @@
TextWrapping="Wrap" Text="1,2,4-6" VerticalAlignment="Top" FontSize="14" IsEnabled="{Binding PageRange_SelectionChanged}" Grid.ColumnSpan="3"
InputMethod.IsInputMethodSuspended="True" PreviewKeyDown="PageBox_PreviewKeyDown" PreviewTextInput="PageBox_PreviewTextInput" LostFocus="PageBox_LostFocus" CommandManager.PreviewExecuted="PageBox_PreviewExecuted" BorderBrush="#FF595959"/>
<TextBox x:Name="ResultConsole" Margin="44,6.667,44.333,8.667" Grid.Row="9" Grid.ColumnSpan="4" VerticalScrollBarVisibility="Auto" FontSize="14" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" BorderBrush="#FF595959" Panel.ZIndex="1"/>
<Button x:Name="TIFFButton" Content="画像出力" HorizontalAlignment="Left" Height="22" Margin="52,2.333,0,0" Grid.Row="10" VerticalAlignment="Top" Width="82" Click="TIFFButtonClick" Grid.Column="1"/>
<Button x:Name="CompareButton" Content="比較" HorizontalAlignment="Left" Height="22" Margin="143,2.333,0,0" Grid.Row="10" VerticalAlignment="Top" Width="82" Grid.Column="1" Click="CompareButtonClick" Grid.ColumnSpan="2"/>
<Button x:Name="closeButton" Content="Close" Height="22" Margin="0,2.333,45.333,0" Grid.Row="10" VerticalAlignment="Top" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Right" Width="77" Click="CloseButton_Click"/>
<Button x:Name="TIFFButton" Content="画像出力" HorizontalAlignment="Left" Height="22" Margin="17,2,0,0" Grid.Row="10" VerticalAlignment="Top" Width="70" Click="TIFFButtonClick" Grid.Column="1"/>
<Button x:Name="CompareButton" Content="比較" HorizontalAlignment="Left" Height="22" Margin="96,2,0,0" Grid.Row="10" VerticalAlignment="Top" Width="70" Grid.Column="1" Click="CompareButtonClick"/>
<Button x:Name="closeButton" Content="Close" Height="22" Margin="0,2.333,45.333,0" Grid.Row="10" VerticalAlignment="Top" Grid.Column="2" Grid.ColumnSpan="2" HorizontalAlignment="Right" Width="70" Click="CloseButton_Click"/>
<Button x:Name="cancelButton" Content="Cancel" Height="22" Margin="0,2,39,0" Grid.Row="10" VerticalAlignment="Top" Grid.Column="2" HorizontalAlignment="Right" Width="70" Click="CancelButton_Click"/>
<Label Content="位置ズレ許容量(0 - 2):" Margin="1,0.667,29.667,0" VerticalAlignment="Top" RenderTransformOrigin="0.544,1.949" FontSize="14" Grid.Row="7" Height="29" Grid.RowSpan="2" Grid.Column="1"/>
<StackPanel Grid.Column="1" Grid.Row="7" Orientation="Horizontal" HorizontalAlignment="Left" Margin="153,4.667,0,2.333" Width="32" Background="WhiteSmoke">
......
......@@ -18,6 +18,7 @@ using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Windows.Threading;
using System.Threading;
namespace CSRender
{
......@@ -80,6 +81,25 @@ namespace CSRender
private void CloseButton_Click(object sender, RoutedEventArgs e) =>
Close();
private CancellationTokenSource CancelToken = null;
//private CancellationToken Canceller;
//Cancelボタン実行
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
isCanceled = true;
ResultConsole.Text += " 処理を中断します\r\n";
if (CancelToken == null) { return; }
else { CancelToken.Cancel(); }
//if (CancelToken?.IsCancellationRequested == false)
//{ CancelToken.Cancel(); }
}
/// <summary>
/// キャンセルフラグ
/// </summary>
private bool isCanceled = false;
/// <summary>
/// 比較ボタンを実行する。
/// </summary>
......@@ -107,6 +127,17 @@ namespace CSRender
{
killButton();//メニューを非活性化
isCanceled = false;//Cancelフラグを初期化
CancelToken = new CancellationTokenSource();
var Canceller = CancelToken.Token;
//前回のOUT_DIFFフォルダを削除
string OldOutDiff = System.IO.Path.Combine(Properties.Settings.Default.workSpaceSetting, "OUT_DIFF");
if (Directory.Exists(OldOutDiff))
{
Directory.Delete(OldOutDiff, true);
}
//各種パスの指定先の取得
string workBoxText = workBox.Text;
string reportBoxText = reportBox.Text;
......@@ -186,7 +217,7 @@ namespace CSRender
//前回のログが内部に残っていれば削除(エラー防止)
CompareTIFF.deleteOldLog(System.IO.Path.Combine(workDir, "report"));
string workLogPath = System.IO.Path.Combine(workBoxText, "report");//reportフォルダのパス
string workLogPath = System.IO.Path.Combine(reportBoxText, "Log");//reportフォルダのパス
checkDirPath(workLogPath);//なければ作成
string outDiffPath = System.IO.Path.Combine(workBoxText, "OUT_DIFF");//DIFF画像の出力先パス
checkDirPath(outDiffPath);//なければ作成
......@@ -195,6 +226,10 @@ namespace CSRender
{
//検版レポートの入力チェック
reportFlag = checkReportPath();
if (reportBoxText == "")
{
reportBoxText = reportBox.Text;
}
}
catch (Exception ex)
{
......@@ -213,202 +248,348 @@ namespace CSRender
selectedPage = pageBox.Text;
}
//TIFF画像の生成
ResultConsole.Text += "< TIFF変換開始 >\r\n";
ResultConsole.Text += " 対象ファイルをTIFF画像に変換中\r\n";
ResultConsole.ScrollToEnd();
DoEvents();
//対象フォルダ
string targetTIFFPath = System.IO.Path.Combine(workBoxText, "work", "targetTIFF");
DeleteOldDir(targetTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
//CSRenderの実行
//実処理スタート
try
{
await Task.Run(() =>
//TIFF画像の生成
ResultConsole.Text += "< TIFF変換開始 >\r\n";
ResultConsole.Text += " 対象ファイルをTIFF画像に変換中\r\n";
ResultConsole.ScrollToEnd();
DoEvents();
//対象フォルダ
string targetTIFFPath = System.IO.Path.Combine(workBoxText, "work", "targetTIFF");
DeleteOldDir(targetTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
if (isCanceled)
{
string targetTIFFResult =
OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, targetBoxText, targetTIFFPath);
});
}
catch (Exception ex)
{
string WorkCategory = "対象PDFのTIFF画像生成";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DoEvents();
DelDirCancel(workBoxText);
reviveButton();
return;
}
ResultConsole.Text += " リファレンスファイルをTIFF画像に変換中\r\n";
ResultConsole.ScrollToEnd();
DoEvents();
//CSRenderの実行
try
{
await Task.Run(() =>
//await Task.Factory.StartNew(() =>
{
//string targetTIFFResult =
OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, targetBoxText, targetTIFFPath, Canceller, isCanceled);
//リファレンスフォルダ
string referenceTIFFPath = System.IO.Path.Combine(workBoxText, "work", "referenceTIFF");
DeleteOldDir(referenceTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
//CSRenderの実行
try
{
await Task.Run(() =>
}, Canceller);
//string targetTIFFResult = await OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, targetBoxText, targetTIFFPath, Canceller, isCanceled);
}
catch (OperationCanceledException)
{
string referenceTIFFResult =
OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, referenceBoxText, referenceTIFFPath);
});
}
catch (Exception ex)
{
string WorkCategory = "リファレンスPDFのTIFF画像生成";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
CancelToken.Dispose();
CancelToken = null;
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
reviveButton();
DoEvents();
return;
}
catch (Exception ex)
{
string WorkCategory = "対象PDFのTIFF画像生成";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
if (!isCanceled)
{
ResultConsole.Text += " リファレンスファイルをTIFF画像に変換中\r\n";
ResultConsole.ScrollToEnd();
}
ripTime.Stop();//RIP時間の計測終了
TimeSpan timeResult = ripTime.Elapsed;
var allRipTime = $"{timeResult}".Substring(0,8);
//リファレンスフォルダ
string referenceTIFFPath = System.IO.Path.Combine(workBoxText, "work", "referenceTIFF");
DeleteOldDir(referenceTIFFPath); //指定先に古いTIFF用フォルダがあれば削除し、新たに作成(前回作業時の生成物との混同防止)
ResultConsole.Text += " [RIP処理時間 " + allRipTime + "]\r\n";
ResultConsole.Text += "< TIFF変換完了 >\r\n";
ResultConsole.ScrollToEnd();
DoEvents();
try
{
//レポートへの出力内容を編集
//editReport(allRipTime, workBoxText);
reportContentsInfo = CompareTIFF.getReportInfo(allRipTime, workBoxText,
targetBoxText, referenceBoxText, ResolutionBox.Text, PageRange.Text, pageBox.Text);
}
catch (Exception ex)
{
string WorkCategory = "検版レポートの編集";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
//この時点での出力文字列を取得
string tiffString = ResultConsole.Text;
try
{
// 日付取得
DateTime NowTime = DateTime.Now;
//検版対象ファイル名の取得
string[] inspectionTargets = CompareTIFF.GetTargetList(targetBoxText, referenceBoxText);
allPDFNum = CompareTIFF.getNumOfTiff(inspectionTargets, targetTIFFPath);//検版する画像ファイルの総数
//出力メニューの進捗表示を初期化
resetProgressText(allPDFNum);
// 並列処理オプションの設定
ParallelOptions parallelOptions = new ParallelOptions();
parallelOptions.MaxDegreeOfParallelism = 4;// 並行数(プロセス数)
var logicalProcessNum = Environment.ProcessorCount;//PCの論理CPUの数
if (logicalProcessNum >= 10)
if (isCanceled)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
DoEvents();
reviveButton();
return;
}
//CSRenderの実行
try
{
await Task.Run(() =>
{
//string referenceTIFFResult =
OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, referenceBoxText, referenceTIFFPath, Canceller, isCanceled);
}, Canceller);
//string referenceTIFFResult = await OutputTIFF.runCSRender(ResolutionBox.Text, "TIFF", pageFlag, selectedPage, referenceBoxText, referenceTIFFPath, Canceller, isCanceled);
}
catch (OperationCanceledException)
{
parallelOptions.MaxDegreeOfParallelism = logicalProcessNum - 4;
CancelToken.Dispose();
CancelToken = null;
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
reviveButton();
DoEvents();
return;
}
catch (Exception ex)
{
string WorkCategory = "リファレンスPDFのTIFF画像生成";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
if (isCanceled)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
reviveButton();
return;
}
ripTime.Stop();//RIP時間の計測終了
TimeSpan timeResult = ripTime.Elapsed;
var allRipTime = $"{timeResult}".Substring(0, 8);
ResultConsole.Text += " [RIP処理時間 " + allRipTime + "]\r\n";
ResultConsole.Text += "< TIFF変換完了 >\r\n";
ResultConsole.ScrollToEnd();
DoEvents();
if (isCanceled)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
reviveButton();
return;
}
//並列処理内で固定の引数を事前に処理
string verifyArgs = CompareTIFF.makeFixityArg(targetTIFFPath, referenceTIFFPath,
shiftPixel, colorMargin, removePoint, shadingOff, appDirectory);
try
{
//レポートへの出力内容を編集
//editReport(allRipTime, workBoxText);
reportContentsInfo = CompareTIFF.getReportInfo(allRipTime, workBoxText,
targetBoxText, referenceBoxText, ResolutionBox.Text, PageRange.Text, pageBox.Text);
}
catch (Exception ex)
{
string WorkCategory = "検版レポートの編集";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
await Task.Factory.StartNew(() => {
Parallel.ForEach(inspectionTargets, parallelOptions, targetPDFName =>
//この時点での出力文字列を取得
string tiffString = ResultConsole.Text;
try
{
// 日付取得
DateTime NowTime = DateTime.Now;
//検版対象ファイル名の取得
string[] inspectionTargets = CompareTIFF.GetTargetList(targetBoxText, referenceBoxText);
allPDFNum = CompareTIFF.getNumOfTiff(inspectionTargets, targetTIFFPath);//検版する画像ファイルの総数
//出力メニューの進捗表示を初期化
resetProgressText(allPDFNum);
// 並列処理オプションの設定
ParallelOptions parallelOptions = new ParallelOptions();
parallelOptions.MaxDegreeOfParallelism = 4;// 並行数(プロセス数)
//parallelOptions.CancellationToken = CancelToken.Token;
var logicalProcessNum = Environment.ProcessorCount;//PCの論理CPUの数
if (logicalProcessNum >= 10)
{
//PureVerifyの実行
int[] NGTiffNum = CompareTIFF.runPureVerify(targetTIFFPath, referenceTIFFPath,
shiftPixel, colorMargin, removePoint, shadingOff, reportFlag, reportBoxText,
outDiffPath, targetPDFName, NowTime, reportContentsInfo, appDirectory, exePath, verifyArgs);
ResultConsole.Dispatcher.Invoke(new Action(() =>
parallelOptions.MaxDegreeOfParallelism = logicalProcessNum - 4;
}
//並列処理内で固定の引数を事前に処理
string verifyArgs = CompareTIFF.makeFixityArg(targetTIFFPath, referenceTIFFPath,
shiftPixel, colorMargin, removePoint, shadingOff, appDirectory);
await Task.Factory.StartNew(() => {
if (isCanceled)
{
outProgressToUI(tiffString, NGTiffNum, allPDFNum);
}));
// キャンセルされたら終了
ResultConsole.Text += " 処理を中断します\r\n";
CancelToken.Cancel();
DoEvents();
reviveButton();
return;
}
Parallel.ForEach(inspectionTargets, parallelOptions, targetPDFName =>
{
//キャンセルフラグONなら終了
if (isCanceled)
{
return;
}
//PureVerifyの実行
int[] NGTiffNum = CompareTIFF.runPureVerify(targetTIFFPath, referenceTIFFPath,
shiftPixel, colorMargin, removePoint, shadingOff, reportFlag, reportBoxText,
outDiffPath, targetPDFName, NowTime, reportContentsInfo, appDirectory, exePath, verifyArgs);
//キャンセルフラグONなら終了
if (isCanceled)
{
return;
}
ResultConsole.Dispatcher.Invoke(new Action(() =>
{
outProgressToUI(tiffString, NGTiffNum, allPDFNum);
}));
});
});
});
}
catch (Exception ex)
{
string WorkCategory = "検版処理";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
try
{
//レポートを出力
//outputLog(System.IO.Path.Combine(workDir, "report"));
NGPDFNum = CompareTIFF.getNGNum(System.IO.Path.Combine(workDir, "report"));
ResultConsole.Text = tiffString;
outResultToUI(allPDFNum, NGPDFNum, referenceTIFFPath, targetTIFFPath);
}
catch (Exception ex)
{
string WorkCategory = "検版ログの出力";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
}
catch (OperationCanceledException)
{
CancelToken.Dispose();
CancelToken = null;
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
reviveButton();
DoEvents();
return;
}
catch (Exception ex)
{
string WorkCategory = "検版処理";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
string PDFName = "";
try
{
//レポート名を取得
if (reportBox.Text != ""){ PDFName = reportBoxText; }
else { PDFName = CompareTIFF.getReportName(workDir); }
}
catch (Exception ex)
{
string WorkCategory = "レポート名の取得";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
try
{
//レポートを出力
//outputLog(System.IO.Path.Combine(workDir, "report"));
NGPDFNum = CompareTIFF.getNGNum(System.IO.Path.Combine(workDir, "report"));
try
{
//指定先にレポートを移動
CompareTIFF.moveReport(workBoxText, workDir);
}
catch (Exception ex)
{
string WorkCategory = "ログファイルの移動";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
if (isCanceled)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
DoEvents();
reviveButton();
return;
}
//レポートのパスを表示
ResultConsole.Text += " 検版レポートのパス:";
ResultConsole.Text += System.IO.Path.Combine(workBoxText, "report", PDFName);
ResultConsole.Text += "\r\n";
if(reportBox.Text == "")
{
reportBox.Text = System.IO.Path.Combine(workBoxText, "report", PDFName);
}
//UIの更新
ResultConsole.Text = tiffString;
outResultToUI(allPDFNum, NGPDFNum, referenceTIFFPath, targetTIFFPath);
}
catch (Exception ex)
{
string WorkCategory = "検版ログの出力";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
//リファレンスファイルを発見できず検版回数0の場合、メッセージを出力して通知
if (allPDFNum == 0)
{
CustomMsgBox.Show(mainWindow, "指定先のリファレンスフォルダから、対象フォルダ内のファイルと対応するファイルを発見できませんでした。",
"検版対象を発見できませんでした。", MessageBoxButton.OK, MessageBoxImage.Warning);
}
string PDFName = "";
try
{
//生成したレポートinf.txtを全削除
CompareTIFF.deleteReportTexts();
if (isCanceled)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
reviveButton();
return;
}
//生成したダミーファイルを削除
if (dummyFlag)
{
CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Target"), dummyFileName);
CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Reference"), dummyFileName);
}
//レポート名を取得
if (reportBox.Text != "") { PDFName = reportBoxText; }
else { PDFName = CompareTIFF.getReportName(workDir); }
}
catch (Exception ex)
{
string WorkCategory = "レポート名の取得";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
//パラメータを次回初期値用に保存
Properties.Settings.Default.resolutionSetting = ResolutionBox.Value;
Properties.Settings.Default.formatSetting = FileSelect.Text;
Properties.Settings.Default.shiftPixelSetting = PositionBox.Value;
Properties.Settings.Default.colorMarginSetting = GradationBox.Value;
Properties.Settings.Default.removePointSetting = SmallDiffBox.Value;
Properties.Settings.Default.shadingOffSetting = VisualBox.Value;
Properties.Settings.Default.workSpaceSetting = workBoxText;
Properties.Settings.Default.targetSetting = targetBox.Text;
Properties.Settings.Default.referenceSetting = referenceBox.Text;
Properties.Settings.Default.reportPathSetting = reportBoxText;
Properties.Settings.Default.Save();
try
{
if (isCanceled)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
DoEvents();
reviveButton();
return;
}
//指定先にレポートを移動
CompareTIFF.moveReport(reportBoxText, workDir);
}
catch (Exception ex)
{
string WorkCategory = "ログファイルの移動";
ExceptionMessage(ex, workLogPath, WorkCategory);
}
//レポートのパスを表示
ResultConsole.Text += " 検版レポートのパス:";
ResultConsole.Text += System.IO.Path.Combine(workBoxText, PDFName);
ResultConsole.Text += "\r\n";
if (reportBox.Text == "")
{
reportBox.Text = System.IO.Path.Combine(workBoxText, "report", PDFName);
}
reviveButton();
//リファレンスファイルを発見できず検版回数0の場合、メッセージを出力して通知
if (allPDFNum == 0)
{
CustomMsgBox.Show(mainWindow, "指定先のリファレンスフォルダから、対象フォルダ内のファイルと対応するファイルを発見できませんでした。",
"検版対象を発見できませんでした。", MessageBoxButton.OK, MessageBoxImage.Warning);
}
//生成したレポートinf.txtを全削除
CompareTIFF.deleteReportTexts();
//生成したダミーファイルを削除
if (dummyFlag)
{
CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Target"), dummyFileName);
CompareTIFF.deleteDummyFile(System.IO.Path.Combine(workBoxText, "Dummy", "Reference"), dummyFileName);
}
//パラメータを次回初期値用に保存
Properties.Settings.Default.resolutionSetting = ResolutionBox.Value;
Properties.Settings.Default.formatSetting = FileSelect.Text;
Properties.Settings.Default.shiftPixelSetting = PositionBox.Value;
Properties.Settings.Default.colorMarginSetting = GradationBox.Value;
Properties.Settings.Default.removePointSetting = SmallDiffBox.Value;
Properties.Settings.Default.shadingOffSetting = VisualBox.Value;
Properties.Settings.Default.workSpaceSetting = workBoxText;
Properties.Settings.Default.targetSetting = targetBox.Text;
Properties.Settings.Default.referenceSetting = referenceBox.Text;
Properties.Settings.Default.reportPathSetting = reportBoxText;
Properties.Settings.Default.Save();
reviveButton();
}
catch (OperationCanceledException)
{
// キャンセルされたら終了
ResultConsole.Text += " 処理が中断されました\r\n";
DelDirCancel(workBoxText);
CancelToken.Dispose();
CancelToken = null;
DoEvents();
reviveButton();
return;
}
}
/// <summary>
......@@ -591,6 +772,16 @@ namespace CSRender
ResultConsole.ScrollToEnd();
}
/// <summary>
/// キャンセル実行時に生成済みのファイルを削除
/// </summary>
private void canceledFile(string inWorkPath, string inReportPath)
{
}
/// <summary>
/// TIFF画像化を実行する
/// </summary>
......@@ -598,8 +789,13 @@ namespace CSRender
/// <param name="selectedPage">入力されたページ数</param>
/// <param name="TIFFresult">CSRenderの処理出力文</param>
///
private void TIFFButtonClick(object sender, RoutedEventArgs e)
private async void TIFFButtonClick(object sender, RoutedEventArgs e)
{
isCanceled = false;//Cancelフラグを初期化
//キャンセルトークン生成
//CancellationTokenSource CancelToken = new CancellationTokenSource();
var Canceller = CancelToken.Token;
//出力メニューにメッセージを出力
ResultConsole.Text += "<変換開始>\r\n";
ResultConsole.Text += " PDFを" + FileSelect.Text + "に変換します\r\n";
......@@ -648,10 +844,10 @@ namespace CSRender
}
//CSRenderの実行
string TIFFresult =
OutputTIFF.runCSRender(ResolutionBox.Text, FileSelect.Text, pageFlag, selectedPage, targetBox.Text, workBox.Text);
//string TIFFresult =
OutputTIFF.runCSRender(ResolutionBox.Text, FileSelect.Text, pageFlag, selectedPage, targetBox.Text, workBox.Text, Canceller, isCanceled);
ResultConsole.Text += TIFFresult;
//ResultConsole.Text += TIFFresult;
ResultConsole.Text += "\r\n<変換終了>\r\n";
ResultConsole.ScrollToEnd();
......@@ -742,5 +938,6 @@ namespace CSRender
VisualBox.Enabled = true;
pageBox.IsEnabled = true;
}
}
}
......@@ -16,58 +16,129 @@ using System.Windows.Controls.Primitives;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace CSRender
{
class OutputTIFF
partial class OutputTIFF
{
public static string runCSRender(string resolutionNum, string outputFile,
bool pageFlag, string filePage, string targetPath, string workPath)
public static void runCSRender(string resolutionNum, string outputFile,
bool pageFlag, string filePage, string targetPath, string workPath, CancellationToken inCanceller, bool inCanFlag)
{
//実行用コンソール呼び出し
ProcessStartInfo processStartInfo = new ProcessStartInfo();
string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得
string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得
processStartInfo.FileName = System.IO.Path.Combine(appDirectory, "CSRender.Data", "CSRender.exe");
processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示
processStartInfo.UseShellExecute = false; // シェル機能オフ
processStartInfo.RedirectStandardOutput = true;//標準出力をリダイレクト
//解像度の引数
processStartInfo.Arguments = "/D ";
processStartInfo.Arguments += resolutionNum;
//出力ファイル形式の引数
processStartInfo.Arguments += " /";
processStartInfo.Arguments += outputFile;
processStartInfo.Arguments += " ";
//必要に応じてページ引数を指定
if (pageFlag == true)
//string resuletString = "";
try
{
processStartInfo.Arguments += "/P \"";
processStartInfo.Arguments += filePage;
processStartInfo.Arguments += "\" ";
}
//実行用コンソール呼び出し
ProcessStartInfo processStartInfo = new ProcessStartInfo();
string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location; //モジュールのパスを取得
string appDirectory = appPath.Substring(0, appPath.LastIndexOf(@"\") + 1); //モジュールの存在するディレクトリを取得
processStartInfo.FileName = System.IO.Path.Combine(appDirectory, "CSRender.Data", "CSRender.exe");
processStartInfo.CreateNoWindow = true; // コマンドプロンプトを非表示
processStartInfo.UseShellExecute = false; // シェル機能オフ
processStartInfo.RedirectStandardOutput = true;//標準出力をリダイレクト
//解像度の引数
processStartInfo.Arguments = "/D ";
processStartInfo.Arguments += resolutionNum;
//出力ファイル形式の引数
processStartInfo.Arguments += " /";
processStartInfo.Arguments += outputFile;
processStartInfo.Arguments += " ";
//指定ファイル
processStartInfo.Arguments += "/F ";
processStartInfo.Arguments += targetPath;
//必要に応じてページ引数を指定
if (pageFlag == true)
{
processStartInfo.Arguments += "/P \"";
processStartInfo.Arguments += filePage;
processStartInfo.Arguments += "\" ";
}
//出力フォルダ
if (workPath != "")
//指定ファイル
processStartInfo.Arguments += "/F ";
processStartInfo.Arguments += targetPath;
//出力フォルダ
if (workPath != "")
{
processStartInfo.Arguments += " /O ";
processStartInfo.Arguments += workPath;
}
//CSRender.exeを実行
Process process = Process.Start(processStartInfo);
Boolean ProcEndFlag = false;
if (inCanceller.IsCancellationRequested)
{
process.Kill();
inCanceller.ThrowIfCancellationRequested();
//process.Close();
// if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "OUT_DIFF")))
// {
// Directory.Delete(System.IO.Path.Combine(inWorkPath, "OUT_DIFF"), true);//OUT_DIFFを削除
// }
// if (Directory.Exists(System.IO.Path.Combine(inWorkPath, "work")))
// {
// Directory.Delete(System.IO.Path.Combine(inWorkPath, "work"), true);//作業(work)ディレクトリを削除
// }
return;
}
////string resuletString = process.StandardOutput.ReadToEnd();
//resuletString = process.StandardOutput.ReadToEnd();
//resuletString = await ReadLineAsync(process, resuletString);
//process.WaitForExit();
while (!ProcEndFlag)
{
if (inCanceller.IsCancellationRequested)
{
process.Kill();
inCanceller.ThrowIfCancellationRequested();
return;
}
ProcEndFlag = process.WaitForExit(10000);
}
process.Close();
}
catch (OperationCanceledException)
{
processStartInfo.Arguments += " /O ";
processStartInfo.Arguments += workPath;
return;
}
//CSRender.exeを実行
Process process = Process.Start(processStartInfo);
string resuletString = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Close();
return resuletString;
return;
}
private async static Task<string> ReadLineAsync(Process inProc, string inLineStr)
{
inLineStr = await inProc.StandardOutput.ReadToEndAsync();
return inLineStr;
}
//public static async Task<string>runExe(string resolutionNum, string outputFile,
// bool pageFlag, string filePage, string targetPath, string workPath, CancellationToken inCanceller)
//{
// string resuletString = "";
// try
// {
// await Task.Run(async () =>
// //await Task.Factory.StartNew(() =>
// {
// resuletString =
// OutputTIFF.runCSRender(resolutionNum, outputFile, pageFlag, filePage, targetPath, workPath, inCanceller);
// }, inCanceller);
// }
// catch(OperationCanceledException)
// {
// return "Canceled";
// }
// return resuletString;
//}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment