private void VerifyCodeBox1_VerifyCodeLoadFailed(object sender, EventArgs e)
        {
            var ar = AutoResumeRefreshConfiguration.Instance;

            if (!ar.AutoReloadVc)
            {
                return;
            }

            pReload.Visible       = true;
            var(isOpen, nextTime) = ParamData.GetSystemMaintenanceTime();
            nextTime = Math.Max(nextTime, ar.AutoReloadVcTime);
            var toTime = DateTime.Now.AddMilliseconds(nextTime);

            lblReloadTip.Text = $"{Utility.ShowMilliSecondInfo(nextTime)} 自动刷新{(isOpen ? "" : "(等待开放)")}";
            _cancellationTokenSource?.Cancel(false);
            _cancellationTokenSource = new CancellationTokenSource();

            async void WaitAutoReloadAsync(CancellationToken token)
            {
                try
                {
                    while (DateTime.Now < toTime)
                    {
                        lblReloadTip.Text = $"{Utility.ShowMilliSecondInfo((int)(toTime - DateTime.Now).TotalMilliseconds)} 自动刷新";
                        await Task.Delay(100, token).ConfigureAwait(true);

                        if (token.IsCancellationRequested || IsDisposed || Form.IsDisposed)
                        {
                            return;
                        }
                    }
                    if (token.IsCancellationRequested || IsDisposed || Form.IsDisposed)
                    {
                        return;
                    }
                    LoadVerifyCode();
                }
                catch (Exception)
                {
                    return;
                }
                finally
                {
                    _cancellationTokenSource?.Cancel(false);

                    _cancellationTokenSource = null;
                    pReload.Visible          = false;
                }
            }

            WaitAutoReloadAsync(_cancellationTokenSource.Token);
        }
예제 #2
0
        /// <summary>
        ///     加载事件,初始化界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MainForm_Load(object sender, EventArgs e)
        {
            InitializeUI();
            InitializeEvents();
            InitServerTime();
            InitBackgroundTask();

            //自动恢复会话
            if (RunTime.SessionManager.Count > 0)
            {
                //tabUser.TabPages.AddRange(RunTime.SessionManager.Select(s => (TabPage)new UserTab(s)).ToArray());
                if (ProgramConfiguration.Instance.EnablePromotion == null)
                {
                    using (InitializingUserPage.Show(this))
                    {
                        RunTime.SessionManager.ForEach(s =>
                        {
                            HandleSession(s);
                            new UserTabDnb(s, st);
                        });
                    }
                }
                else
                {
                    st.SelectedTab = RunTime.SessionManager.Select(s => new UserTabDnb(s, st)).Last();
                }

                RunTime.SessionManager.Where(s => !s.UserProfile.IsPassengerLoaded).ForEach(s => s.AccquireLoadPassengers());
            }

            //在系统关闭时间,自动打开查询页
            var(isOpen, _) = ParamData.GetSystemMaintenanceTime();
            if (!isOpen)
            {
                OpenQueryPageWithoutLogin();
            }
        }
예제 #3
0
        void HandleGlobalEvents()
        {
            Session.UserLogined += (s, e) =>
            {
                var session = (Session)s;
                //var tab = new UserTab(session);
                //tabUser.TabPages.Add(tab);
                //tabUser.SelectedTab = tab;

                //提示信息。
                if (!session.LoginNotification.IsNullOrEmpty() && ProgramConfiguration.Instance.ShowMessageFrom12306)
                {
                    new MsgFrom12306(session.LoginNotification).ShowDialog(this);
                    session.LoginNotification = null;
                }

                using (InitializingUserPage.Show(this))
                {
                    st.SelectedTab = new UserTabDnb(session, st);
                }
                if (session.UserProfile.Passengers == null || session.UserProfile.Passengers.Any(x => x.TotalTimes == 0))
                {
                    session.AccquireLoadPassengers();
                }
                HandleSession(session);
            };
            Session.UserVerificationStateChanged += (s, e) =>
            {
                var session = s as Session;
                if (session.IsUserVerified == false)
                {
                    this.Invoke(() => new UserNotVerified()
                    {
                        Session = session
                    }.ShowDialog());
                }
            };
            Session.MobileCheckStateChanged += (s, e) =>
            {
                var session = s as Session;
                if (session.IsMobileChecked == false)
                {
                    this.BeginInvoke(new Action(() =>
                    {
                        var tip = new MobileNotChecked(session);
                        if (tip.ShowDialog(this) == DialogResult.Yes)
                        {
                            new AccountMobileCheck(session).ShowDialog(this);
                        }
                    }));
                }
            };
            Session.Logout += (s, e) => this.Invoke(() =>
            {
                var session = s as Session;
                st.Tabs.OfType <UserTabDnb>().FirstOrDefault(x => x.Session == session)?.Remove();
                GC.Collect();
            });
            Session.ForceLogout += this.SafeInvoke(new EventHandler <GeneralEventArgs <bool> >((s, e) =>
            {
                var session = (Session)s;
                if (session == null)
                {
                    return;
                }

                //撤消改签
                session.UserProfile.QueryParams.Where(x => x.Resign).ToArray().ForEach(x => x.IsLoaded = false);

                ni.ShowBalloonTip(5000, "账户已被踢", "账户【" + session.UserKeyData?.DisplayName + "】:您已被踢。如果需要继续订票,请重新登录。", ToolTipIcon.Warning);

                var(isOpen, _) = ParamData.GetSystemMaintenanceTime();
                if (MediaConfiguration.Instance.EnableForceLogoutAudioPrompt && isOpen)
                {
                    LosingSoundPlayer.Instance.PlayAsync();
                }
            }));
            //Session.MayNeedRelogin += (s, e) =>
            //{
            //	var session = s as Session;
            //	if (session == null)
            //		return;

            //	e.Canceled = this.Invoke<Session, bool, bool>(CheckNeedRelogin, session, e.Data);
            //};
            //Session.LoginConflict += (s, e) =>
            //{
            //	this.Invoke(() =>
            //	{
            //		if (!ProgramConfiguration.Instance.DismissedDialogs.Contains("login_confliect"))
            //		{
            //			new LoginConflict().ShowDialog(this);
            //		}
            //	});
            //};
            Session.PreInputedVcMissed += (s, e) =>
            {
                var session = s as Session;
#if DEBUG
                ni.ShowBalloonTip(3000, "验证码已失效", string.Format("账户【{0}】提前输入的验证码已经失效,历时 {1} 分钟", session.UserName, (DateTime.Now - session.LastVerifyCodeInputTime.Value).TotalMinutes.ToString("#0.00")), ToolTipIcon.Warning);
#else
                ni.ShowBalloonTip(2000, "验证码已失效", string.Format("账户【{0}】提前输入的验证码已经失效", session.UserName), ToolTipIcon.Warning);
#endif
            };
            Session.OrderSubmitSuccess += (s, e) =>
            {
            };
            ControllerSession.NotificationCreated += (s, e) => UiInvoke(() =>
            {
                ShowBalloonTip(1500, "订单自动操作通知", e.Data, ToolTipIcon.Warning);
            });
        }
예제 #4
0
        void InitializeEvents()
        {
            st.TabItemClose += (s, e) =>
            {
                var tab = e.Tab as UserTabDnb;
                if (tab != null)
                {
                    e.Cancel = !MessageDialog.Question("确定要把放出来的账号【" + tab.Session.UserKeyData.DisplayName + "】残忍地关回小黑屋里?", true);
                    if (!e.Cancel)
                    {
                        Session.OnLogout(tab.Session, LogoutReason.UserManually);
                        e.Cancel = true;
                    }
                }
                else if (e.Tab is SuperTabItem)
                {
                    st.Tabs.Remove(e.Tab);
                    st.Controls.Remove((e.Tab as SuperTabItem).AttachedControl);
                    st.SelectedTabIndex = 0;
                }
            };

            //状态统计
            stuStatistics.DropDownOpening += (s, e) =>
            {
                UpdateStatistics();
            };
            stuStatisticsQuery.DropDownOpening += (s, e) => UpdateQueryStatistics();

            Shown += (s, e) =>
            {
                var(isOpen, _) = ParamData.GetSystemMaintenanceTime();

                if (ProgramConfiguration.Instance.AutoShowLoginDialog && isOpen && !st.Tabs.OfType <UserTabDnb>().Any())
                {
                    Login();
                }
            };

            //IP被封
            var lastIpBlockTipTime = (DateTime?)null;

            TOBA.Events.IpBlocked += this.SafeInvoke((s, e) =>
            {
                if (!ProgramConfiguration.Instance.ShowIPBlockTip)
                {
                    return;
                }
                if (lastIpBlockTipTime != null && (DateTime.Now - lastIpBlockTipTime.Value).TotalMinutes <= 1)
                {
                    return;
                }

                lastIpBlockTipTime = DateTime.Now;
                DesktopAlert.Show(
                    "<b>检测到您的IP已经被12306封锁。</b>\n请重启路由器(拨号上网)\n或使用代理服务器(固定IP或局域网)。\n可能是其他人过于频繁刷票导致此问题的,揍丫的。",
                    Properties.Resources.cou_32_warning,
                    eDesktopAlertColor.Red,
                    eAlertPosition.BottomRight,
                    30,
                    1L,
                    _ =>
                {
                    var dlg    = new UI.Dialogs.ConfigCenter();
                    dlg.Shown += (ss, ee) =>
                    {
                        dlg.SelectedConfig = dlg.FindConfigUI <UI.Controls.Option.NetworkConfig>().First();
                    };

                    dlg.ShowDialog();
                }
                    );
            });
        }