예제 #1
0
        private async Task GetDustData()
        {
            try
            {
                string url = new StringBuilder().AppendFormat("https://api.waqi.info/feed/geo:{0};{1}/?token={2}",
                                                              latitude, longitude, Air_Access_Key).ToString();

                JObject obj = await httpClient.Requester(url, "GET", null);

                //Console.WriteLine("# Public Quality.\n{0}", obj.ToString());

                if (obj.GetValue(HTTPPacket.Key_Air_Status).ToString().Equals("ok"))
                {
                    JObject dataObj = JObject.Parse(obj[HTTPPacket.Key_Air_Data][HTTPPacket.Key_Air_Info].ToString());
                    string  pm10    = dataObj[HTTPPacket.Key_Air_PM10][HTTPPacket.Key_Air_Value].ToString();
                    string  pm25    = dataObj[HTTPPacket.Key_Air_PM25][HTTPPacket.Key_Air_Value].ToString();
                    Console.WriteLine("[Public API] - Air Quality : pm10 ({0}), pm25 ({1})", pm10, pm25);
                    environmentData.SetDust(pm10, pm25);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
예제 #2
0
        private async Task RequestCreateCode()
        {
            try
            {
                JObject obj = await httpClient.Requester(HTTPPacket.Url_Create_ID, "POST", null);

                string resCode = obj.GetValue(HTTPPacket.Param_Res_Code).ToString();
                Console.WriteLine("[Register] - Create Product Result.\n{0}", obj.ToString());
                if (resCode.Equals(HTTPPacket.Res_Success))
                {
                    Tb_ProductCode.Text = obj.GetValue(HTTPPacket.Param_Device_ID).ToString();
                }
                else
                {
                    ShowErrorMessage("제품 코드 생성에 실패하였습니다.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ShowErrorMessage("서버와 연결이 불안정합니다. 잠시 후 다시 시도해주세요.");
            }
        }
예제 #3
0
        private async Task <JObject> GetUserSettingData()
        {
            JObject infoObj = null;

            try
            {
                JObject paramObj = new JObject();
                paramObj.Add(HTTPPacket.Param_Device_ID, SystemEnv.GetProductKey());
                JObject obj = await httpClient.Requester(HTTPPacket.Url_Get_Info, "POST", paramObj);

                string resCode = obj.GetValue(HTTPPacket.Param_Res_Code).ToString();
                Console.WriteLine("[Dislay] User Setting Data.\n{0}", obj.ToString());
                if (resCode.Equals(HTTPPacket.Res_Success))
                {
                    JArray arrayObj = JArray.Parse(obj.GetValue(HTTPPacket.Param_Res_Rows).ToString());
                    infoObj = JObject.FromObject(arrayObj[0]);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            return(infoObj);
        }