private void Window_Loaded(object sender, RoutedEventArgs e) { DuplexChannelFactory <IDGSerController> DGSer; NetTcpBinding tcpBinding = new NetTcpBinding(); //release the limitation of the size of message which can be sent tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; try { //connect to Server Tier DGSer = new DuplexChannelFactory <IDGSerController>(this, tcpBinding, server_URL); m_DGSer = DGSer.CreateChannel(); } catch (CommunicationObjectFaultedException ex) { MessageBox.Show(ex.Message); } catch (Exception exc) { MessageBox.Show(exc.Message); } //set up page information user.Content = "Welcome " + username + ", \nplease select a hreo and press \"GO\" to enter the battle."; pressGO = false; try { m_DGSer.RegisterClient(username); heroInfoList = m_DGSer.GetHeroInfoList(); heroNameList = m_DGSer.GetHeroNameList(); selectedBossInfo = m_DGSer.GetSelectedBossInfo(); setupInfo(); m_DGSer.NotifyServer(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/** * Check the connection of every servers in Server Tier * **/ public CheckServer(Dictionary <String, String> serverList) { playerSelectHero = new Dictionary <String, String>(); playerHeroInfo = new Dictionary <String, String>(); serverState = new ServerState(); serverInfo = new ServerInfo(); bossInServer = new List <String>(); serverCount = 0; //run each server foreach (var server in serverList) { DuplexChannelFactory <IDGSerController> DGSer; NetTcpBinding tcpBinding = new NetTcpBinding(); try { //connect server DGSer = new DuplexChannelFactory <IDGSerController>(this, tcpBinding, server.Value); m_DGSer = DGSer.CreateChannel(); playerSelectHero = m_DGSer.GetPlayersHeroName(); playerHeroInfo = m_DGSer.GetPlayersHeroHPInfo(); bossInServer.Add(m_DGSer.GetSelectedBossInfo()); setServerState(server.Key, true); setServerInfo(server.Key); serverInfo.serverInfoList.Insert(serverCount, memberInServer); serverCount++; } catch (Exception)//if fail to connect { bossInServer.Add(""); setServerState(server.Key, false); memberInServer = new MemberInServer(); serverInfo.serverInfoList.Insert(serverCount, memberInServer); serverCount++; } } }
//load window private void Window_Loaded(object sender, RoutedEventArgs e) { DuplexChannelFactory <IDGSerController> DGSer; NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; try { DGSer = new DuplexChannelFactory <IDGSerController>(this, tcpBinding, server_URL); m_DGSer = DGSer.CreateChannel(); } catch (CommunicationObjectFaultedException ex) { MessageBox.Show(ex.Message); } catch (Exception exc) { MessageBox.Show(exc.Message); } //set up the information try { m_DGSer.RegisterPlayer(username, selectedHeroID); int heroHP = 0; while (heroHP == 0) { heroHP = m_DGSer.GetSelectedHeroHP(username); } currentHP.Content = heroHP; selfState.Content = "/" + heroHP; hero_type.Content = username + "(" + m_DGSer.GetHeroName(selectedHeroID) + ")"; boss_name.Content = m_DGSer.GetBossName(); bossMaxHP = m_DGSer.GetBossMaxHP(); boss_hp.Content = "HP: " + bossMaxHP; lvAbilitySelection.ItemsSource = m_DGSer.GetAbilityInfo(selectedHeroID).abilitesList; m_DGSer.NotifyAllPlayer(); } catch (TimeoutException et) { MessageBox.Show(et.Message); m_DGSer.RegisterPlayer(username, selectedHeroID); int heroHP = 0; while (heroHP == 0) { heroHP = m_DGSer.GetSelectedHeroHP(username); } currentHP.Content = heroHP; selfState.Content = "/" + heroHP; hero_type.Content = username + "(" + m_DGSer.GetHeroName(selectedHeroID) + ")"; boss_name.Content = m_DGSer.GetBossName(); bossMaxHP = m_DGSer.GetBossMaxHP(); boss_hp.Content = "HP: " + bossMaxHP; lvAbilitySelection.ItemsSource = m_DGSer.GetAbilityInfo(selectedHeroID).abilitesList; m_DGSer.NotifyAllPlayer(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }