Beispiel #1
0
        private static string LocationToCode(RainRadarLocations location)
        {
            switch (location)
            {
            case RainRadarLocations.AllNewZealand:
                return("rainRadarNZ");

            case RainRadarLocations.BayOfPlenty:
                return("rainRadarBOP");

            case RainRadarLocations.Auckland:
                return("rainRadarAuckland");

            case RainRadarLocations.HawkesBay:
                return("rainRadarMahia");

            case RainRadarLocations.NewPlymouth:
                return("rainRadarNew-plymouth");

            case RainRadarLocations.Wellington:
                return("rainRadarWellington");

            case RainRadarLocations.Canterbury:
                return("rainRadarChristchurch");

            case RainRadarLocations.Westland:
                return("rainRadarWestland");

            case RainRadarLocations.Southland:
                return("rainRadarInvercargill");

            default:
                goto case RainRadarLocations.AllNewZealand;
            }
        }
Beispiel #2
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);
     }
 }
Beispiel #3
0
 private static string GenerateUrl(RainRadarLocations location, RainRadarTimes times, RainRadarDistance distance)
 {
     return(Common.BaseUrl + "/publicData/" + LocationToCode(location) + "_" + TimeToCode(times) + "_" + DistanceToCode(distance));
 }