public async Task Invoke() { var request = new HttpRequestMessage(HttpMethod.Get, "http://api.gios.gov.pl/pjp-api/rest/aqindex/getIndex/129"); var client = _clientFactory.CreateClient(); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { var answer = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <PollutionDataDTO>(answer); var converted = new PollutionData() { indexLevel = data.StIndexLevel.IndexLevelName, no2IndexLevel = data.No2IndexLevel.IndexLevelName, coIndexLevel = data.CoIndexLevel.IndexLevelName, pm25IndexLevel = data.Pm25IndexLevel.IndexLevelName, }; await _AirPollutionContext.Pollutants.AddAsync(converted); await _AirPollutionContext.SaveChangesAsync(); } else { Console.WriteLine($"StatusCode: {response.StatusCode}"); } }
void FakeData() { Debug.Log("FakeIt"); newData = new PollutionData(); newData.Randomize(); Dispatch(newData); }
void Dispatch(PollutionData newData) { foreach (GameObject go in toNotify) { go.SendMessage("UpdateValue", newData); } }
public void UpdateValue(PollutionData pd) { Vector3 s = new Vector3(pd.pm10, pd.pm25, pd.co2); s = Vector3.one + s * 2; goalScale = s; }
private static async Task SendMessagesToEventHub(PollutionData data) { try { await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(data.ToJSON()))); } catch (Exception ex) { Console.WriteLine($"{DateTime.Now} > Exception: {ex.Message}"); } }
IEnumerator PerformCheck() { while (true) { finalUrl = urlBase + PollutionLogin._username + urlFeeds + feed + "/data/last" + urlKey + PollutionLogin._apiKey; // WWWForm form = new WWWForm(); //form.AddField("myField", "myData"); // using (UnityWebRequest www = UnityWebRequest.Get(finalUrl)) { yield return(www.SendWebRequest()); // if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { //Debug.Log("Form upload complete!"); //Debug.Log(www.downloadHandler.text); // JSONObject = JSON.Parse(jsonString); newData = new PollutionData(www.downloadHandler.text); if (oldRawData == null || !www.downloadHandler.text.Equals(oldRawData)) { oldRawData = www.downloadHandler.text; Debug.Log("Updated data"); Dispatch(newData); } else { // If it's the same Debug.Log("No update (same data)"); } } } yield return(new WaitForSeconds(timingUpdate)); } }