Skip to content

Commit

Permalink
Merge pull request #120 from jirkapok/Change_Query_Connection
Browse files Browse the repository at this point in the history
UI enhancedments to allow Change query connection
  • Loading branch information
tdanner committed Mar 8, 2018
2 parents d6a9bb3 + fd62be4 commit ba8f1a6
Show file tree
Hide file tree
Showing 21 changed files with 942 additions and 500 deletions.
25 changes: 17 additions & 8 deletions Src/SwqlStudio/ActivityMonitorTab.cs
@@ -1,12 +1,22 @@
using System;
using System.Windows.Forms;
using SwqlStudio.Subscriptions;

namespace SwqlStudio
{
public partial class ActivityMonitorTab : UserControl, IConnectionTab
{
private string subscriptionId;

public ConnectionInfo ConnectionInfo { get; set; }

public SubscriptionManager SubscriptionManager { get; set; }

public bool AllowsChangeConnection
{
get { return false; }
}

public ActivityMonitorTab()
{
InitializeComponent();
Expand All @@ -15,17 +25,18 @@ public ActivityMonitorTab()

void ActivityMonitorTabDisposed(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(subscriptionId) && ConnectionInfo.IsConnected)
if (!String.IsNullOrEmpty(subscriptionId) && ConnectionInfo.IsConnected)
{
ApplicationService.SubscriptionManager.Unsubscribe(ConnectionInfo, subscriptionId);
this.SubscriptionManager.Unsubscribe(ConnectionInfo, subscriptionId);
}
}

public IApplicationService ApplicationService { get; set; }

private void SubscriptionIndicationReceived(IndicationEventArgs e)
{
BeginInvoke(new Action<IndicationEventArgs>(AddIndication), e);
if (this.IsDisposed)
return;

BeginInvoke(new Action<IndicationEventArgs>(AddIndication), e);
}

private void AddIndication(IndicationEventArgs obj)
Expand All @@ -41,8 +52,6 @@ private void AddIndication(IndicationEventArgs obj)
item.EnsureVisible();
}

public ConnectionInfo ConnectionInfo { get; set; }

public void Start()
{
backgroundWorker1.RunWorkerAsync();
Expand All @@ -55,7 +64,7 @@ private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWor
backgroundWorker1.ReportProgress(0, "Starting subscription...");
try
{
subscriptionId = ApplicationService.SubscriptionManager.CreateSubscription(ConnectionInfo, "SUBSCRIBE System.QueryExecuted", SubscriptionIndicationReceived);
subscriptionId = this.SubscriptionManager.CreateSubscription(ConnectionInfo, "SUBSCRIBE System.QueryExecuted", SubscriptionIndicationReceived);
backgroundWorker1.ReportProgress(0, "Waiting for notifications");
}
catch (ApplicationException ex)
Expand Down
76 changes: 76 additions & 0 deletions Src/SwqlStudio/ConnectionsManager.cs
@@ -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;
}
}
}
5 changes: 2 additions & 3 deletions Src/SwqlStudio/CrudTab.cs
Expand Up @@ -31,12 +31,11 @@ public Entity Entity
}
}

/// <inheritdoc />
public IApplicationService ApplicationService { get; set; }

/// <inheritdoc />
public ConnectionInfo ConnectionInfo { get; set; }

public bool AllowsChangeConnection => true;

public event EventHandler CloseItself;

private void CreateSubComponents()
Expand Down
4 changes: 4 additions & 0 deletions Src/SwqlStudio/IApplicationService.cs
Expand Up @@ -8,5 +8,9 @@ public interface IApplicationService
PropertyBag QueryParameters { get; set; }

SubscriptionManager SubscriptionManager { get; }

ConnectionInfo SelectedConnection { get; }

void RefreshSelectedConnections();
}
}
3 changes: 2 additions & 1 deletion Src/SwqlStudio/IConnectionTab.cs
Expand Up @@ -2,7 +2,8 @@ namespace SwqlStudio
{
public interface IConnectionTab
{
IApplicationService ApplicationService { get; set; }
ConnectionInfo ConnectionInfo { get; set; }

bool AllowsChangeConnection { get; }
}
}
4 changes: 2 additions & 2 deletions Src/SwqlStudio/ITabsFactory.cs
Expand Up @@ -6,9 +6,9 @@ internal interface ITabsFactory
{
void AddTextToEditor(string text, ConnectionInfo info);

void OpenActivityMonitor(string title, ConnectionInfo connectionInfo);
void OpenActivityMonitor(ConnectionInfo connectionInfo);

void OpenInvokeTab(string title, ConnectionInfo connectionInfo, Verb verb);
void OpenInvokeTab(ConnectionInfo connectionInfo, Verb verb);

void OpenCrudTab(CrudOperation operation, ConnectionInfo connectionInfo, Entity entity);
}
Expand Down
2 changes: 1 addition & 1 deletion Src/SwqlStudio/InvokeVerbTab.cs
Expand Up @@ -17,8 +17,8 @@ public InvokeVerbTab()
InitializeComponent();
}

public IApplicationService ApplicationService { get; set; }
public ConnectionInfo ConnectionInfo { get; set; }
public bool AllowsChangeConnection => true;
private int locationX = 0;
private int locationY = 0;

Expand Down

0 comments on commit ba8f1a6

Please sign in to comment.