private void Window_Loaded(object sender, RoutedEventArgs e) { if (AppSettings.Default.AutoConnect) { ConnectionManager.GetManager().Connect(AppSettings.Default.Host, AppSettings.Default.Port); } else { ConnectionWindow conWin = new ConnectionWindow(); conWin.Owner = GetWindow(this); conWin.ShowDialog(); } }
public async Task Connect(string ipAddress, string port) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://" + ipAddress + ":" + port + "/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ApplicationManager.GetManager().Init(client); try { HttpResponseMessage response = await client.GetAsync("api/application/"); response.EnsureSuccessStatusCode(); isConnected = true; } catch (Exception) { MessageBox.Show(System.Windows.Application.Current.MainWindow, "Error: Could not connect to the server at " + ipAddress + ":" + port, "Error"); ConnectionWindow connectionWindow = new ConnectionWindow(); connectionWindow.Owner = System.Windows.Application.Current.MainWindow; connectionWindow.ShowDialog(); return; } await ApplicationManager.GetManager().RefreshApplications(); foreach (Window w in System.Windows.Application.Current.Windows) { if (w.GetType() == typeof(MainWindow)) { MainWindow window = w as MainWindow; window.menuConnect.IsEnabled = false; window.menuDisconnect.IsEnabled = true; window.menuRefresh.IsEnabled = true; } } }//Checking why we get 2 error messages on fail connect. Check with clicking refresh first.
private void menuConnect_Click(object sender, RoutedEventArgs e) { ConnectionWindow connectionWindow = new ConnectionWindow(); connectionWindow.Owner = GetWindow(this); connectionWindow.ShowDialog(); }