private void reloadUI()
        {
            if (null == messagehubClient)
            {
                messagehubClient                       = new MessageHubClient(textBoxMessageHubUrl.Text, textBoxapiAddress.Text, textBoxLaneCode.Text);
                tabMain.Enabled                        = true;
                button1.Enabled                        = true;
                textLaneSend.Enabled                   = true;
                messagehubClient.reciveMessage        += MessagehubClient_reciveMessage;
                messagehubClient.reciveStatus         += MessagehubClient_reciveStatus;
                messagehubClient.reciveHubError       += MessagehubClient_reciveHubError;
                messagehubClient.reciveP2pMessage     += MessagehubClient_reciveP2pMessage;
                commandExecutor.commandExecutorResult += CommandExecutor_commandExecutorResult;//指令处理器回调
                messagehubClient.HubInit();
                buttonConnectMessageHub.Text = "取消监听";

                textLanePoolName.Enabled     = false;
                textBoxLaneCode.Enabled      = false;
                textBoxapiAddress.Enabled    = false;
                textBoxMessageHubUrl.Enabled = false;
                textJobQueuePoolName.Enabled = false;
                textLanePoolName.Enabled     = false;
                textBoxlaneName.Enabled      = false;
                textBox1.Enabled             = false;
            }

            else if (buttonConnectMessageHub.Text == "取消监听")
            {
                JobQueueTree.Nodes.Clear();
                treeLane.Nodes.Clear();
                //button1.Enabled = false;
                textLaneSend.Enabled = false;
                tabMain.Enabled      = false;
                messagehubClient.Dispose();
                messagehubClient          = null;
                textBoxLaneNodeInfo.Text  = "";
                textBoxQueueNodeInfo.Text = "";
                richTextBox1.Clear();
                comboBox1.Items.Clear();
                comboBox1.Text = "";
                buttonConnectMessageHub.Text = "注册监听";
                textLanePoolName.Enabled     = true;
                textBoxLaneCode.Enabled      = true;
                textBoxapiAddress.Enabled    = true;
                textBoxMessageHubUrl.Enabled = true;
                textJobQueuePoolName.Enabled = true;
                textLanePoolName.Enabled     = true;
                textBoxlaneName.Enabled      = true;
                textBox1.Enabled             = true;
            }
        }
        /// <summary>
        /// Creates and connects the hub connection and hub proxy. This method
        /// is called asynchronously from SignInButton_Click.
        /// </summary>
        private async void ConnectAsync()
        {
            if (Connection != null)
            {
                Connection = null;
            }
            Connection = new HubConnection(Server);
            var asm = this.GetType().Assembly.GetName();
            Connection.Headers["x-name"] = asm.Name;
            Connection.Headers["x-version"] = asm.Version.ToString();
            Connection.Headers["x-creation-time"] = new System.IO.FileInfo(Application.ExecutablePath).CreationTime.ToString();
            Connection.Headers["x-os-version"] = Environment.OSVersion.VersionString + "(" + Environment.OSVersion.Platform.ToString() + ")";
            Connection.Headers["x-ie-version"] = wb.Version.ToString();
            Connection.Headers["x-runtime-version"] = Environment.Version.ToString();
            Connection.Error += Connection_Error;
            Connection.Closed += Connection_Closed;
            Connection.Reconnecting += Connection_Reconnecting;
            Connection.Reconnected += Connection_Reconnected;
            Connection.StateChanged += Connection_StateChanged;
            Connection.CookieContainer = new System.Net.CookieContainer();
            var cookie = IECookieHelper.GetGlobalCookie(Server, ".AspNet.ApplicationCookie");
            Connection.CookieContainer.SetCookies(new Uri(Server), ".AspNet.ApplicationCookie=" + cookie);
            client = new MessageHubClient(Connection);

            //常规事件处理
            client.ItemHub.ItemAdd += ItemHub_ItemAdd;
            client.ItemHub.ItemDelete += ItemHub_ItemDelete;
            client.ItemHub.ItemDownshelf += ItemHub_ItemDownshelf;
            client.ItemHub.ItemStockChanged += ItemHub_ItemStockChanged;
            client.ItemHub.ItemUpdate += ItemHub_ItemUpdate;
            client.ItemHub.ItemUpshelf += ItemHub_ItemUpshelf;
            client.ItemHub.ItemZeroStock += ItemHub_ItemZeroStock;

            client.RefundHub.RefundBlockMessage += RefundHub_RefundBlockMessage;
            client.RefundHub.RefundBuyerModifyAgreement += RefundHub_RefundBuyerModifyAgreement;
            client.RefundHub.RefundBuyerReturnGoods += RefundHub_RefundBuyerReturnGoods;
            client.RefundHub.RefundClosed += RefundHub_RefundClosed;
            client.RefundHub.RefundCreated += RefundHub_RefundCreated;
            client.RefundHub.RefundCreateMessage += RefundHub_RefundCreateMessage;
            client.RefundHub.RefundSellerAgreeAgreement += RefundHub_RefundSellerAgreeAgreement;
            client.RefundHub.RefundSellerRefuseAgreement += RefundHub_RefundSellerRefuseAgreement;
            client.RefundHub.RefundSuccess += RefundHub_RefundSuccess;
            client.RefundHub.RefundTimeoutRemind += RefundHub_RefundTimeoutRemind;

            client.TradeHub.TradeBuyerPay += TradeHub_TradeBuyerPay;
            client.TradeHub.TradeClose += TradeHub_TradeClose;
            client.TradeHub.TradeCreate += TradeHub_TradeCreate;

            client.onMessage += (message) => { AppendText(String.Format("{0}: {1}" + Environment.NewLine, "[服务端信息]", message)); };
            client.onTmcState += (state) => { AppendText(String.Format("{0}: {1}" + Environment.NewLine, "交易监控", state)); };
            try
            {
                if (!GetServerTime())
                {
                    MessageBox.Show("网络错误!");
                    ExitConfirmed = true;
                    this.Close();
                    return;
                }
                this.InvokeAction(() =>
                {
                    //登录完成后导航到这个页面,方便后面AJAX直接使用这个浏览器取数据
                    this.InvokeAction(wb.Navigate, "http://chongzhi.taobao.com/index.do?spm=0.0.0.0.OR0khk&method=index");
                });
                try
                {
                    await Connection.Start();
                }
                catch
                {
                    AppendText("尝试连接失败,10s后重试...");
                    await Task.Delay(1000 * 10);
                    ConnectAsync();
                    return;
                }
                this.tssl_ConnState.Text = "连接状态:" + ConnectionState.Connected.AsZhConnectionState();
                IsLogin = true;
                var userInfo = await this.InvokeTask(client.UserInfo);
                var userName = (string)userInfo.UserName;
                AppDatabase.Initialize(userName);
                AppSetting.InitializeUserSetting(userName, AppDatabase.db.Database);
                LoadUserSetting();
                SetupTaskbarIcon();
                AppDatabase.db.Statistics.Delete(userName);
                AppDatabase.db.Statistics.Insert(new Statistic { Id = userName });
                var statistic = AppDatabase.db.Statistics.FindById(userName);
                OnStatisticUpdate(statistic);
                this.InvokeAction(() =>
                {
                    this.Text = title + " [" + asm.Version + "] 授权给:" + userName +
                    " 过期时间:" + userInfo.LicenseExpires;
                });
                if (userInfo.LicenseExpires == null)
                {
                    MessageBox.Show("软件授权无效,疑问、咨询或购买请联系客服");
                    this.Close();
                    return;
                }
                if (DateTime.Now > (DateTime)userInfo.LicenseExpires)
                {
                    MessageBox.Show("软件授权过期,疑问或续期请联系客服");
                    this.Close();
                    return;
                }
                //this.InvokeAction(() =>
                //{
                //    wbMain.ScriptErrorsSuppressed = true;
                //    WBHelper.wbQueue.Enqueue(wbMain);
                //});
                var taoInfo = await this.InvokeTask(GetTaoInfo);
                if (taoInfo.status == 200)
                {
                    AppSetting.UserSetting.Set("TaoInfo", taoInfo);
                    ResetProductStates();
                    BindDGViewProduct();
                    BindDGViewTBOrder();
                    var permit = await this.InvokeTask(client.TmcGroupAddThenTmcUserPermit);
                    var permitSuccess = permit.Success;
                    this.AppendText("消息授权{0}", permitSuccess ? "成功" : "失败,错误消息:" + permit.Message);
                    if (permitSuccess)
                    {
                        this.InvokeAction(() =>
                        {
                            tabControl1.Enabled = true;
                        });
                    }
                    else
                    {
                        MessageBox.Show("消息授权失败,请联系客服。");
                        this.ExitConfirmed = true;
                        this.Close();
                        return;
                    }
                    SyncBackground();
                }
                else
                {
                    AppendText("网络错误!");
                }
            }
            catch (Exception ex)
            {
                AppendException(ex);
            }
        }