/// <summary> /// Tries to start a <see cref="ControlPanel"/> for a given <see cref="InstanceListBox"/> <paramref name="index"/> /// </summary> /// <param name="index">The <see cref="ListBox.SelectedIndex"/> of <see cref="InstanceListBox"/> to connect to</param> async void TryConnectToIndexInstance(int index) { if (index == ListBox.NoMatches) { return; } var instanceName = InstanceData[index].Name; if (ControlPanel.InstancesInUse.TryGetValue(instanceName, out ControlPanel activeCP)) { activeCP.BringToFront(); return; } var InstanceAccessor = new ServerInterface(masterInterface as ServerInterface); try { ConnectivityLevel res = ConnectivityLevel.None; await WrapServerOp(() => { res = InstanceAccessor.ConnectToInstance(instanceName); }); if (!res.HasFlag(ConnectivityLevel.Connected)) { MessageBox.Show("Unable to connect to instance! Does it exist?"); RefreshInstances(); } else if (!res.HasFlag(ConnectivityLevel.Authenticated)) { MessageBox.Show("The current user is not authorized to access this instance!"); } else { new ControlPanel(InstanceAccessor).Show(); } } catch { InstanceAccessor.Dispose(); throw; } }