public async Task <SiteListResponse> GetAllSites(string resolution = "daily")
        {
            string url = "http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/sitelist?res=" + resolution + "&key=" + _apiKey;

            var request        = (HttpWebRequest)WebRequest.Create(url);
            var response       = (HttpWebResponse)request.GetResponse();
            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            SiteListResponse siteListResponse = JsonConvert.DeserializeObject <SiteListResponse>(responseString);

            return(siteListResponse);
        }
Exemple #2
0
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            try
            {
                SiteListResponse response = RecoveryServicesClient.GetAzureSiteRecoverySites(this.Vault);

                this.WriteSites(response.Sites);
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemple #3
0
        public async Task <SiteListResponse> GetAllSites(string resolution = "daily")
        {
            string url = "http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/sitelist?res=" + resolution + "&key=" + _apiKey;

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage response = await client.GetAsync(new Uri(url));

                response.EnsureSuccessStatusCode();
                SiteListResponse siteListResponse = JsonConvert.DeserializeObject <SiteListResponse>(await response.Content.ReadAsStringAsync());

                return(siteListResponse);
            }
        }
Exemple #4
0
        public async Task <Location> GetClosestSite(GeoCoordinate coordinate)
        {
            // Create client
            MetOfficeDataPointClient client = new MetOfficeDataPointClient(_apiKey);

            // Get all sites
            SiteListResponse siteListResponse = await client.GetAllSites();

            // Find nearest coordinates
            GeoCoordinate nearest = siteListResponse.Locations.Location.Select(x => new GeoCoordinate(x.Latitude, x.Longitude)).OrderBy(x => x.GetDistanceTo(coordinate)).First();

            // Find site matching nearest coordinates
            Location location = siteListResponse.Locations.Location.Find(x => x.Latitude == nearest.Latitude && x.Longitude == nearest.Longitude);

            return(location);
        }
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            try
            {
                this.WriteWarningWithTimestamp(
                    string.Format(
                        Properties.Resources.CmdletWillBeDeprecatedSoon,
                        this.MyInvocation.MyCommand.Name));

                SiteListResponse response = RecoveryServicesClient.GetAzureSiteRecoverySites(this.Vault);

                this.WriteSites(response.Sites);
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            // Create client
            MetOfficeDataPointClient client = new MetOfficeDataPointClient("<API_KEY>");

            // Get all sites
            SiteListResponse siteListResponse = client.GetAllSites().Result;

            // Get available forcasts
            AvailableTimeStampsResponse availableTimeStampsResponse = client.GetAvailableTimestamps().Result;

            // Get all 3 hourly forecasts
            ForecastResponse3Hourly forecastResponse3Hourly = client.GetForecasts3Hourly().Result;

            // Get daily forecasts for site 14
            ForecastResponseDaily forecastResponseDaily = client.GetForecastsDaily(14).Result;

            // Get historical observations
            ForecastResponse3Hourly historicalResponse = client.GetHistoricalObservations().Result;

            // Get closest site
            GeoCoordinate coordinate = new GeoCoordinate(51.508363, -0.163006);
            Location      location   = client.GetClosestSite(coordinate).Result;
        }