@@ -59,67 +59,71 @@ protected override void OnStartup(StartupEventArgs e)
5959 bool disableTelemetry = ( AppOptions . Telemetry == false ) ;
6060 TelemetryHelper th = new TelemetryHelper ( disableTelemetry ) ;
6161
62- string serverName = ( ( App ) Application . Current ) . AppOptions ? . Server ;
63- string databaseName = ( ( App ) Application . Current ) . AppOptions ? . Database ;
64- string cubeName = ModelHelper . GetModelName ( serverName , databaseName ) ;
65- if ( serverName != null && databaseName != null )
62+ try
6663 {
67- try
64+ string serverName = ( ( App ) Application . Current ) . AppOptions ? . Server ;
65+ string databaseName = ( ( App ) Application . Current ) . AppOptions ? . Database ;
66+ string cubeName = ModelHelper . GetModelName ( serverName , databaseName , th ) ;
67+ if ( serverName != null && databaseName != null )
6868 {
69- if ( string . IsNullOrEmpty ( cubeName ) )
69+ try
7070 {
71- ShowMessage ( "Power BI has an empty model or it is connected to an unkonwn external dataset. You cannot connect Excel." ) ;
72- th . TrackEvent ( "Model not available" ) ;
73- }
74- else if ( ExcelHelper . IsExcelAvailable ( ) )
75- {
76- // TODO: Manage options requested
77- if ( OptionsRequested )
71+ if ( string . IsNullOrEmpty ( cubeName ) )
7872 {
79- // TODO request action / configuration to users
73+ ShowMessage ( "Power BI has an empty model or it is connected to an unkonwn external dataset. You cannot connect Excel." ) ;
74+ th . TrackEvent ( "Model not available" ) ;
8075 }
81-
82- // Create ODC file
83- OdcHelper . CreateOdcFile ( serverName , databaseName , cubeName ) ;
84- var fileName = OdcHelper . OdcFilePath ( ) ;
85-
86- // Open ODC file
87- var p = new Process
76+ else if ( ExcelHelper . IsExcelAvailable ( ) )
8877 {
89- StartInfo = new ProcessStartInfo ( fileName )
78+ // TODO: Manage options requested
79+ if ( OptionsRequested )
9080 {
91- UseShellExecute = true
81+ // TODO request action / configuration to users
9282 }
93- } ;
94- th . TrackEvent ( "Run Excel" ) ;
95- p . Start ( ) ;
83+
84+ RunExcelProcess ( serverName , databaseName , cubeName ) ;
85+ th . TrackEvent ( "Run Excel" ) ;
86+ }
87+ else
88+ {
89+ ShowMessage ( "Excel is not available. Please check whether Excel is correctly installed." ) ;
90+ th . TrackEvent ( "Excel not available" ) ;
91+ }
92+ th . Flush ( ) ;
93+
94+ // Check updates synchronously when Excel starts, no wait for Excel
95+ CheckUpdates ( true ) ;
96+ this . Shutdown ( 0 ) ;
9697 }
97- else
98+ catch ( Exception ex )
9899 {
99- ShowMessage ( "Excel is not available. Please check whether Excel is correctly installed." ) ;
100- th . TrackEvent ( "Excel not available" ) ;
100+ th . TrackException ( ex ) ;
101+ th . Flush ( ) ;
102+ ShowMessage ( "Error launching Excel: " + ex . Message ) ;
101103 }
102- th . Flush ( ) ;
103- // Check updates synchronously when Excel starts, no wait for Excel
104- CheckUpdates ( true ) ;
105- this . Shutdown ( 0 ) ;
106104 }
107- catch ( Exception ex )
105+ else
108106 {
109- th . TrackException ( ex ) ;
107+ th . TrackEvent ( "Configuration incomplete" ) ;
110108 th . Flush ( ) ;
111- ShowMessage ( "Error launching Excel: " + ex . Message ) ;
112109 }
110+
111+ // Check updates asynchronously when there is an error, while displaying the diagnostic message
112+ CheckUpdates ( false ) ;
113+
114+ OpenDiagnosticWindow ( serverName , databaseName ) ;
113115 }
114- else
116+ catch ( Exception ex )
115117 {
116- th . TrackEvent ( "Configuration incomplete" ) ;
118+ // Send any exception to Telemetry
119+ th . TrackException ( ex ) ;
117120 th . Flush ( ) ;
121+ throw ;
118122 }
119123
120- // Check updates asynchronously when there is an error, while displaying the diagnostic message
121- CheckUpdates ( false ) ;
122-
124+ }
125+ private void OpenDiagnosticWindow ( string serverName , string databaseName )
126+ {
123127 //// start application window
124128 MainWindow mw = new MainWindow ( ) ;
125129 mw . diagnosticInfo . Content = $@ "Current configuration
@@ -133,5 +137,22 @@ Check that the file
133137" ;
134138 mw . Show ( ) ;
135139 }
140+
141+ private void RunExcelProcess ( string serverName , string databaseName , string cubeName )
142+ {
143+ // Create ODC file
144+ OdcHelper . CreateOdcFile ( serverName , databaseName , cubeName ) ;
145+ var fileName = OdcHelper . OdcFilePath ( ) ;
146+
147+ // Open ODC file
148+ var p = new Process
149+ {
150+ StartInfo = new ProcessStartInfo ( fileName )
151+ {
152+ UseShellExecute = true
153+ }
154+ } ;
155+ p . Start ( ) ;
156+ }
136157 }
137158}
0 commit comments