//��ʼ��ͨ�Ŵ��� 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; } } }
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("****** 正常关闭 ******"); } } }