示例#1
0
 private void btnReg_Click(object sender, EventArgs e)
 {
     txbPwd.Enabled   = false;
     txbUsr.Enabled   = false;
     btnLogin.Enabled = false;
     btnReg.Enabled   = false;
     LoadingProgress();
     Dispatcher.BackgroundThread(() =>
     {
         dynamic ret = UAC.Register(txbUsr.Text, txbPwd.Text);
         Loadding    = false;
         Program.Invoke(() =>
         {
             txbPwd.Enabled   = true;
             txbUsr.Enabled   = true;
             btnLogin.Enabled = true;
             btnReg.Enabled   = true;
         });
         if (ret != null)
         {
             if (ret is string)
             {
                 MessageBox.Show(ret);
                 return;
             }
             Program.Repository.Global["username"] = txbUsr.Text;
             Program.Repository.Global["password"] = txbPwd.Text;
             MessageBox.Show("注册成功! 请联系商家进行授权!");
         }
     });
 }
示例#2
0
        static void Main()
        {
            AdbServer.Instance.StartServer(usrDir + @"\bin\adb.exe", true);
            LoadDefaultStorage();
            GlobalSave.Handle("Global", Repository);
            GlobalSave.Handle("Contents", Contents);
            GlobalSave.Handle("Logs", Logs);
            GlobalSetting = new SettingManager();
            GlobalSetting.LoadConfig(CONFIG_FILE);
            GlobalSave.Handle("Settings", GlobalSetting);
            AdbServer.Instance.StartServer(usrDir + @"\bin\adb.exe", false);
            Application.EnableVisualStyles();
            Application.ApplicationExit += Application_ApplicationExit;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += Application_ThreadException;
            Application.SetCompatibleTextRenderingDefault(false);
            //RPCServer = new TcpServer((int)GlobalSetting.Get("RPCPort").Value);
            //RPCServer.DataArrived += RPCServer_DataArrived;
            ScreenPortBase = (int)GlobalSetting.Get("ScreenPortBase").Value;
            MonkeyPortBase = (int)GlobalSetting.Get("ManipulatePortBase").Value;
            // 全局错误处理器
            Events.Register("on_exception", new GlobalEventHandler((_sender, _name, _param) =>
            {
                var ex = _param as Exception;
                checkExcetion(ex);
            }));

            Logs.RegisterEntry("remote");
            // 自动保存设置, 每分钟
            Dispatcher.StartTicking((o) =>
            {
                SaveStorages();
            }, 1000 * 60);
            // free ports
            Repository.Temp["screen"] = new Hashtable();
            for (var i = 0; i < 3000; i++)
            {
                Repository.Temp[ScreenPortBase + i] = true;
                Repository.Temp[MonkeyPortBase + i] = true;
                Repository.Temp[LocationBase + i]   = true;
            }
            if (!UAC.Establish())
            {
                Dispatcher.BackgroundThread(() =>
                                            // 秘钥交换失败
                                            MessageBox.Show("无法与远程服务器取得联系.请稍后再试"));
                Thread.Sleep(3000);
                Process.GetCurrentProcess().Kill();
            }
            // 主题默认字体
            MaterialSkinManager.BaseFont = new System.Drawing.FontFamily("微软雅黑");
            var logFrm = new LoginForm();

            mainFrm = logFrm;
            Application.Run(logFrm);
        }
示例#3
0
 private void Timer_Tick(object sender, EventArgs e)
 {
     Debug.WriteLine("UAC CHECKED");
     if (!UAC.KeepAlive())
     {
         Dispatcher.BackgroundThread(() =>
         {
             Process.GetCurrentProcess().Kill();
         });
     }
 }
示例#4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            txbPwd.Enabled   = false;
            txbUsr.Enabled   = false;
            btnLogin.Enabled = false;
            btnReg.Enabled   = false;
            LoadingProgress();
            Dispatcher.BackgroundThread(() =>
            {
                var ret  = UAC.Login(txbUsr.Text, txbPwd.Text);
                Loadding = false;
                Program.Invoke(() =>
                {
                    txbPwd.Enabled   = true;
                    txbUsr.Enabled   = true;
                    btnLogin.Enabled = true;
                    btnReg.Enabled   = true;
                });

                if (ret != null)
                {
                    var obj = ret as JObject;
                    // 失败了
                    if (ret is string)
                    {
                        MessageBox.Show(ret.ToString());
                        return;
                    }
                    else if (obj["privilege"].ToString() == "0")
                    {
                        MessageBox.Show("您的账号尚未授权, 请联系商家进行授权");
                        return;
                    }
                    else
                    {
                        Program.Repository.Global["username"] = txbUsr.Text;
                        Program.Repository.Global["password"] = txbPwd.Text;

                        // 成功, 并且有权限
                        UAC.Privilege = obj["privilege"].ToString();
                        UAC.Username  = txbUsr.Text;
                        UAC.Password  = txbPwd.Text;

                        Program.Invoke(() =>
                        {
                            this.Hide();
                            new MainForm().ShowDialog();
                            this.Close();
                        });
                    }
                }
            });
        }
示例#5
0
 private static void Application_ApplicationExit(object sender, EventArgs e)
 {
     UAC.Offline();
     SaveStorages();
 }