public void Perform(string inputDir, string outputDir, bool outputOverwriteMode, int threadCount) { try { Ground.I.CmProgressRate.Clear(); Ground.I.CmReport.Clear(); using (WorkingDir wd = new WorkingDir()) { string successfulFile = wd.MakePath(); double progressRate = 0.0; List <string> reportBuff = new List <string>(); WaitDlgTools.Show( Consts.CONV_PROCESSING_TITLE, Consts.CONV_PROCESSING_MESSAGE_NORMAL, () => { ProcessTools.Batch(new string[] { string.Format( Ground.I.ConvExeFile + " CS-Conv {0} {1} {2} {3} \"{4}\"" , StringTools.LiteEncode(inputDir) , StringTools.LiteEncode(outputDir) , outputOverwriteMode ? 1 : 0 , threadCount , successfulFile ), }, ProcMain.SelfDir ); }, () => { if (Ground.I.EvCancellable_Y.WaitForMillis(0)) { WaitDlg.Cancellable = true; } if (Ground.I.EvCancellable_N.WaitForMillis(0)) { WaitDlg.Cancellable = false; } if (Ground.I.EvMessage_Normal.WaitForMillis(0)) { WaitDlg.MessagePost.Post(Consts.CONV_PROCESSING_MESSAGE_NORMAL); } if (Ground.I.EvMessage_StartGenVideo.WaitForMillis(0)) { WaitDlg.MessagePost.Post(Consts.CONV_PROCESSING_MESSAGE_START_GEN_VIDEO); } if (Ground.I.EvMessage_GenVideoRunning.WaitForMillis(0)) { WaitDlg.MessagePost.Post(Consts.CONV_PROCESSING_MESSAGE_GEN_VIDEO_RUNNING); } { byte[] message = Ground.I.CmProgressRate.Recv(); if (message != null) { progressRate = double.Parse(Encoding.ASCII.GetString(message)); } } { byte[] message = Ground.I.CmReport.Recv(); if (message != null) { reportBuff.Add(Encoding.UTF8.GetString(message)); while (REPORT_BUFF_MAX < reportBuff.Count) { reportBuff.RemoveAt(0); } WaitDlg.DetailMessagePost.Post(reportBuff.ToArray()); } } return(progressRate); }, () => { Ground.I.EvStop_Conv.Set(); Ground.I.EvStop_Master.Set(); }); if (File.Exists(successfulFile) == false) { throw new Exception("変換プロセスは正常に動作しませんでした。"); } bool userCancelled = Ground.I.EvMessage_UserCancelled.WaitForMillis(0); if (WaitDlg.LastCancelled || userCancelled) { MessageDlgTools.Show(MessageDlg.Mode_e.Warning, "変換中止", "変換プロセスを中止しました。(" + (userCancelled ? 1 : 0) + ")"); } else { MessageDlgTools.Information("変換完了", "変換プロセスは終了しました。"); } } } catch (Exception ex) { MessageDlgTools.Error("変換処理エラー", ex); } }
private void Btn個数_Click(object sender, EventArgs e) { using (this.MTBusy.Section()) { try { string minval = this.T個数_最小値.Text; string maxval = this.T個数_最大値.Text; if (minval == "") { throw new Exception("最小値 が 未入力です。"); } if (maxval == "") { throw new Exception("最大値 が 未入力です。"); } if (StringTools.LiteValidate(minval, StringTools.DECIMAL) == false) { throw new Exception("最小値 に [0-9] 以外の文字が含まれています。"); } if (StringTools.LiteValidate(minval, StringTools.DECIMAL) == false) { throw new Exception("最大値 に [0-9] 以外の文字が含まれています。"); } if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", minval)[0] == '-') { throw new LongMessageException(Utils.AutoInsertNewLine("最小値 には 0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg)); } if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", maxval)[0] == '-') { throw new LongMessageException(Utils.AutoInsertNewLine("最大値 には 0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg)); } if (Ground.TCalc_Int.Calc(maxval, "-", minval)[0] == '-') { throw new Exception("最大値 < 最小値 になっています。"); } string outFile = "PrimeCount_" + minval + "-" + maxval + ".txt"; if (Consts.OutputLocalFileLenMax < outFile.Length) { //outFile = "PrimeCount.txt"; outFile = "PrimeCount_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; } //outFile = Path.Combine(ProcMain.SelfDir, outFile); outFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), outFile); outFile = InputFileDlgTools.Save( "Prime4096", "出力ファイルを選択して下さい。", true, outFile, null, "txt" ); if (outFile == null) { throw new Returning(); } bool[] cancelledBox = new bool[1]; this.Visible = false; this.CommonInterlude_INIT(currValue => string.Format("{0} あたりの素数を数えています...", currValue)); WaitDlgTools.Show( "Prime4096", "数えています...", () => Prime4096.WritePrimeCount(minval, maxval, outFile, () => cancelledBox[0] == false), this.CommonInterlude, () => cancelledBox[0] = true ); if (WaitDlg.LastCancelled) { // memo: Prime4096.exe, Prime53.exe は ABORTED 行等を出力しない。 File.WriteAllText( outFile, File.ReadAllText(outFile, Encoding.ASCII).Trim() + "\n中止しました。\nこの出力結果は正しくない可能性があります。", StringTools.ENCODING_SJIS ); MessageDlgTools.Show(MessageDlg.Mode_e.Warning, "Prime4096", "中止しました。\r\n出力ファイルの内容は正しくない可能性があります。"); } else { MessageDlgTools.Information("Prime4096", "完了しました。"); } } catch (Exception ex) { this.CommonCought(ex); } } this.Visible = true; // 復元 }