-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from jirkapok/Change_Query_Connection
UI enhancedments to allow Change query connection
- Loading branch information
Showing
21 changed files
with
942 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System.Windows.Forms; | ||
|
||
namespace SwqlStudio | ||
{ | ||
internal class ConnectionsManager | ||
{ | ||
private readonly IApplicationService applicationService; | ||
private readonly ServerList serverList; | ||
private readonly QueriesDockPanel dockPanel; | ||
|
||
public ConnectionsManager(IApplicationService applicationService, ServerList serverList, QueriesDockPanel dockPanel) | ||
{ | ||
this.applicationService = applicationService; | ||
this.serverList = serverList; | ||
this.dockPanel = dockPanel; | ||
} | ||
|
||
public void CreateConnection() | ||
{ | ||
ConnectionInfo connection = AskForNewConnection(); | ||
if (connection != null) | ||
ResolveExistingConnection(connection); | ||
} | ||
|
||
internal ConnectionInfo ResolveConnection() | ||
{ | ||
ConnectionInfo info = EnsureExistingConnection(); | ||
if (info != null) | ||
return ResolveExistingConnection(info); | ||
|
||
return null; | ||
} | ||
|
||
private ConnectionInfo EnsureExistingConnection() | ||
{ | ||
var selectedConnection = this.applicationService.SelectedConnection; | ||
if (selectedConnection != null) | ||
return selectedConnection; | ||
|
||
return AskForNewConnection(); | ||
} | ||
|
||
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(); | ||
var provider = serverList.Add(info); | ||
|
||
info.ConnectionClosed += (sender, args) => | ||
{ | ||
this.dockPanel.CloseAllFixedConnectionTabs(info); | ||
serverList.Remove(info); | ||
}; | ||
|
||
this.dockPanel.AddServer(provider, info); | ||
return info; | ||
} | ||
|
||
internal static ConnectionInfo AskForNewConnection() | ||
{ | ||
using (var nc = new NewConnection()) | ||
{ | ||
if (nc.ShowDialog() == DialogResult.OK) | ||
{ | ||
return nc.ConnectionInfo; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.