11using CommandLine ;
22using System ;
3- using System . Collections . Generic ;
4- using System . Configuration ;
53using System . Data ;
64using System . Linq ;
75using System . Windows ;
86using System . Diagnostics ;
97using AutoUpdaterDotNET ;
10- using System . Linq . Expressions ;
118
129namespace AnalyzeInExcel
1310{
@@ -17,15 +14,20 @@ namespace AnalyzeInExcel
1714 public partial class App : Application
1815 {
1916 public Options AppOptions ;
20- protected override void OnStartup ( StartupEventArgs e )
17+
18+ public void CheckUpdates ( bool synchronous = true )
2119 {
2220 AutoUpdater . HttpUserAgent = "AutoUpdater" ;
2321 AutoUpdater . ShowSkipButton = true ;
2422 AutoUpdater . ShowRemindLaterButton = true ;
2523 AutoUpdater . LetUserSelectRemindLater = true ;
26- AutoUpdater . Synchronous = true ;
27- AutoUpdater . Start ( "https://cdn.sqlbi.com/updates/AnalyzeInExcelAutoUpdater.xml" ) ;
24+ AutoUpdater . Synchronous = synchronous ;
25+ // The random number guarantees that the web client cache is not used (it is applied often even though internally the policy is disabled)
26+ AutoUpdater . Start ( $@ "https://cdn.sqlbi.com/updates/AnalyzeInExcelAutoUpdater.xml?random={ new Random ( ) . Next ( ) } ") ;
27+ }
2828
29+ protected override void OnStartup ( StartupEventArgs e )
30+ {
2931 // Read configuration
3032 var result = Parser . Default . ParseArguments < Options > ( e . Args )
3133 . WithNotParsed ( errors => MessageBox . Show ( "Invalid configuration, check the pbitool.json file\n " + String . Join ( ";" , from err in errors select err . ToString ( ) ) ) )
@@ -56,6 +58,8 @@ protected override void OnStartup(StartupEventArgs e)
5658 tc . TrackEvent ( "Run Excel" ) ;
5759 p . Start ( ) ;
5860 tc . Flush ( ) ;
61+ // Check updates synchronously when Excel starts, no wait for Excel
62+ CheckUpdates ( true ) ;
5963 this . Shutdown ( 0 ) ;
6064 }
6165 catch ( Exception ex )
@@ -71,6 +75,9 @@ protected override void OnStartup(StartupEventArgs e)
7175 tc . Flush ( ) ;
7276 }
7377
78+ // Check updates asynchronously when there is an error, while displaying the diagnostic message
79+ CheckUpdates ( false ) ;
80+
7481 //// start application window
7582 MainWindow mw = new MainWindow ( ) ;
7683 mw . diagnosticInfo . Content = $@ "Current configuration
0 commit comments