@@ -173,11 +173,7 @@ public enum HeightUnit
173173 /// <returns>A downloaded time series.</returns>
174174 public static async Task < TimeSeries > FromGHCN ( string siteNumber , TimeSeriesType timeSeriesType = TimeSeriesType . DailyPrecipitation , DepthUnit unit = DepthUnit . Inches )
175175 {
176- // Check internet connection
177- if ( ! await IsConnectedToInternet ( ) )
178- {
179- throw new InvalidOperationException ( "No internet connection." ) ;
180- }
176+
181177
182178 // Check site number
183179 if ( siteNumber . Length != 11 )
@@ -195,6 +191,12 @@ public static async Task<TimeSeries> FromGHCN(string siteNumber, TimeSeriesType
195191 DateTime ? previousDate = null ;
196192 string tempFilePath = Path . Combine ( Path . GetTempPath ( ) , $ "{ siteNumber } .dly") ;
197193
194+ // Check internet connection
195+ if ( ! await IsConnectedToInternet ( ) )
196+ {
197+ throw new InvalidOperationException ( "No internet connection." ) ;
198+ }
199+
198200 try
199201 {
200202
@@ -353,11 +355,7 @@ private static string CreateURLForUSGSDownload(string siteNumber, TimeSeriesType
353355 /// <param name="timeSeriesType">The time series type.</param>
354356 public static async Task < ( TimeSeries TimeSeries , string RawText ) > FromUSGS ( string siteNumber , TimeSeriesType timeSeriesType = TimeSeriesType . DailyDischarge )
355357 {
356- // Check internet connection
357- if ( ! await IsConnectedToInternet ( ) )
358- {
359- throw new InvalidOperationException ( "No internet connection." ) ;
360- }
358+
361359
362360 // Check site number
363361 if ( siteNumber . Length != 8 )
@@ -371,6 +369,12 @@ private static string CreateURLForUSGSDownload(string siteNumber, TimeSeriesType
371369 throw new ArgumentException ( "The time series type cannot be daily precipitation or daily snow." , nameof ( timeSeriesType ) ) ;
372370 }
373371
372+ // Check internet connection
373+ if ( ! await IsConnectedToInternet ( ) )
374+ {
375+ throw new InvalidOperationException ( "No internet connection." ) ;
376+ }
377+
374378 var timeSeries = new TimeSeries ( ) ;
375379 string textDownload = "" ;
376380
@@ -742,9 +746,7 @@ public static async Task<TimeSeries> FromABOM(
742746 DateTime ? startDate = null ,
743747 DateTime ? endDate = null )
744748 {
745- // Check connectivity
746- if ( ! await IsConnectedToInternet ( ) )
747- throw new InvalidOperationException ( "No internet connection." ) ;
749+
748750
749751 // Validate station number (BOM station numbers are typically 6 digits)
750752 if ( string . IsNullOrWhiteSpace ( stationNumber ) || stationNumber . Length < 6 )
@@ -754,6 +756,10 @@ public static async Task<TimeSeries> FromABOM(
754756 if ( timeSeriesType != TimeSeriesType . DailyDischarge && timeSeriesType != TimeSeriesType . DailyStage )
755757 throw new ArgumentException ( "BOM API supports DailyDischarge or DailyStage only." , nameof ( timeSeriesType ) ) ;
756758
759+ // Check connectivity
760+ if ( ! await IsConnectedToInternet ( ) )
761+ throw new InvalidOperationException ( "No internet connection." ) ;
762+
757763 // Set default dates
758764 DateTime sd = startDate ?? new DateTime ( 1800 , 1 , 1 ) ;
759765 DateTime ed = endDate ?? DateTime . Today ;
0 commit comments