/// <summary> /// Asynch form of Connect /// </summary> /// <param name="address">IP address</param> /// <param name="port">Port number</param> public void BeginConnect(string address, int port) { SocketClient sc = new SocketClient(); base.SetSocket(sc); sc.BeginConnect(address, port); }
protected override void Start() { if (_client != null) { Stop(); } _client = new SocketClient(); _client.ConnectCompleted += _client_ConnectCompleted; _client.ErrorOccured += _client_ErrorOccured; _client.ReceiveCompleted += _client_ReceiveCompleted; _client.BeginConnect(_serverIp, _serverPort); }
static void Main(string[] args) { SocketClient sc = new SocketClient(); sc.ConnectCompleted += Sc_ConnectCompleted; sc.ReceiveCompleted += Sc_ReceiveCompleted; sc.SendCompleted += Sc_SendCompleted; sc.ErrorOccured += Sc_ErrorOccured; Thread.Sleep(1000); sc.BeginConnect("127.0.0.1", 37010); Console.ReadLine(); }
public void Start() { if (!_started) { if (_client != null) { Stop(); } _client = new SocketClient(); _client.ConnectCompleted += _client_ConnectCompleted; _client.ErrorOccured += _client_ErrorOccured; _client.ReceiveCompleted += _client_ReceiveCompleted; _client.BeginConnect(_serverIp, _serverPort); _started = true; } }
//Thread loadThread; //delegate void updateUIHandler(string name); //private void updateWork() //{ // GlobalData.ModuleManager.LoadModuleCompleted += ModuleManager_LoadModuleCompleted; // foreach (var item in GlobalData.ModuleCatalog.Modules) // { // if (item.ModuleName != ModuleNames.Login) // { // Log.info("加载模块开始:" + item.ModuleName); // GlobalData.ModuleManager.LoadModule(item.ModuleName); // } // } // Log.info("运行模块开始"); // //GlobalData.ModuleManager.Run(); //} //public void LoadAllModules() //{ // loadThread = new Thread(new ThreadStart(updateWork)); // loadThread.SetApartmentState(ApartmentState.STA); // loadThread.IsBackground = true; // loadThread.Start(); //} //void ModuleManager_LoadModuleCompleted(object sender, LoadModuleCompletedEventArgs e) //{ // Log.info("加载模块完成:" + e.ModuleInfo.ModuleName); // updateUIHandler mothed = new updateUIHandler(updateUI); // this.Dispatcher.Invoke(mothed, e.ModuleInfo.ModuleName); //} //private void updateUI(string name) { // this.moduleTracker.RecordModuleLoaded(name); // GlobalData.LoadModule.Add(name); // //throw new NotImplementedException(); // if (GlobalData.LoadModule.Count == GlobalData.ModuleCatalog.Modules.Count()) // { // Log.info("加载模块完成打开主菜单"); // regionViewRegistry.RegisterViewWithRegion(RegionNames.Main, typeof(SysSwitchView)); // regionManager.RequestNavigate(RegionNames.Main, "SysSwitchView"); // // 加载各模块主页面 // CommandEventArgs ces = new CommandEventArgs(); // ces.Type = CommandType.registerDefViewWithRegion; // GlobalData.EventAggregator.GetEvent<CommandEvent>().Publish(ces); // } //} private void btnLogin_Click(object sender, RoutedEventArgs e) { this.btnLogin.IsEnabled = false; if ((!String.IsNullOrEmpty(this.txtPassword.Password.Trim()) && !String.IsNullOrEmpty(this.txtName.Text.Trim()))) { this.gcLogin.Visibility = Visibility.Collapsed; this.loadingInfo.Visibility = Visibility.Visible; CommandEventArgs cmd = new CommandEventArgs(); cmd.Type = CommandType.showLoading; GlobalData.EventAggregator.GetEvent <CommandEvent>().Publish(cmd); ServiceComm sc = new ServiceComm(); sc.LoginCompleted += (serice, eve) => { if (eve.Succesed && eve.Result) { Log.info("登录成功"); GlobalData.EventAggregator.GetEvent <BaseDataLoadedEvent>().Publish(1); Log.info("加载模块"); LoadAllModules(); Log.info("存储登录信息"); #region 独立存储区操作 try { if (IsolatedStorageFile.IsEnabled == true) { IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForAssembly(); IsolatedStorageFileStream isoFileStream = isoFile.OpenFile("login.txt", System.IO.FileMode.Create); String loginStr = ""; if (this.cbxRemPassword.IsChecked == true) { loginStr = String.Format("{0}", this.txtName.Text.Trim()); } Byte[] bts = Encoding.UTF8.GetBytes(loginStr); isoFileStream.Write(bts, 0, bts.Length); isoFileStream.Close(); isoFile.Dispose(); } } catch (Exception) { } #endregion GlobalData.UserName = this.txtName.Text.Trim(); Log.info("建立回话连接"); SocketClient socketClient = null; socketClient = SocketClient.GetInstance(); //socketClient.ReceivedMsg = new SocketClient.ReceivedMsgHandler(socketClient_ReceivedMsg); socketClient.BeginConnect(); cmd.Type = CommandType.hideLoading; GlobalData.EventAggregator.GetEvent <CommandEvent>().Publish(cmd); } else { this.btnLogin.IsEnabled = true; this.gcLogin.Visibility = Visibility.Visible; this.loadingInfo.Visibility = Visibility.Collapsed; cmd.Type = CommandType.hideLoading; GlobalData.EventAggregator.GetEvent <CommandEvent>().Publish(cmd); MessageBoxX.Info("登陆失败!"); } }; Log.info("开始登录"); sc.Login(this.txtName.Text.Trim(), this.txtPassword.Password.Trim()); } else { this.btnLogin.IsEnabled = true; MessageBox.Show("请输入用户名或密码!"); } }