예제 #1
0
    public void GetLocalWeather(LocalWeatherInput input, AsyncCallback success, AsyncCallback fail)
    {
        successCallback = success;
        failCallback = fail;
        // create URL based on input paramters
        string apiURL = ApiBaseURL + "weather.ashx?q=" + input.query + "&format=" + "json" + "&extra=" + input.extra + "&num_of_days=" + input.num_of_days + "&date=" + input.date + "&fx=" + input.fx + "&cc=" + input.cc + "&includelocation=" + input.includelocation + "&show_comments=" + input.show_comments + "&callback=" + input.callback + "&key="+FreeAPIKey;
        #if DEBUG
        System.Diagnostics.Debug.WriteLine(apiURL);
        #endif
        // get the web response
        RequestHandler rh = new RequestHandler();
        rh.Process(apiURL,GetLoaclWeatherCallback,fail);

        // serialize the json output and parse in the helper class
        //        LocalWeather lWeather = JsonConvert.DeserializeObject<LocalWeather>(result);
    }
예제 #2
0
 public async void updateRequierdData(int days, AsyncCallback callback, AsyncCallback failCallback)
 {
     
     DateTime today=  DateTime.Now;
     LocalWeatherInput weatherInput = new LocalWeatherInput();
     weatherInput.num_of_days = days.ToString();
     callback.Invoke(new Task((object obj) => { },
                 string.Format(" {0} place will be updated!", places.Count)));
     try
     {
         
         foreach (string langName in VoiceCommandInfo.AvailableLanguages)
         {
             if (VoiceCommandService.InstalledCommandSets.ContainsKey(langName))
             {
                 VoiceCommandSet widgetVcs = VoiceCommandService.InstalledCommandSets[langName];
                 widgetVcs.UpdatePhraseListAsync("place", places.Keys);
             }
         }
     }
     catch (Exception e)
     {
         BugReporter.GetInstance().report(e);
     }
     foreach (KeyValuePair<string, Place> dictionaryEntry in places)
     {
         Place place =  dictionaryEntry.Value;
         if (place.LastUpdateTime > DateTime.Now.AddHours(-2) && !Settings.GetInstance().APIKey.Any())
         {
             callback.Invoke(new Task((object obj) => { },
                 "current weather data for " + place.Name + " is not outdated yet!"));
             continue;
         }
         if (place._useName)
             weatherInput.query = place.Name;
         else
             weatherInput.query = place.Latitude + "," + place.Longitude;
         SaveWeatherDataClass saver = new SaveWeatherDataClass(place.Name,callback);
         new FreeAPI().GetLocalWeather(weatherInput,saver.SaveWeatherData, failCallback);
         Thread.Sleep(1000);
     }
     
 }