private ConnectionInfo ResolveExistingConnection(ConnectionInfo info) { ConnectionInfo found; bool alreadyExists = serverList.TryGet(info.ServerType, info.Server, info.UserName, out found); if (alreadyExists) { return(found); } info.Connect(); info.ConnectionClosed += (sender, args) => serverList.Remove(info); serverList.Add(info); return(info); }
private void AddNewQueryTab() { using (NewConnection nc = new NewConnection()) { if (nc.ShowDialog(this) != DialogResult.OK) { return; } string msg = null; try { ConnectionInfo info; bool alreadyExists = false; alreadyExists = serverList.TryGet(nc.ConnectionInfo.ServerType, nc.ConnectionInfo.Server, nc.ConnectionInfo.UserName, out info); if (!alreadyExists) { info = nc.ConnectionInfo; info.Connect(); serverList.Add(info); info.ConnectionClosed += (sender, args) => serverList.Remove(info); } CreateQueryTab(info.Title, info); if (!alreadyExists) { objectExplorer.AddServer(new SwisMetaDataProvider(info), info); } } catch (FaultException <InfoServiceFaultContract> ex) { log.Error("Failed to connect", ex); msg = ex.Detail.Message; } catch (SecurityNegotiationException ex) { log.Error("Failed to connect", ex); msg = ex.Message; } catch (FaultException ex) { log.Error("Failed to connect", ex); msg = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; } catch (MessageSecurityException ex) { log.Error("Failed to connect", ex); if (ex.InnerException != null && ex.InnerException is FaultException) { msg = (ex.InnerException as FaultException).Message; } else { msg = ex.Message; } } catch (Exception ex) { log.Error("Failed to connect", ex); msg = ex.Message; } if (msg != null) { msg = string.Format("Unable to connect to Information Service. {0}", msg); MessageBox.Show(this, msg, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }