示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 /// <summary>
 /// ToJson
 /// </summary>
 /// <param name="payload"></param>
 /// <returns></returns>
 public static string ToJson(this DeviceDescriptionPayload payload)
 {
     return(JsonSerializer.Serialize(payload));
 }