private void btnLogin_Click(object sender, EventArgs e) { try { CommunicateProxy.SetCredential(Username, Password); CommunicateProxy.SessionId = Program.SessionId; CommunicateProxy.EncryptKey = Guid.NewGuid().ToString(); using (WaitCursor cursor = new WaitCursor(true)) { CommunicateProxy.RegisterSession(); } } catch (SecurityException) { string errInfo = PasswordTryCount != 3 ? "您输入的用户名或密码不正确请确认后再试。" : "非授权用户不得使用本系统,请与系统管理员联系。"; XtraMessageBox.Show(errInfo); txtPassword.Focus(); PasswordTryCount++; if (PasswordTryCount >= 3) { Environment.Exit(0); } else { return; } } DisableUI(); this.lblProgress.Visible = true; this.pbProgress.Visible = true; if (Acceptted != null) { Acceptted(this, EventArgs.Empty); } }
/// <summary> /// Initials the state of the network. /// </summary> private void InitialNetworkState() { if (CommunicateProxy.Ping()) { online = true; tbtnNetworkStatus.Glyph = Resources.link; tbtnNetworkStatus.Hint = "当前状态 - 在线(双击鼠标强制系统离线)"; } else { online = false; tbtnNetworkStatus.Glyph = Resources.link_delete; tbtnNetworkStatus.Hint = "当前状态 - 离线(双击鼠标强制系统在线)"; } }
//��ʼ��ͨ�Ŵ��� void InitCommunicationProxy(ClientServerSetting server, string user, string pwd, bool anonymous) { m_currentServer = server; m_communicateProxy = new CommunicateProxy(server.HOST, server.Port, "", 30000); m_communicateProxy.ErrorRecived += new EventHandler<CustomEventArgs<string>>(communicateProxy_ErrorRecived); m_communicateProxy.SessionKicked += new EventHandler<CustomEventArgs<string>>(communicateProxy_SessionKicked); string sid = GenerateSession(user); try { m_communicateProxy.Login(user, pwd, sid, false, anonymous, false); m_sessionID = sid; ServiceRepository.ClientCommunicateProxy = m_communicateProxy; } catch (Exception ex) { if (ex.Message.StartsWith("���û��ѵ�½")) { DialogResult dialogResult = Helper.ShowQuestion(this, "���˺��Ѿ��Զ�ռ��ʽ��¼��ѡ��\"��\"���Թ���ģʽ��¼��ѡ��\"��\"��ǿ��ע���ѵ�¼���û�", MessageBoxButtons.YesNoCancel, MessageBoxDefaultButton.Button1); if (dialogResult == DialogResult.Yes) { m_communicateProxy.Login(user, pwd, sid, false, true, false); m_sessionID = sid; ServiceRepository.ClientCommunicateProxy = m_communicateProxy; } else if (dialogResult == DialogResult.No) { m_communicateProxy.Login(user, pwd, sid, true, false, false); m_sessionID = sid; ServiceRepository.ClientCommunicateProxy = m_communicateProxy; } else { throw; } } else { throw; } } }
/// <summary> /// 判断当前网络的连通状态 /// </summary> /// <returns>如果连通则返回true,否则返回false</returns> public bool IsConnected() { return(CommunicateProxy.Ping()); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //读取BH客户端地址 s_bhClientAppDir = Helper.GetBhClientDir(); if (string.IsNullOrEmpty(s_bhClientAppDir)) ChangeBhClientAppLocation(); if (string.IsNullOrEmpty(s_bhClientAppDir)) { MessageBox.Show("未找到有效的ZLBH客户端程序目录"); } else { List<ClientServerSetting> serverList = Helper.GetAllServerSetting(s_bhClientAppDir); using (LoginForm loginForm = LoginForm.New()) { if (loginForm.ShowDialog() == DialogResult.OK) { s_communicateProxy = loginForm.CommunicateProxy; s_sessionID = loginForm.SessionID; s_currentServer = loginForm.CurrentServer; } else { return; } } if (s_communicateProxy != null) { if (s_bhClientAppDir != AppDomain.CurrentDomain.BaseDirectory) { File.Copy( Path.Combine(s_bhClientAppDir, "ZLSoft.BusinessHome.DynamicServiceProxy.dll"), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZLSoft.BusinessHome.DynamicServiceProxy.dll"), true); } Environment.CurrentDirectory = s_bhClientAppDir; //日志组件 string logCfgFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XToolLog.config"); log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(logCfgFile)); s_log = log4net.LogManager.GetLogger(typeof(Program)); ClientEventDispatcher.Log = s_log; CommunicateProxy.Logger = s_log; ClientLogger.logger = s_log; s_log.Info(string.Format("****** 以[{0}]登陆[{1}:{2}] ******", s_communicateProxy.UserName, s_currentServer.HOST, s_currentServer.Port)); //远程服务 RemoteServiceRegister register = new RemoteServiceRegister(); register.RegisterRemoteServices(ServiceRepository.Instance); #region 客户端初始化 try { s_isNewVer = File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZLSoft.BusinessHome.Plugin.DataLayer.Interface.dll")); try { Helper.InitOnStartup(s_isNewVer); } catch (TypeLoadException) { if (s_isNewVer) { Helper.InitOnStartup(false); s_isNewVer = false; } else { throw; } } } catch (Exception ex) { Logger.Error("客户端初始化发生异常", ex); } #endregion s_mainForm = new MainForm(); ClientPluginManager.EventToServer(s_mainForm, true); s_communicateProxy.StartPing(); Application.Run(s_mainForm); try { ClientPluginManager.RemovePlugin(s_mainForm); } catch { } finally { s_mainForm.Dispose(); s_mainForm = null; } s_log.Info("****** 正常关闭 ******"); } } }
/// <summary> /// 调用远程访求 /// </summary> /// <param name="request">请求对象</param> /// <returns>返回方法调用结果</returns> private object InvokeRequest(Request request) { return(CommunicateProxy.InvokeCommand(request.Method, request.CallParameters)); }