Exemplo n.º 1
0
        protected virtual void OnLoginSuccess()
        {
            //NotifyIconControl.Instance.notifyIcon.ContextMenu.MenuItems["ExitApp"].Click -= ItemExitClick;
            //NotifyIconControl.Instance.notifyIcon.MouseClick -= OnNotifyIconMouseClick;
            //NotifyIconControl.Instance.notifyIcon.Visible = false;
            //this.LoginSuccessEvent?.Invoke();
            System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();

            System.Windows.Application.Current.Dispatcher.Invoke(() =>
            {
                MainWindowViewModel model = new MainWindowViewModel();
                var result = model.GetGroupList();
                if (!result)
                {
                    loginCount++;
                    //如果尝试3获取数据失败,返回登录页面
                    if (loginCount >= 3)
                    {
                        MessageBoxWindow.Show("尝试多次获取群数据失败,请联系管理员。", GlobalVariable.WarnOrSuccess.Warn);
                        if (IsLoginSuccess)
                        {
                            var errorCode = 0;
                            var errorMsg  = string.Empty;
                            //发送状态
                            AntSdkService.AntSdkUpdateCurrentUserState((int)GlobalVariable.OnLineStatus.OffLine,
                                                                       ref errorCode, ref errorMsg);
                            //停止SDK
                            SDK.AntSdk.AntSdkService.StopAntSdk(ref errorCode, ref errorMsg);
                            AudioChat.ExitClearApi();
                        }
                        System.Windows.Application.Current.Shutdown();
                        CommonMethods.StartApplication(System.Windows.Forms.Application.StartupPath + "/AntennaChat.exe");
                        return;
                    }
                    OnLoginSuccess();
                    return;
                }
                //model.DownloadUserHeadImage();
                MainWindowView mainWindow = new MainWindowView {
                    DataContext = model
                };
                //model.InitMainVM();
                if (this.LoginWindow != null)
                {
                    var loginWindow = LoginWindow as LoginWindowView;
                    loginWindow?.taskbarIcon.Dispose();
                }
                loginCount = 0;
                mainWindow.Show();
                GlobalVariable.LastLoginDatetime = DateTime.Now;
                this.LoginWindow?.Close();
            });
            stopWatch.Stop();
            Antenna.Framework.LogHelper.WriteDebug($"[Model_LoginSuccessEvent({stopWatch.Elapsed.TotalMilliseconds}毫秒)]");
        }