예제 #1
0
        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);
            }
        }
예제 #2
0
        private void Btn素因数分解_Click(object sender, EventArgs e)
        {
            string text = "";

            using (this.MTBusy.Section())
            {
                try
                {
                    string value = this.T素因数分解_入力.Text;

                    if (value == "")
                    {
                        throw new Exception("未入力です。");
                    }

                    if (StringTools.LiteValidate(value, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("[0-9] 以外の文字が含まれています。");
                    }

                    if (
                        Ground.TCalc_Int.Calc(value, "-", "1")[0] == '-' ||
                        Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", value)[0] == '-'
                        )
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("1 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    bool[] cancelledBox = new bool[1];

                    this.Visible = false;
                    this.CommonInterlude_INIT(currValue => string.Format("素因数分解しています... {0}", currValue));

                    WaitDlgTools.Show(
                        "Prime4096",
                        "素因数分解しています...",
                        () => text = string.Join("\r\n", Prime4096.Factorization(value, () => cancelledBox[0] == false)),
                        this.CommonInterlude,
                        () => cancelledBox[0] = true
                        );

                    if (WaitDlg.LastCancelled)
                    {
                        //text += "\r\n中止しました。この出力結果は正しくない可能性があります。"; // old

                        text =
                            "中止しました。\r\n" +
                            "この出力結果は正しくない可能性があります。\r\n" +
                            text;
                    }
                }
                catch (Exception ex)
                {
                    this.CommonCought(ex);
                }
            }
            this.Visible = true;             // 復元

            this.T素因数分解_結果.Text = text;
            //this.T素因数分解_結果.SelectionStart = this.T素因数分解_結果.TextLength;
            //this.T素因数分解_結果.ScrollToCaret();
        }
예제 #3
0
        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;             // 復元
        }
예제 #4
0
        private void Btn探索_Click(object sender, EventArgs e)
        {
            string text = "";

            using (this.MTBusy.Section())
            {
                try
                {
                    string value = this.T探索_入力.Text;

                    if (value == "")
                    {
                        throw new Exception("未入力です。");
                    }

                    if (StringTools.LiteValidate(value, StringTools.DECIMAL) == false)
                    {
                        throw new Exception("[0-9] 以外の文字が含まれています。");
                    }

                    if (Ground.TCalc_Int.Calc(Consts.S2P4096_1, "-", value)[0] == '-')
                    {
                        throw new LongMessageException(Utils.AutoInsertNewLine("0 以上 " + Consts.S2P4096_1 + " 以下の整数を入力して下さい。", Consts.MaxLineLen_LongMessageDlg));
                    }

                    bool[] cancelledBox = new bool[1];

                    this.Visible = false;
                    this.CommonInterlude_INIT();

                    WaitDlgTools.Show(
                        "Prime4096",
                        "最寄りの素数を探しています...",
                        () =>
                    {
                        //WaitDlg.MessagePost.Post("最寄りの素数を探しています... (小さい方)");
                        this.WD_ProgressRate = 0.333;
                        string lowerPrime    = Prime4096.GetLowerPrime(value, () => cancelledBox[0] == false);
                        //WaitDlg.MessagePost.Post("最寄りの素数を探しています... (大きい方)");
                        this.WD_ProgressRate = 0.666;
                        string higherPrime   = Prime4096.GetHigherPrime(value, () => cancelledBox[0] == false);

                        if (lowerPrime == "0")
                        {
                            lowerPrime = "none";
                        }

                        text = string.Join("\r\n",
                                           "元の数より小さい最大の素数 ---->",
                                           lowerPrime,
                                           "",
                                           "元の数より大きい最小の素数 ---->",
                                           higherPrime,
                                           "",
                                           "元の数 ---->",
                                           value
                                           );
                    },
                        this.CommonInterlude,
                        () => cancelledBox[0] = true
                        );

                    if (WaitDlg.LastCancelled)
                    {
                        text = "中止しました。";
                    }
                }
                catch (Exception ex)
                {
                    this.CommonCought(ex);
                }
            }
            this.Visible = true;             // 復元

            this.T探索_結果.Text = text;
            //this.T探索_結果.SelectionStart = this.T探索_結果.TextLength;
            //this.T探索_結果.ScrollToCaret();
        }