public void StartSubscribe() { if (mqttClient != null && mqttClient.IsConnected) { mqttClient.Subscribe(new string[] { SystemEnv.GetProductKey() }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE }); } }
private async Task <List <string> > GetUserImageList() { List <string> fileNames = new List <string>(); try { JObject paramObj = new JObject(); paramObj.Add(HTTPPacket.Param_Device_ID, SystemEnv.GetProductKey()); JObject obj = await httpClient.Requester(HTTPPacket.Url_Get_IMGs, "POST", paramObj); string resCode = obj.GetValue(HTTPPacket.Param_Res_Code).ToString(); Console.WriteLine("[Display] User IMG Resource.\n{0}", obj.ToString()); if (resCode.Equals(HTTPPacket.Res_Success)) { JArray arrayObj = JArray.Parse(obj.GetValue(HTTPPacket.Param_Res_Rows).ToString()); foreach (JObject imgObj in arrayObj.Children <JObject>()) { string fileName = imgObj.GetValue(HTTPPacket.Param_IMG_Name).ToString(); fileNames.Add(fileName); } } } catch (Exception e) { Console.WriteLine(e.StackTrace); } return(fileNames); }
private async Task DownloadIMGFiles(string folderPath, List <string> fileNames) { DirectoryInfo directory = new DirectoryInfo(folderPath); List <string> existingFiles = new List <string>(); foreach (FileInfo info in directory.GetFiles()) { existingFiles.Add(info.Name); } List <string> downloadFileNames = new List <string>(); foreach (string fileName in fileNames) { if (!existingFiles.Contains(fileName)) { downloadFileNames.Add(fileName); } } foreach (string fileName in downloadFileNames) { StringBuilder urlStr = new StringBuilder(); if (folderPath.Equals(SystemEnv.DefaultFolderPath)) { urlStr.AppendFormat(@"{0}/{1}/{2}/{3}", HTTPPacket.Url_IMG_Downlaod, Download_Type_Default, fileName, "0"); } else { urlStr.AppendFormat(@"{0}/{1}/{2}/{3}", HTTPPacket.Url_IMG_Downlaod, Download_Type_User, fileName, SystemEnv.GetProductKey()); } string filePath = folderPath + @"/" + fileName; Console.WriteLine("> Downlaod Url : {0}", urlStr); await httpClient.DownloadFile(new Uri(urlStr.ToString()), filePath); } }
public async Task <bool> Connect() { await Task.Run(() => { try { mqttClient = new MqttClient(BROKER_IP); mqttClient.ConnectionClosed += MqttClient_ConnectionClosed; mqttClient.MqttMsgPublishReceived += MqttClient_MqttMsgPublishReceived; mqttClient.Connect(SystemEnv.GetProductKey() + SystemEnv.PRODUCT_TYPE); } catch (MqttConnectionException e) { Console.WriteLine(e.StackTrace); } }); Console.WriteLine("[MQTT] - Connect Result : {0}", mqttClient.IsConnected); return(mqttClient != null && mqttClient.IsConnected); }
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); }