public async Task <bool> Exists(DeviceDescriptionPayload deviceDescription) { bool result = false; try { var query = HttpUtility.ParseQueryString(string.Empty); query["callerId"] = deviceDescription.ChannelId; query["nodeId"] = $"{deviceDescription.NodeId}"; query["hashCode"] = deviceDescription.HashCode; var url = UrlHelper.BuildUrl(Url, "api/description/exists", query); var json = await Transporter.Get(_identity, url); if (!string.IsNullOrEmpty(json)) { var requestResult = json.TryDeserializeObject <RequestResult>(); if (requestResult != null) { result = requestResult.Result; } } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - Exists", e); } return(result); }
public async Task <DeviceDescriptionPayload> Download(string channelId, DeviceVersion deviceVersion) { DeviceDescriptionPayload result = null; try { var query = HttpUtility.ParseQueryString(string.Empty); query["callerId"] = channelId; query["hardwareVersion"] = $"{deviceVersion.HardwareVersion}"; query["softwareVersion"] = $"{deviceVersion.SoftwareVersion}"; query["applicationNumber"] = $"{deviceVersion.ApplicationNumber}"; query["applicationVersion"] = $"{deviceVersion.ApplicationVersion}"; var url = UrlHelper.BuildUrl(Url, "api/description/download", query); var json = await Transporter.Get(_identity, url); if (!string.IsNullOrEmpty(json)) { result = json.TryDeserializeObject <DeviceDescriptionPayload>(); if (result != null) { result.Version = deviceVersion; } } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - Download", e); } return(result); }
public async Task <bool> Upload(DeviceDescriptionPayload deviceDescription) { bool result = false; try { MsgLogger.WriteLine($"upload device description version='{deviceDescription.Version}'"); var postResult = await Transporter.Post(_identity, Url, "api/description/upload", deviceDescription.ToJson()); if (postResult.StatusCode == HttpStatusCode.OK) { result = true; } } catch (Exception e) { MsgLogger.Exception($"{GetType().Name} - Upload", e); } return(result); }
/// <summary> /// ToJson /// </summary> /// <param name="payload"></param> /// <returns></returns> public static string ToJson(this DeviceDescriptionPayload payload) { return(JsonSerializer.Serialize(payload)); }