コード例 #1
0
 private void btnLogin_Click(object sender, RoutedEventArgs e)
 {
     btnLogin.IsEnabled = false;
     try
     {
         LoginRequestModel loginModel = new LoginRequestModel();
         loginModel.UserName   = txtUserName.Text.Trim();
         loginModel.Password   = txtPwd.Password;
         loginModel.MacAddress = MacHelper.GetLocalMac();
         var result = proxyServer.Login(loginModel);
         if (result.Status == 1)
         {
             CurrentData.Instance.UserName = loginModel.UserName;
             CurrentData.Instance.Token    = new TokenRequestModel()
             {
                 Token = result.Token
             };
             DialogResult = true;
         }
         else
         {
             var info = result.Message ?? "登录失败!";
             ShowError(info);
             txtUserName.Focus();
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         ShowError(ex.Message);
     }
     btnLogin.IsEnabled = true;
 }
コード例 #2
0
        void App_Startup(object sender, StartupEventArgs e)
        {
            //if the client is run, then close the new client application
            //Process process = Process.GetCurrentProcess();
            //foreach (Process p in Process.GetProcessesByName(process.ProcessName))
            //{
            //    if (p.Id != process.Id)
            //    {
            //        Shutdown();
            //        return;
            //    }
            //}

            Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomain_UnhandledException;
            try
            {
                ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
                //check mac address
                var errMsg  = "地址验证失败,非法访问!";
                var macAddr = MacHelper.GetLocalMac();
                if (string.IsNullOrEmpty(macAddr))
                {
                    MessageBox.Show(errMsg);
                    this.Shutdown();
                    return;
                }
                IProxy proxyServer = CurrentData.Instance.ProxyServer;
                var    result      = proxyServer.ValidateAddress(new AddressRequestModel()
                {
                    MacAddress = macAddr
                });
                if (result.Status != 1)
                {
                    var info = result.Message ?? errMsg;
                    MessageBox.Show(info);
                    this.Shutdown();
                    return;
                }

                LoginWindow loginWin = new LoginWindow();
                loginWin.ShowDialog();
                if (!loginWin.DialogResult.Value)
                {
                    this.Shutdown();
                    return;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
                this.Shutdown();
            }
        }