Example #1
0
        public WriteResCommand(OperationBbs operationBbs)
        {
            Logger.Instance.Debug("WriteResCommand");
            this.operationBbs = operationBbs;

            worker.DoWork += (sender, e) =>
            {
                Logger.Instance.Debug("WriteResCommandWorker.DoWork");
                e.Result = null;

                try
                {
                    WrireResCommandArg arg = e.Argument as WrireResCommandArg;
                    operationBbs.Write(arg.Name, arg.Mail, arg.Message);
                }
                catch (Exception excetpion)
                {
                    Logger.Instance.ErrorFormat("WriteResCommandWorker.DoWork error : Message{0}\n{1}", excetpion.Message, excetpion.StackTrace);
                    e.Result = excetpion;
                }
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                Logger.Instance.Debug("WriteResCommandWorker.RunWorkerCompleted");
                Exception exception = e.Result as Exception;

                if (exception != null)
                {
                    Logger.Instance.DebugFormat("WriteResCommandWorker.RunWorkerCompleted [Message:{0}]", exception.Message);
                    MessageBox.Show(exception.Message);
                }
                else
                {
                    Logger.Instance.DebugFormat("WriteResCommandWorker.RunWorkerCompleted PropertyChanged(Message)");
                    PropertyChanged(this, new PropertyChangedEventArgs("Message"));
                }
            };
        }
Example #2
0
        //-------------------------------------------------------------
        // 概要:コンストラクタ
        // 詳細:イベントの設定
        //-------------------------------------------------------------
        public WriteFieldControl()
        {
            InitializeComponent();

            // 選択スレッドのクリックイベント
            selectThreadLabel.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    // 選択スレッド画面を開く
                    threadSelectView.TopMost = ParentForm.TopMost;
                    threadSelectView.Open();
                }
                else if (e.Button == MouseButtons.Right)
                {
                    RightClick(sender, e);
                }
            };

            // 新着レス表示処理
            string newRes = "";

            showNewResWorker.WorkerSupportsCancellation = true;             // キャンセル処理を許可
            showNewResWorker.DoWork += (sender, e) =>
            {
                newRes = ReadNewRes();
            };
            showNewResWorker.RunWorkerCompleted += (sender, e) =>
            {
                newResToolTip.SetToolTip(selectThreadLabel, newRes);
            };

            // マウスオーバー時に新着レス表示
            selectThreadLabel.MouseHover += (sender, e) =>
            {
                // 新着レス表示の実行
                if (!showNewResWorker.IsBusy)
                {
                    showNewResWorker.RunWorkerAsync();
                }
            };

            // レス書き込み処理
            writeResWorker.WorkerSupportsCancellation = true;
            writeResWorker.DoWork += (sender, e) =>
            {
                string message = writeFieldTextBox.Text;

                WriteResResult result = new WriteResResult();
                result.WriteResult = true;
                result.Message     = message;

                // レス書き込み
                try
                {
                    Logger.Instance.InfoFormat("レス書き込み [掲示板:{0} スレッド:{1}, 本文:{2}]", operationBbs.BbsInfo.BbsName, operationBbs.SelectThread.ThreadTitle, message);

                    operationBbs.Write("", "sage", message);
                    Logger.Instance.InfoFormat("レス書き込み:成功 [掲示板:{0} スレッド:{1}, 本文:{2}]", operationBbs.BbsInfo.BbsName, operationBbs.SelectThread.ThreadTitle, message);
                }
                catch (Exception ex)
                {
                    result.WriteResult = false;
                    result.Exception   = ex;
                    Logger.Instance.ErrorFormat("レス書き込み:失敗 [エラー内容{0} 掲示板:{1} スレッド:{2}, 本文:{3}]", ex.Message, operationBbs.BbsInfo.BbsName, operationBbs.SelectThread.ThreadTitle, message);
                }
                finally
                {
                    e.Result = result;
                }
            };
            // 書き込み完了処理
            writeResWorker.RunWorkerCompleted += (sender, e) =>
            {
                WriteResResult result = (WriteResResult)e.Result;

                // 書き込み欄を有効
                writeFieldTextBox.Enabled       = true;
                writeFieldTextBox.WatermarkText = "書き込み内容を入力してください";

                // 書き込み成功
                if (result.WriteResult)
                {
                    ToastMessage.Show("レス書き込みが完了しました。");
                    writeFieldTextBox.Text = "";
                }
                // 書き込み失敗
                else
                {
                    ToastMessage.Show(string.Format("レス書き込みに失敗しました。[{0}]", result.Exception.Message));
                    writeFieldTextBox.Text = result.Message;
                    Logger.Instance.ErrorFormat("{0}\n\n掲示板:{1}\nスレッド:{2}\n本文:{3}", result.Exception.Message, operationBbs.BbsInfo.BbsName, operationBbs.SelectThread.ThreadTitle, result.Message);
                }

                // 書き込み欄をフォーカス
                writeFieldTextBox.Focus();
            };

            // 書き込みボタン押下
            writeButton.Click += (sender, e) =>
            {
                // レス書き込み
                WriteRes();
            };

            // スレッド変更イベント
            threadSelectView.ThreadChange += (sender, e) =>
            {
                // スレッド情報の更新
                ThreadSelectEventArgs args = (ThreadSelectEventArgs)e;
                operationBbs = args.OperationBbs;
                UpdateThreadTitle();
            };
            // スレッドタイトルの更新
            operationBbs.ThreadListChange += (sender, e) => UpdateThreadTitle();

            // 高さ自動調節
            writeFieldTextBox_TextChanged(this, new EventArgs());

            // 選択スレッドのレス数の更新
            Timer timer = new Timer();

            timer.Interval = UpdateThreadResCount;
            timer.Tick    += (sender, e) =>
            {
                operationBbs.UpdateThreadList();
                UpdateThreadTitle();
            };
            timer.Start();

            // サイズ変更時に高さの自動調節
            SizeChanged += (sender, e) =>
            {
                if (Visible)
                {
                    Height = selectThreadLabel.Height + writeFieldTextBox.PreferredSize.Height;
                }
                else
                {
                    Height = 0;
                }
            };
        }