예제 #1
0
        async private Task<bool> TestConnExec()
        {
            SystemMenagerService.SystemManagerServiceClient sm = new SystemMenagerService.SystemManagerServiceClient();
            LogService.LogServiceClient lv = new LogService.LogServiceClient();
            InfoManagerService.InfoManagerServiceClient im = new InfoManagerService.InfoManagerServiceClient();

            bool testConnRet = false;
            string lToken = System.Configuration.ConfigurationManager.AppSettings["localToken"];
            try
            {
                var ran = new System.Random();
                var token = ran.Next(int.MaxValue).ToString();

                sm.Open();
                Task<int> testsm = sm.TestConnAsync(token);
                lv.Open();
                Task<int> testLv = lv.TestConnAsync(token);
                im.Open();
                Task<int> testIm = im.TestConnAsync(token);

                int smRet = await testsm;
                int imRet = await testIm;
                int lvRet = await testLv;

                testConnRet = (smRet == (token+lToken).GetHashCode()) || (smRet == imRet) || (smRet == lvRet);
            }
            catch (System.Exception)
            {
                this.IsChecking = false;
                Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("fail"), "connFail");
                return false;
            }

            finally
            {
                sm.Close();
                lv.Close();
                im.Close();
            }
            this.IsChecking = false;
            if (testConnRet)
                Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("success"), "loginSuccess");
            else
                Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("fail"), "connFail");
            this.Title = "登录";
            return true;
        }
 private void UpdateExec()
 {
     SystemMenagerService.SystemManagerServiceClient client = new SystemMenagerService.SystemManagerServiceClient();
     try
     {
         client.Open();
         var ret = client.ChangePwd(MainViewModel.NowUser.id,
             this.Password == null ? null : this.Password.GetHashCode().ToString(),
             this.NewPasswordAg == null ? null : this.NewPasswordAg.GetHashCode().ToString());
         if (ret == 1|| ret ==0)
         {
             Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("Success"), "ChangePasswordMsg");
             return;
         }
         else if (ret == -1)
         {
             Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("密码输入错误"), "ChangePasswordMsg");
         }
         else
             Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("密码修改失败"), "ChangePasswordMsg");
     }
     catch (System.Exception ex)
     {
         Messenger.Default.Send<GenericMessage<System.Exception>>(new GenericMessage<System.Exception>(ex), "ChangePasswordError");
     }
     finally
     {
         client.Close();
     }
 }
예제 #3
0
        public void LonginExec()
        {
            //            Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(""), "start");
            //Messenger.Default.Send<NotificationMessageAction<MahApps.Metro.Controls.ProgressRing>>(
            //    new NotificationMessageAction<MahApps.Metro.Controls.ProgressRing>("start",
            //        res => res.IsActive = true));
            // System.Threading.Thread.Sleep(5000);
            Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("update text of textbox "), "update");

            if (string.IsNullOrEmpty(this.UserName))//用户名验证
            {
                Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("用户名不能为空!"), "errorUserName");
                this._isLogin = false;
            }

            if (!string.IsNullOrEmpty(this.Password))
            {
                this.Password = Password.GetHashCode().ToString();
            }
            else
            {
                this.Password = null;
            }
            SystemMenagerService.SystemManagerServiceClient smService =
                new SystemMenagerService.SystemManagerServiceClient();
            try
            {
                smService.Open();
                var user = smService.Login(this.UserName, this.Password, System.Net.Dns.GetHostName());

                if (user != null)//登录成功
                {
                    // Debug
                    // System.Windows.MessageBox.Show("Login seuccess!");

                    Messenger.Default.Send<GenericMessage<SystemMenagerService.LoginUser>>(new GenericMessage<SystemMenagerService.LoginUser>(user), "success");
                }
                else
                {
                    Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("账户或者密码错误!"), "errorUser");
                }
            }
            catch (System.Exception ex)
            {
                if (ex.Message.Contains("NotFindUsetException"))
                {
                    Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("账户或者密码错误!"), "errorUser");
                }
                else
                {
                    Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("登录错误,请联系管理员!\r\n错误描述: " + ex.Message), "systemError");
                }
            }
            finally
            {
                smService.Close();
                Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("Finish login"), "finish");
            }

            #region Debug
            //System.Threading.Thread.Sleep(2000);
            //if (this.UserName == "admin")
            //    Messenger.Default.Send<GenericMessage<SystemMenagerService.LoginUser>>(new GenericMessage<SystemMenagerService.LoginUser>(new LoginUser { RealName = "success" }), "success");
            //else
            //    Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>("账户或者密码错误!"), "errorUser");
            //Messenger.Default.Send<GenericMessage<string>>(new GenericMessage<string>(""), "finish");
            #endregion
            IsRunning = false;
            this.Title = "登录";
            return;
        }