public static void Main(string[] args) { Application.Init (); MainWindow win = new MainWindow (); win.Show (); Application.Run (); }
private void Application_Startup(object sender, StartupEventArgs e) { // create the main window and assign your datacontext MainWindow main; main = new MainWindow(); main.Show(); main.ShowOptionsWindow(); }
private void Application_Startup(object sender, StartupEventArgs e) { #if PORTABLE var programDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Log.LogFile = Path.Combine(programDir, "log.txt"); MakePortable(User.Default); #endif MigrateUserSettings(); var mainWindow = new MainWindow(); mainWindow.Show(); }
private void OnGameSessionJoin(object sender, BoolEventArgs e) { connectAnimation.Stop(); if(e.Ok) { var mw = new MainWindow(); mw.Show(); mw.Closed += (s, o) => Show(); mw.serverListWindow = this; Hide(); } else { MessageBox.Show("Не удалось подключиться к игре: " + e.Error); } }
private void Button_Click(object sender, RoutedEventArgs e) { ResourceManager.Instance.LoginName = loginTB.Text; bool loginSuccess = ResourceManager.Instance.Login(); if(loginSuccess == false && ResourceManager.Instance.IsConnected == false) { MessageBox.Show("Service connection couldn't be established.\nCheck service is running and try again.", "Service not running", MessageBoxButton.OK, MessageBoxImage.Error); } else if (loginSuccess == false && ResourceManager.Instance.IsConnected == true) { MessageBox.Show("Login failed please try again.", "Service login failed", MessageBoxButton.OK, MessageBoxImage.Information); } else { MainWindow mainWin = new MainWindow(); mainWin.Show(); mainWin.loginNameLbl.Content = "Logged in as: "+ResourceManager.Instance.LoginName; Close(); } }
private void btnEnter_Click(object sender, RoutedEventArgs e) { string login = TbLogin.Text; string password = PbPassword.Password; Guid? result = MainWindow.ServerClient.Authorize(login, password); if (result == null) { MessageBox.Show("Неверный логин или пароль", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); TbLogin.Clear(); PbPassword.Clear(); } else { _userId = (Guid) result; this.Hide(); var contatcs = new MainWindow(_userId, login); contatcs.Activate(); contatcs.Show(); this.Close(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { if (name.Text != "" && pass1.Password != "" && pass2.Password != "") { reg_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //Console.WriteLine("Enter server IP:"); string ip_str = "localhost"; int port = 3000; IPHostEntry ipList = Dns.Resolve(ip_str); IPAddress ip = ipList.AddressList[0]; IPEndPoint endPoint = new IPEndPoint(ip, port); reg_socket.Connect(endPoint); RegInfo regInfo = new RegInfo(name.Text, pass1.Password, pass2.Password); IFormatter formatter = new BinaryFormatter(); Stream stream = new MemoryStream(); formatter.Serialize(stream, regInfo); byte[] buffer2 = new byte[1024]; stream.Position = 0; while (stream.Position < stream.Length) { int readCount = stream.Read(buffer2, 0, 1024); reg_socket.Send(buffer2, readCount, 0); } byte[] answerFromServer = new byte[1024]; int resCount = reg_socket.Receive(answerFromServer); string messFromServer = Encoding.UTF8.GetString(answerFromServer, 0, resCount); if (messFromServer == "Добро пожаловать!") { MainWindow mainW = new MainWindow(regInfo.Name); mainW.Show(); //mainW.name = regInfo.Name; this.Close(); } else { MessageBox.Show(messFromServer); } reg_socket.Close(); } } catch (SocketException exp) { MessageBox.Show(exp.Message); } }
/// <summary> /// Funzione che tenta di instaurare la connessione. Riavvia l'interfaccia di connessione se la connessione fallisce. /// In caso di connessione riuscita, crea la Window principale (MainWindow) se non già esistente /// Se già esistente invece, perchè già si è collegati ad un altro server, crea un nuovo tab /// </summary> /// <param name="result"> Struttura contenente il risultato delle operazioni asincrone </param> private void ConnectionRequest(IAsyncResult result) { ClientProperties properties = result.AsyncState as ClientProperties; // Nel caso in cui la connessione fallisce if ((properties == null) || (!properties.client.Connected)) { MessageBox.Show("Impossibile stabilire una connessione"); this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { // Abilitazione dei vari componenti dell'interfaccia ConnectButton.IsEnabled = true; txtAddress1.IsEnabled = txtAddress2.IsEnabled = txtAddress3.IsEnabled = txtAddress4.IsEnabled = true; txtPort.IsEnabled = true; this.Cursor = Cursors.Arrow; })); return; } NetworkStream stream = properties.client.GetStream(); // Imposto il tempo in cui il client si mette in attesa di ricevere dati stream.ReadTimeout = 5000; // Se la connessione ha avuto successo, bisogna verificare se esiste già una MainWindow // - Se esiste, significa che non bisogna crearne una nuova, ma bisogna solo aggiungere un tab // - Se non esiste, significa che bisogna crearne una nuova this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { // Caso in cui MainWindow esiste già foreach (Window window in System.Windows.Application.Current.Windows) { if (window is MainWindow) { MainWindow w = window as MainWindow; w.NewTab(properties.client, stream, properties.address); w.ActiveConnections.Add(properties.address); this.Close(); return; } } // Caso in cui MainWindows non esiste: creazione di una nuova MainWindow MainWindow main = new MainWindow(properties.client, stream, properties.address); main.ActiveConnections.Add(properties.address); this.Close(); main.Show(); })); try { properties.client.EndConnect(result); } catch (SocketException) { // In caso di errore sul socket: chiusura del nuovo tab ExceptionHandler.ConnectionError(); } catch (ObjectDisposedException) { // In caso di chiusura del socket: chiusura del tab ExceptionHandler.ConnectionError(); } }