Ejemplo n.º 1
0
        /// <summary>
        /// 未処理例外をキャッチするイベント・ハンドラ
        /// </summary>
        /// <remarks>
        /// メイン・スレッド以外の例外はUnhandledExceptionでハンドル
        /// </remarks>
        public static void Application_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;

            if (ex != null)
            {
                RcMyCmnFunction.ShowErrorMessageWin(ex, "Application_UnhandledExceptionによる例外通知です。");
            }
        }
Ejemplo n.º 2
0
        // .NET TIPS > 適切に処理されなかった例外をキャッチするには?
        // http://www.atmarkit.co.jp/fdotnet/dotnettips/320appexception/appexception.html

        /// <summary>
        /// 未処理例外をキャッチするイベント・ハンドラ
        /// </summary>
        public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            RcMyCmnFunction.ShowErrorMessageWin(e.Exception, "Application_ThreadExceptionによる例外通知です。");
        }
Ejemplo n.º 3
0
        /// <summary>参照処理</summary>
        /// <param name="rcFxEventArgs">イベントハンドラの共通引数</param>
        /// <remarks>
        /// 非同期フレームワークを使用してB層の呼び出し処理を非同期化
        /// (結果表示にだけ匿名デリゲードを使用するパターン)
        /// </remarks>
        protected void UOC_btnButton6_Click(RcFxEventArgs rcFxEventArgs)
        {
            // 非同期処理クラスを生成
            AsyncFunc af = new AsyncFunc(this);

            // 引数クラスを生成
            // 下位(B・D層)は、テスト クラスを流用する
            TestParameterValue testParameterValue
                = new TestParameterValue(
                      this.Name, rcFxEventArgs.ControlName, "Select",
                      ((ComboBoxItem)this.ddlDap.SelectedItem).Value + "%"
                      + ((ComboBoxItem)this.ddlMode1.SelectedItem).Value + "%"
                      + ((ComboBoxItem)this.ddlMode2.SelectedItem).Value + "%"
                      + ((ComboBoxItem)this.ddlExRollback.SelectedItem).Value,
                      MyBaseControllerWin.UserInfo);

            // 情報の設定
            testParameterValue.ShipperID = int.Parse(this.textBox1.Text);

            // 引数を非同期処理クラスに設定
            af.Parameter = testParameterValue;

            // 画面上のデータは退避する(オブジェクトであれば、クローンする。)
            af.LogicalName = ((ComboBoxItem)this.ddlTransmission.SelectedItem).Value;

            // 非同期実行するメソッドを指定
            // ここは副スレッドから実行されるので注意。
            af.AsyncFunc = new BaseAsyncFunc.AsyncFuncDelegate(af.btn6_Exec);

            // 結果表示のメソッドを指定(匿名デリゲード)
            // このメソッドは必ず主スレッドで実行される。
            af.SetResult = delegate(object retVal)
            {
                if (retVal is Exception)
                {
                    // 例外発生時
                    RcMyCmnFunction.ShowErrorMessageWin((Exception)retVal, "非同期処理で例外発生!");
                }
                else
                {
                    // 正常時

                    // 戻り値(キャスト)
                    TestReturnValue testReturnValue = (TestReturnValue)retVal;
                    // 結果表示するメッセージ エリア
                    this.labelMessage.Text = "";

                    if (testReturnValue.ErrorFlag == true)
                    {
                        // 結果(業務続行可能なエラー)
                        this.labelMessage.Text  = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n";
                        this.labelMessage.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n";
                        this.labelMessage.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n";
                    }
                    else
                    {
                        // 結果(正常系)
                        this.textBox1.Text = testReturnValue.ShipperID.ToString();
                        this.textBox2.Text = testReturnValue.CompanyName;
                        this.textBox3.Text = testReturnValue.Phone;
                    }
                }
            };

            // 非同期実行する。
            if (!af.Start())
            {
                MessageBox.Show("別の非同期処理が実行中です。");
            }
        }
Ejemplo n.º 4
0
        /// <summary>件数取得</summary>
        /// <param name="rcFxEventArgs">イベントハンドラの共通引数</param>
        /// <remarks>
        /// 非同期フレームワークを使用してB層の呼び出し処理を非同期化
        /// (非同期実行、結果表示の双方に匿名デリゲードを使用するパターン)
        /// </remarks>
        protected void UOC_btnButton1_Click(RcFxEventArgs rcFxEventArgs)
        {
            // ↓カバレージ上げ

            //// Web認証情報
            //this.CallCtrl.NetworkCredentialToWAS
            //    = new NetworkCredential("test", "test", "test");

            //// プロキシ(認証)情報
            //this.CallCtrl.ProxyUrl = "http://xxx.xxx.xxx.xxx:8080";
            //this.CallCtrl.NetworkCredentialToProxy
            //    = new NetworkCredential("ptest", "ptest", "ptest");

            // 非同期処理クラスを生成
            // 匿名デリゲードの場合は、ベース2で良い。
            MyBaseAsyncFunc af = new MyBaseAsyncFunc(this);

            // 引数を纏める
            af.Parameter = (object)new TestParameterValue(
                this.Name, rcFxEventArgs.ControlName, "SelectCount",
                ((ComboBoxItem)this.ddlDap.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode1.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlMode2.SelectedItem).Value + "%"
                + ((ComboBoxItem)this.ddlExRollback.SelectedItem).Value,
                MyBaseControllerWin.UserInfo);

            // 画面上のデータは退避する
            //(オブジェクトであれば、クローンする。)
            string logicalName = ((ComboBoxItem)this.ddlTransmission.SelectedItem).Value;

            // 非同期実行するメソッドを指定(匿名デリゲード)
            // ここは副スレッドから実行されるので注意
            // (画面上のメンバに触らないこと!)。
            af.AsyncFunc = delegate(object param)
            {
                // 引数クラス(キャスト)
                TestParameterValue testParameterValue = (TestParameterValue)param;

                // 戻り値
                TestReturnValue testReturnValue;

                // 呼出し制御部品(スレッドセーフでないため副スレッド内で作る)
                CallController callCtrl = new CallController(Program.AccessToken);

                // Invoke
                testReturnValue = (TestReturnValue)callCtrl.Invoke(
                    logicalName, testParameterValue);

                //// 進捗表示のテスト
                //af.ChangeProgress = delegate(object o)
                //{
                //    MessageBox.Show(o.ToString());
                //};

                //af.ExecChangeProgress("進捗表示");

                //// 非同期メッセージボックス表示のテスト
                //DialogResult dr = af.ShowAsyncMessageBoxWin(
                //    "メッセージ", "タイトル", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                ////// 非同期メッセージボックス表示のテスト(エラー)
                ////System.Windows.MessageBoxResult mr = af.ShowAsyncMessageBoxWPF("メッセージ", "タイトル",
                ////    System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Information);

                // 結果表示
                return(testReturnValue);
            };

            // 結果表示のメソッドを指定(匿名デリゲード)
            // このメソッドは必ず主スレッドで実行される。
            // (画面上のメンバを更新できる!)。
            af.SetResult = delegate(object retVal)
            {
                if (retVal is Exception)
                {
                    // 例外発生時
                    RcMyCmnFunction.ShowErrorMessageWin((Exception)retVal, "非同期処理で例外発生!");
                }
                else
                {
                    // 正常時

                    // 戻り値(キャスト)
                    TestReturnValue testReturnValue = (TestReturnValue)retVal;

                    // 結果表示するメッセージ エリア
                    this.labelMessage.Text = "";

                    if (testReturnValue.ErrorFlag == true)
                    {
                        // 結果(業務続行可能なエラー)
                        this.labelMessage.Text  = "ErrorMessageID:" + testReturnValue.ErrorMessageID + "\r\n";
                        this.labelMessage.Text += "ErrorMessage:" + testReturnValue.ErrorMessage + "\r\n";
                        this.labelMessage.Text += "ErrorInfo:" + testReturnValue.ErrorInfo + "\r\n";
                    }
                    else
                    {
                        // 結果(正常系)
                        this.labelMessage.Text = testReturnValue.Obj.ToString() + "件のデータがあります";
                    }
                }
            };

            // 非同期実行する。
            if (!af.Start())
            {
                MessageBox.Show("別の非同期処理が実行中です。");
            }
        }