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">
......
......@@ -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