/// <summary> /// Get a list of pre-subscription data. /// </summary> /// <returns>List of <see cref="Presubscription"/></returns> /// <example> /// <code> /// try /// { /// var presubscriptions = connectApi.ListPresubscriptions(); /// foreach (var item in presubscriptions) /// { /// Console.WriteLine(item); /// } /// return presubscriptions; /// } /// catch (MbedCloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <exception cref="CloudApiException">CloudApiException</exception> public Presubscription[] ListPresubscriptions() { try { return(SubscriptionsApi.GetPreSubscriptions()?.Select(p => Presubscription.Map(p))?.ToArray()); } catch (mds.Client.ApiException ex) { throw new CloudApiException(ex.ErrorCode, ex.Message, ex.ErrorContent); } }
private List <Object> GetMethodParams(MethodInfo methodInfo, JObject argsJsonObj) { var @params = methodInfo.GetParameters(); var serialisedParams = new List <object>(); foreach (var p in @params) { var paramType = p.ParameterType; if (paramType.IsPrimitive || paramType == typeof(String)) { var paramValue = GetParamValuePrimitive(p, paramType, argsJsonObj); serialisedParams.Add(paramValue); } else if (paramType.IsArray) { // currently not generic because EndpointName is sent as device_id and as Presubscription is generated, it cannot be decorated with a name attribute to correct this. var arrayType = paramType.GetElementType(); if (arrayType == typeof(Presubscription)) { var stringArg = GetParamValuePrimitive(p, paramType, argsJsonObj) as string; var json = JsonConvert.DeserializeObject(stringArg, typeof(JObject[])) as JObject[]; var presubList = new List <Presubscription>(); foreach (var item in json) { var presub = new Presubscription(); presub.DeviceId = item["device_id"].Value <string>(); var pathList = new List <string>(); foreach (var path in item["resource_paths"]) { pathList.Add(path.Value <string>()); } presub.ResourcePaths = pathList; presubList.Add(presub); } serialisedParams.Add(presubList.ToArray()); } } else if (paramType == typeof(DateTime)) { var val = argsJsonObj[p.Name.ToUpper()].Value <string>(); var isDate = DateTime.TryParseExact(val, "MM/dd/yyyy HH:mm:ss", null, DateTimeStyles.None, out DateTime dateValue); if (isDate) { var dateWithMilli = argsJsonObj[p.Name.ToUpper()].Value <DateTime>(); serialisedParams.Add(dateWithMilli); } else { serialisedParams.Add(null); } } else if (p.Name == "timeout") { var val = argsJsonObj[p.Name.ToUpper()].Value <int>(); serialisedParams.Add(val * 1000); } else { var properties = paramType.GetProperties(); var vals = new JObject(); foreach (var prop in properties) { var propertyInst = paramType.GetProperty(prop.Name); if (propertyInst != null) { if (propertyInst.PropertyType.Name == "Filter") { var filterJson = GetParamValue(propertyInst, argsJsonObj); var filterJsonString = filterJson != null?filterJson.ToString() : ""; if (filterJsonString.Contains("filter_string")) { var filterJsonObj = JsonConvert.DeserializeObject(filterJsonString) as JObject; var dict = filterJsonObj["filter_json"].ToString(); var obj = JToken.FromObject(new Filter(dict, string.IsNullOrEmpty(dict))); vals[propertyInst.Name] = obj; } else { var filterJToken = JToken.FromObject(new Filter(filterJsonString, string.IsNullOrEmpty(filterJsonString))); vals[propertyInst.Name] = filterJToken; } } else if (propertyInst.PropertyType == typeof(List <string>)) { var paramValue = GetParamValue(propertyInst, argsJsonObj); if (paramValue != null) { var list = JsonConvert.DeserializeObject <List <string> >(paramValue.ToString()); vals[propertyInst.Name] = JToken.FromObject(list); } else { vals[propertyInst.Name] = paramValue; } } else { var paramValue = GetParamValue(propertyInst, argsJsonObj); vals[propertyInst.Name] = paramValue; } } } try { var obj = JsonConvert.DeserializeObject(vals.ToString(), paramType); serialisedParams.Add(obj); } catch (JsonReaderException) { serialisedParams.Add(null); } } } if (serialisedParams.Count < @params.Length) { while (serialisedParams.Count < @params.Length) { serialisedParams.Add(null); } } return(serialisedParams); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns> /// true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false. /// </returns> public bool Equals(Presubscription other) { return(DeviceId == other.DeviceId && ResourcePaths.SequenceEqual(other.ResourcePaths)); }