コード例 #1
0
 public static RainRadarImage[] GetRadarImages(RainRadarLocations location, RainRadarTimes time, RainRadarDistance distance)
 {
     try
     {
         var webRequest = (HttpWebRequest)WebRequest.Create(GenerateUrl(location, time, distance));
         webRequest.UserAgent = Common.UserAgent;
         webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
         webRequest.AllowAutoRedirect      = true;
         RainRadarImage[] images;
         using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
         {
             var stream = webResponse.GetResponseStream();
             images = RainRadarImage.GetRadarImages(stream);
         }
         return(images);
     }
     catch (Exception e)
     {
         if (e.GetType() != typeof(WebException))
         {
             throw new Exception("An error occured while retreiving the requested rain radar.", e);
         }
         var webE = (WebException)e;
         if (((HttpWebResponse)webE.Response).StatusCode == HttpStatusCode.NotImplemented)
         {
             throw new Exception("The requested rain radar format does not exist.", e);
         }
         throw new Exception("An error occured while retreiving the requested rain radar.", e);
     }
 }
コード例 #2
0
        private static string TimeToCode(RainRadarTimes time)
        {
            switch (time)
            {
            case RainRadarTimes.TwoHoursEvery7Mins:
                return("2h_7min");

            case RainRadarTimes.EightHoursHourly:
                return("8h_hourly");

            default: goto case RainRadarTimes.TwoHoursEvery7Mins;
            }
        }
コード例 #3
0
 private static string GenerateUrl(RainRadarLocations location, RainRadarTimes times, RainRadarDistance distance)
 {
     return(Common.BaseUrl + "/publicData/" + LocationToCode(location) + "_" + TimeToCode(times) + "_" + DistanceToCode(distance));
 }