コード例 #1
0
        private void BtnLogin_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Vm.ServerHost))
            {
                Vm.ShowMessage("服务器地址不能为空");
                return;
            }
            string passwordSha1 = HashUtil.Sha1(Vm.Password);

            NTMinerRegistry.SetControlCenterHost(Vm.ServerHost);
            var list = NTMinerRegistry.GetControlCenterHosts();

            if (!list.Contains(Vm.ServerHost))
            {
                list.Insert(0, Vm.ServerHost);
            }
            NTMinerRegistry.SetControlCenterHosts(list);
            // 内网免登录
            if (Net.IpUtil.IsInnerIp(Vm.ServerHost))
            {
                VirtualRoot.SetRpcUser(new User.RpcUser("localhost", "localhost"));
                this.Close();
                // 回调可能弹窗,弹窗可能有父窗口,父窗口是顶层窗口,如果在this.Close()之前回调
                // 则会导致弹窗的父窗口是本窗口,而本窗口随后立即关闭导致作为子窗口的弹窗也会被关闭。
                _onLoginSuccess?.Invoke();
                return;
            }
            RpcRoot.Server.ControlCenterService.LoginAsync(Vm.LoginName, passwordSha1, (response, exception) => {
                UIThread.Execute(() => () => {
                    if (response == null)
                    {
                        Vm.ShowMessage("服务器忙");
                        return;
                    }
                    if (response.IsSuccess())
                    {
                        this.Close();
                        // 回调可能弹窗,弹窗可能有父窗口,父窗口是顶层窗口,如果在this.Close()之前回调
                        // 则会导致弹窗的父窗口是本窗口,而本窗口随后立即关闭导致作为子窗口的弹窗也会被关闭。
                        _onLoginSuccess?.Invoke();
                    }
                    else if (Vm.LoginName == "admin" && response.StateCode == 404)
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Visible;
                        Vm.ShowMessage(response.ReadMessage(exception));
                        this.PbPasswordAgain.Focus();
                    }
                    else
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Collapsed;
                        Vm.ShowMessage(response.ReadMessage(exception));
                    }
                });
            });
        }
コード例 #2
0
ファイル: LoginWindow.xaml.cs プロジェクト: GangDang/ntminer
        private void BtnLogin_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Vm.ServerHost))
            {
                Vm.ShowMessage("服务器地址不能为空");
                return;
            }
            string passwordSha1 = HashUtil.Sha1(Vm.Password);

            NTMinerRegistry.SetControlCenterHost(Vm.ServerHost);
            var list = NTMinerRegistry.GetControlCenterHosts();

            if (!list.Contains(Vm.ServerHost))
            {
                list.Insert(0, Vm.ServerHost);
            }
            NTMinerRegistry.SetControlCenterHosts(list);
            if (Net.Util.IsInnerIp(Vm.ServerHost))
            {
                SingleUser.LoginName = "localhost";
                SingleUser.SetPasswordSha1("localhost");
                this.Close();
                return;
            }
            Server.ControlCenterService.LoginAsync(Vm.LoginName, passwordSha1, (response, exception) => {
                UIThread.Execute(() => {
                    if (response == null)
                    {
                        Vm.ShowMessage("服务器忙");
                        return;
                    }
                    if (response.IsSuccess())
                    {
                        SingleUser.LoginName = Vm.LoginName;
                        SingleUser.SetPasswordSha1(passwordSha1);
                        this.Close();
                    }
                    else if (Vm.LoginName == "admin" && response.StateCode == 404)
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Visible;
                        Vm.ShowMessage(response.Description);
                        this.PbPasswordAgain.Focus();
                    }
                    else
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Collapsed;
                        Vm.ShowMessage(response.Description);
                    }
                });
            });
        }
コード例 #3
0
        public ServerHostSelectViewModel(string selected, Action <ServerHostItem> onOk)
        {
            var data = NTMinerRegistry.GetControlCenterHosts().ToList();

            if (!data.Contains("127.0.0.1") && !data.Contains("localhost"))
            {
                data.Add("127.0.0.1");
            }
            _serverHosts    = data.Select(a => new ServerHostItem(a)).ToList();
            _selectedResult = _serverHosts.FirstOrDefault(a => a.IpOrHost == selected);
            OnOk            = onOk;
            this.Remove     = new DelegateCommand <ServerHostItem>((serverHost) => {
                if (this.ServerHosts.Remove(serverHost))
                {
                    if (NTMinerRegistry.GetControlCenterHost() == serverHost.IpOrHost)
                    {
                        NTMinerRegistry.SetControlCenterHost(string.Empty);
                    }
                    this.ServerHosts = this.ServerHosts.ToList();
                }
            });
        }