private void ScrapeStationInfo(Station station) { var stationId = station.StationId; var client = new WebClient(); try { var result = client.DownloadString(Settings.GetStationDetailUrl(stationId)); var referenceStationMatch = ReferencedStationRegex.Match(result); if (referenceStationMatch.Success) { station.ReferencedStationId = int.Parse(referenceStationMatch.Groups["stationid"].Value); var offsetMatch = OffsetRegex.Match(result); station.HeightOffset = new Offset(double.Parse(offsetMatch.Groups["heighthigh"].Value), double.Parse(offsetMatch.Groups["heightlow"].Value)); station.TimeOffset = new Offset(int.Parse(offsetMatch.Groups["timehigh"].Value), int.Parse(offsetMatch.Groups["timelow"].Value)); } else { station.IsHarmonic = true; } station.IsComplete = true; } catch (Exception) { station.IsComplete = false; } }
private int ParseOffset(string offsetString) { _isValidOffset = true; var match = OffsetRegex.Match(offsetString); if (!match.Success) { _isValidOffset = false; return(0); } if (string.IsNullOrEmpty(match.Groups["hours"].Value) && string.IsNullOrEmpty(match.Groups["minutes"].Value) && string.IsNullOrEmpty(match.Groups["seconds"].Value) && string.IsNullOrEmpty(match.Groups["milliseconds"].Value)) { _isValidOffset = false; return(0); } int hours = string.IsNullOrEmpty(match.Groups["hours"].Value) ? 0 : Int32.Parse(match.Groups["hours"].Value); int minutes = string.IsNullOrEmpty(match.Groups["minutes"].Value) ? 0 : Int32.Parse(match.Groups["minutes"].Value); int seconds = string.IsNullOrEmpty(match.Groups["seconds"].Value) ? 0 : Int32.Parse(match.Groups["seconds"].Value); int milliseconds = string.IsNullOrEmpty(match.Groups["milliseconds"].Value) ? 0 : Int32.Parse(match.Groups["milliseconds"].Value); int sign = (match.Groups["plusminus"].Value != "-") ? 1 : (-1); return(sign * (milliseconds + seconds * 1000 + minutes * 60 * 1000 + hours * 60 * 60 * 1000)); }