Skip to content

Commit

Permalink
Enhanced the connection re-connection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rosssaunders committed Jun 24, 2019
1 parent c7ae40b commit 0d1be5f
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 167 deletions.
13 changes: 8 additions & 5 deletions src/Clients/ExcelClient/AddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void AutoOpen()
ConnectionMonitor.RegisterClient(Client);
ExcelComAddInHelper.LoadComAddIn(new ComAddIn(Client, ConnectionMonitor));

//app.StatusBar = Resources.SearchingForServersMessage;

Client.OnConnectionStatusChanged += Client_OnConnectionStatusChanged;
//Start the monitor
ConnectionMonitor.FindAvailableServicesAsync().ContinueWith(result =>
{
Expand All @@ -47,12 +47,15 @@ public void AutoOpen()

ConnectionMonitor.Start();

CustomRibbon.Refresh(); //Inform Excel to refresh the UI

//ExcelStatusBarHelperAsync.ResetStatusBar();
CustomRibbon.Refresh();
});
}

private void Client_OnConnectionStatusChanged(object sender, ConnectionStatusChangedEventArgs e)
{
CustomRibbon.Refresh();
}

public void AutoClose()
{
ConnectionMonitor.Stop();
Expand Down
32 changes: 26 additions & 6 deletions src/Clients/ExcelClient/CustomRibbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public void Ribbon_Load(IRibbonUI sender)

public bool OnRefreshEnabled(IRibbonControl control)
{
if (_client.IsConnecting)
return false;

return !_connectionMonitor.IsSearchingForEndPoints;
}

Expand All @@ -51,6 +54,9 @@ public bool OnConnectionsEnabled(IRibbonControl control)
if (_connectionMonitor.IsSearchingForEndPoints)
return false;

if (_client.IsConnecting)
return false;

return _connectionMonitor.AvailableEndpoints.Count > 0;
}

Expand Down Expand Up @@ -222,19 +228,33 @@ public void OnRefresh(IRibbonControl control)

public void OnCalculate(IRibbonControl control)
{
if(_connectionMonitor.IsConnected)
try
{
if (_connectionMonitor.IsConnected)
{
_client.RequestCalculate();
ExcelStatusBarHelperAsync.SetStatusBarWithResetDelay(Resources.ComputeRequestedMessage, 3);
}
}
catch(Exception ex)
{
_client.RequestCalculate();
ExcelStatusBarHelperAsync.SetStatusBarWithResetDelay(Resources.ComputeRequestedMessage, 3);
ExcelStatusBarHelperAsync.SetStatusBarWithResetDelay(ex.Message, 5);
}
}

public void OnLoadPositions(IRibbonControl control)
{
if (_connectionMonitor.IsConnected)
try
{
if (_connectionMonitor.IsConnected)
{
_client.LoadPositions();
ExcelStatusBarHelperAsync.SetStatusBarWithResetDelay(Resources.LoadPortfoliosRequestedMessage, 3);
}
}
catch(Exception ex)
{
_client.LoadPositions();
ExcelStatusBarHelperAsync.SetStatusBarWithResetDelay(Resources.LoadPortfoliosRequestedMessage, 3);
ExcelStatusBarHelperAsync.SetStatusBarWithResetDelay(ex.Message, 5);
}
}

Expand Down
Loading

0 comments on commit 0d1be5f

Please sign in to comment.