public FileDownloader(string url, string fullPathWhereToSave, IRecordAnEvent logger) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } if (string.IsNullOrEmpty(fullPathWhereToSave)) { throw new ArgumentNullException("fullPathWhereToSave"); } this._url = url; this._fullPathWhereToSave = fullPathWhereToSave; _logger = logger; }
public static void Readxml(string filePath, string connectionString, IRecordAnEvent logger) { decimal latitudeValue = 0.00m; decimal longitudeValue = 0.00m; string stationIDValue = ""; string locationValue = ""; DateTime today = DateTime.Now; DateTime observationDateTime = today; string weatherConditionValue = ""; decimal temperatureValue = 0.00m; int humidityValue = 0; string content = null; using (StreamReader reader = new StreamReader(filePath)) { content = reader.ReadToEnd(); } // reassign & to & so XML can be read using (StreamWriter writer = new StreamWriter(filePath)) { writer.Write(content.Replace("& ", "& ")); } XPathDocument doc = new XPathDocument(filePath); XPathNavigator nav = doc.CreateNavigator(); while (true) { foreach (XPathNavigator latitude in nav.Select("current_observation/latitude")) { latitudeValue = (decimal)latitude.ValueAsDouble; } if (latitudeValue == 0.00m) { break; } foreach (XPathNavigator longitude in nav.Select("current_observation/longitude")) { longitudeValue = (decimal)longitude.ValueAsDouble; } if (longitudeValue == 0.00m) { break; } foreach (XPathNavigator station_id in nav.Select("current_observation/station_id")) { stationIDValue = station_id.Value; } foreach (XPathNavigator location in nav.Select("current_observation/location")) { locationValue = location.Value; } foreach (XPathNavigator observation_time_rfc822 in nav.Select("current_observation/observation_time_rfc822")) { CultureInfo provider = CultureInfo.InvariantCulture; observationDateTime = DateTime.ParseExact(observation_time_rfc822.Value, "ddd, dd MMM yyyy HH:mm:ss zzz", provider); } foreach (XPathNavigator weather in nav.Select("current_observation/weather")) { weatherConditionValue = weather.Value; } foreach (XPathNavigator temp_f in nav.Select("current_observation/temp_f")) { temperatureValue = (decimal)temp_f.ValueAsDouble; } foreach (XPathNavigator relative_humidity in nav.Select("current_observation/relative_humidity")) { humidityValue = relative_humidity.ValueAsInt; } try { using (SqlConnection connection = new SqlConnection(connectionString)) { WeatherDataService WeatherDataService = new WeatherDataService(); WeatherDataService.StationID = stationIDValue; WeatherDataService.Location = locationValue; WeatherDataService.Latitude = latitudeValue; WeatherDataService.Longitude = longitudeValue; WeatherDataService.ObservationTime = observationDateTime; WeatherDataService.WeatherCondition = weatherConditionValue; WeatherDataService.Temperature = temperatureValue; WeatherDataService.Humidity = humidityValue; WeatherDataService.CreationDateTime = today; connection.Insert(WeatherDataService); } } catch (SqlException) {} break; } }
public RunEarthQuake(IRecordAnEvent logger) { _logger = logger; }
public static bool DownloadFile(string url, string fullPathWhereToSave, int timeoutInMilliSec, IRecordAnEvent logger) { return(new FileDownloader(url, fullPathWhereToSave, logger).StartDownload(timeoutInMilliSec)); }