Skip to content

Commit 54938f4

Browse files
committed
Perform update check while Excel is running
1 parent 4eab179 commit 54938f4

23 files changed

+244
-620
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
- Avoid checking trust access to the VBA project object model twice on function generation.
5353
- Return raw result when using as a python module even if HTTP 202 is received.
5454
- Return the full response as text when using as a python module, and not only the first 255 characters.
55+
- In case NO_PROXY environment variable was containing multiple URLs and should have been applied, it was not the case by the add-in.
5556

5657
### Removed
5758
- Drop support for `python` < `3.8`.
@@ -107,6 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
107108
- `caching` options are now per formula instead of per REST API and have been renamed. See [migration guide](docs/migration_guide.md) for more details.
108109
- xlwings configuration is now retrieved faster (not retrieved from a file and do not look for environment variable).
109110
- `definition_retrieval_auths` parameters have been renamed to match `requests_auth` parameters for consistency with `auth` section.
111+
- Update is now retrieved as soon as possible instead of only at Microsoft Excel close.
110112

111113
## [0.69.0] - 2018-12-03
112114
### Changed

MANIFEST.in

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
recursive-include addin/PyxelRestAddIn/bin/Release *.dll *.config *.manifest *.vsto *.xml *.png *.ico
22
recursive-include addin *.xlam
3-
recursive-include pyxelrest_resources *.png

addin/PyxelRestAddIn/Configuration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private YamlStream LoadPath(string path)
5252

5353
private YamlStream LoadUrl(string fileUrl)
5454
{
55-
HttpWebResponse response = UrlChecker.ConnectTo(fileUrl, UrlChecker.GetProxyFor(fileUrl), close: false);
55+
HttpWebResponse response = HttpHelper.ConnectTo(fileUrl);
5656
if (response == null || response.StatusCode != HttpStatusCode.OK)
5757
{
5858
string details = response == null ? "" : response.StatusDescription;

addin/PyxelRestAddIn/HttpHelper.cs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using log4net;
2+
using System;
3+
using System.Net;
4+
using System.Net.Security;
5+
using System.Security.Cryptography.X509Certificates;
6+
7+
namespace PyxelRestAddIn
8+
{
9+
public sealed class HttpHelper
10+
{
11+
private static readonly ILog Log = LogManager.GetLogger("HttpHelper");
12+
13+
internal static HttpWebResponse ConnectTo(string url, string proxy="", bool close=false)
14+
{
15+
try
16+
{
17+
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysValidate);
18+
ServicePointManager.Expect100Continue = true;
19+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
20+
Uri urlCheck = new Uri(url);
21+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlCheck);
22+
request.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysValidate);
23+
request.Timeout = 500;
24+
if (proxy.Equals(string.Empty))
25+
proxy = GetProxyFor(url);
26+
if (proxy == null)
27+
request.Proxy = new WebProxy();
28+
else if (proxy.Length > 0)
29+
request.Proxy = new WebProxy(proxy);
30+
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
31+
if (close)
32+
response.Close();
33+
return response;
34+
}
35+
catch (WebException e)
36+
{
37+
HttpWebResponse response = (HttpWebResponse)e.Response;
38+
if (response != null)
39+
response.Close();
40+
return response;
41+
}
42+
catch (Exception)
43+
{
44+
return null;
45+
}
46+
}
47+
48+
private static bool AlwaysValidate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
49+
{
50+
return true;
51+
}
52+
53+
internal static string GetProxyFor(string url)
54+
{
55+
string no_proxy = Environment.GetEnvironmentVariable("NO_PROXY");
56+
if (string.IsNullOrEmpty(no_proxy))
57+
return string.Empty; // System proxy should be used
58+
59+
foreach(string no_proxy_url in no_proxy.Split(','))
60+
{
61+
if (url.Contains(no_proxy_url))
62+
return null; // No proxy should be used
63+
}
64+
return string.Empty; // System proxy should be used
65+
}
66+
}
67+
}

addin/PyxelRestAddIn/PyxelRestAddIn.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
<SubType>Form</SubType>
270270
</Compile>
271271
<Compile Include="Updater.cs" />
272+
<Compile Include="HttpHelper.cs" />
272273
<Compile Include="UrlChecker.cs" />
273274
<Compile Include="ServicePanel.cs" />
274275
<Compile Include="ThisAddIn.cs">

addin/PyxelRestAddIn/PyxelRestRibbon.Designer.cs

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addin/PyxelRestAddIn/PyxelRestRibbon.cs

+25-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public partial class PyxelRestRibbon
1818
"User Defined Functions cannot be loaded.\n"+
1919
"Check logs for more details or contact your support team.\n";
2020

21+
private Updater VersionUpdater;
22+
2123
private void PyxelRestRibbon_Load(object sender, RibbonUIEventArgs e)
2224
{
2325
generateUDFAtStartupButton.Checked = ThisAddIn.GenerateUDFAtStartup();
@@ -50,7 +52,8 @@ private void PyxelRestRibbon_Load(object sender, RibbonUIEventArgs e)
5052
pathToPythonEditBox.Text = ThisAddIn.GetSetting("PathToPython");
5153
customXlwingsPathEditBox.Text = ThisAddIn.GetSetting("PathToXlWingsBasFile");
5254

53-
developerGroup.Label = string.Format("Excel {0} - Python {1}", Globals.ThisAddIn.GetVersion(), Globals.ThisAddIn.GetPyxelRestVersion(pathToPythonEditBox.Text));
55+
var pyxelrestVersion = Globals.ThisAddIn.GetPyxelRestVersion(pathToPythonEditBox.Text);
56+
developerGroup.Label = string.Format("Excel {0} - Python {1}", Globals.ThisAddIn.GetVersion(), pyxelrestVersion);
5457

5558
if (!File.Exists(pathToPythonEditBox.Text))
5659
{
@@ -60,17 +63,28 @@ private void PyxelRestRibbon_Load(object sender, RibbonUIEventArgs e)
6063
{
6164
developerOptionsGroup.Label = "Advanced options seems to be valid";
6265
}
66+
67+
VersionUpdater = new Updater(pyxelrestVersion, installDevelopmentReleasesButton.Checked);
68+
if (autoUpdateButton.Enabled)
69+
VersionUpdater.StartCheck();
6370
}
6471

6572
private void ActivateOrDeactivateAutoUpdate(object sender, RibbonControlEventArgs e)
6673
{
6774
try
6875
{
69-
((RibbonToggleButton)sender).Label = string.Format("Automatic update is {0}", ((RibbonToggleButton)sender).Checked ? "enabled" : "disabled");
70-
installDevelopmentReleasesButton.Enabled = ((RibbonToggleButton)sender).Checked;
71-
((RibbonToggleButton)sender).Image = ((RibbonToggleButton)sender).Checked ? Properties.Resources.data_transfer_download_128 : Properties.Resources.data_transfer_download_128_grey;
72-
ThisAddIn.SetSetting("AutoCheckForUpdates", "" + ((RibbonToggleButton)sender).Checked);
73-
Log.DebugFormat("Auto check for update set to {0}", ((RibbonToggleButton)sender).Checked);
76+
var autoUpdate = ((RibbonToggleButton)sender).Checked;
77+
((RibbonToggleButton)sender).Label = string.Format("Automatic update is {0}", autoUpdate ? "enabled" : "disabled");
78+
installDevelopmentReleasesButton.Enabled = autoUpdate;
79+
((RibbonToggleButton)sender).Image = autoUpdate ? Properties.Resources.data_transfer_download_128 : Properties.Resources.data_transfer_download_128_grey;
80+
ThisAddIn.SetSetting("AutoCheckForUpdates", "" + autoUpdate);
81+
82+
if (autoUpdate)
83+
VersionUpdater.StartCheck();
84+
else
85+
VersionUpdater.StopCheck();
86+
87+
Log.DebugFormat("Auto check for update set to {0}", autoUpdate);
7488
}
7589
catch (ConfigurationErrorsException ex)
7690
{
@@ -140,7 +154,8 @@ private void ActivateOrDeactivatePreReleaseCheck(object sender, RibbonControlEve
140154
{
141155
try
142156
{
143-
if (((RibbonToggleButton)sender).Checked)
157+
var checkPreRelease = ((RibbonToggleButton)sender).Checked;
158+
if (checkPreRelease)
144159
{
145160
((RibbonToggleButton)sender).Label = "Update include unstable releases";
146161
((RibbonToggleButton)sender).Image = Properties.Resources.data_transfer_download_128_orange;
@@ -150,8 +165,9 @@ private void ActivateOrDeactivatePreReleaseCheck(object sender, RibbonControlEve
150165
((RibbonToggleButton)sender).Label = "Update include stable releases only";
151166
((RibbonToggleButton)sender).Image = Properties.Resources.data_transfer_download_128;
152167
}
153-
ThisAddIn.SetSetting("CheckPreReleases", "" + ((RibbonToggleButton)sender).Checked);
154-
Log.DebugFormat("Check pre-releases during update set to {0}", ((RibbonToggleButton)sender).Checked);
168+
ThisAddIn.SetSetting("CheckPreReleases", "" + checkPreRelease);
169+
VersionUpdater.InstallPreRelease = checkPreRelease;
170+
Log.DebugFormat("Check pre-releases during update set to {0}", checkPreRelease);
155171
}
156172
catch (ConfigurationErrorsException ex)
157173
{

addin/PyxelRestAddIn/ThisAddIn.cs

+1-16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public partial class ThisAddIn
2525

2626
private static System.Configuration.Configuration Config = LoadConfig();
2727

28+
2829
internal static string GetSetting(string key)
2930
{
3031
if (Config.AppSettings.Settings[key] == null)
@@ -93,22 +94,6 @@ private static System.Configuration.Configuration LoadConfig()
9394

9495
private void ThisAddIn_Shutdown(object sender, EventArgs e)
9596
{
96-
Log.Debug("Stopping PyxelRest Addin...");
97-
try
98-
{
99-
// Do not read configuration to perform the action requested by the user even if saving it in configuration failed.
100-
var autoUpdateButton = Globals.Ribbons.PyxelRestRibbon.autoUpdateButton;
101-
if (autoUpdateButton.Enabled && autoUpdateButton.Checked)
102-
{
103-
var installDevelopmentReleasesButton = Globals.Ribbons.PyxelRestRibbon.installDevelopmentReleasesButton;
104-
var pathToPythonEditBox = Globals.Ribbons.PyxelRestRibbon.pathToPythonEditBox;
105-
new Updater(pathToPythonEditBox.Text).CheckUpdate(installDevelopmentReleasesButton.Checked);
106-
}
107-
}
108-
catch (Exception ex)
109-
{
110-
Log.Error("An error occurred while checking for PyxelRest update on Microsoft Excel shutdown.", ex);
111-
}
11297
}
11398

11499
internal string GetVersion()

0 commit comments

Comments
 (0)