コード例 #1
0
        /// <summary>
        /// Receives a uri and uses this to download a json file and deserialise it into the custom WeatherData object as an async operation.
        /// </summary>
        /// <param name="pwsUri"></param>
        /// <returns></returns>
        private async Task<WeatherData> CombinedWeatherDataAsync(Uri pwsUri)
        {
            // Download Json data
            JsonProvider jsonProvider = new JsonProvider();
            string jsonData = await jsonProvider.DownloadJsonStringAsync(pwsUri);

            // Deserialise Json file into custom object
            JsonDeserializer jsonDeserialize = new JsonDeserializer();
            return await jsonDeserialize.JsonToWeatherDataAsync(jsonData);
        }
コード例 #2
0
        /// <summary>
        /// Generic method for getting the data features of your choosing as a synchronous operation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="location"></param>
        /// <param name="dataFeatures"></param>
        /// <returns></returns>
        public T GetData <T>(PwsGeographicLocation location, WunDataFeatures dataFeatures) where T : IWunData
        {
            UriProvider  uriProvider   = new UriProvider();
            string       pwsIdentifier = GetPwsIdentifier(location);
            Uri          pwsUri        = uriProvider.CreateWunUri(dataFeatures, pwsIdentifier);
            JsonProvider jsonProvider  = new JsonProvider();
            string       jsonData      = jsonProvider.DownloadJsonString(pwsUri);

            return(JsonConvert.DeserializeObject <T>(jsonData));
        }
コード例 #3
0
        /// <summary>
        /// Generic method for getting the data features of your choosing as an asynchronous operation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="location"></param>
        /// <param name="dataFeatures"></param>
        /// <returns></returns>
        public async Task <T> GetDataAsync <T>(PwsGeographicLocation location, WunDataFeatures dataFeatures) where T : IWunData
        {
            UriProvider  uriProvider   = new UriProvider();
            string       pwsIdentifier = GetPwsIdentifier(location);
            Uri          pwsUri        = uriProvider.CreateWunUri(dataFeatures, pwsIdentifier);
            JsonProvider jsonProvider  = new JsonProvider();
            string       jsonData      = await jsonProvider.DownloadJsonStringAsync(pwsUri);

            return(await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <T>(jsonData)));
        }
コード例 #4
0
        /// <summary>
        /// Receives a uri and uses this to download a json file and deserialise it into the custom WeatherData object as an async operation.
        /// </summary>
        /// <param name="pwsUri"></param>
        /// <returns></returns>
        private async Task <WeatherData> CombinedWeatherDataAsync(Uri pwsUri)
        {
            // Download Json data
            JsonProvider jsonProvider = new JsonProvider();
            string       jsonData     = await jsonProvider.DownloadJsonStringAsync(pwsUri);

            // Deserialise Json file into custom object
            JsonDeserializer jsonDeserialize = new JsonDeserializer();

            return(await jsonDeserialize.JsonToWeatherDataAsync(jsonData));
        }
コード例 #5
0
        public void GivenValidUri_WhenCallingDownloadJsonString_ThenStringFileReturned()
        {
            // Arrange
            bool actualResultValue = false;
            UriProvider uriProvider = new UriProvider();
            Uri testUri = uriProvider.CreateWunUri(WunDataFeatures.astronomy, "INORTHLA43");
            JsonProvider jsonProvider = new JsonProvider();

            //Act
            string jsonData = jsonProvider.DownloadJsonString(testUri);
            if (string.IsNullOrEmpty(jsonData) == true)
            {
                actualResultValue = false;
            }
            else
            {
                actualResultValue = true;
            }

            //Assert
            Assert.IsTrue(actualResultValue);
        }