public void PutProperty(string deviceId, string propertyDesc, string postData, DeviceMetadataServiceDelegate callback) { //Validate the current sitename. if (!CommonUtil.ValidateCurrentSiteName()) { return; } var endpointUrl = SET_ATTRIBUTES_URL; endpointUrl = endpointUrl.Replace("{device_id}", deviceId); Attributes attribute; _attributes.TryGetValue(propertyDesc, out attribute); if (attribute != null) { var attributName = attribute.name; endpointUrl = endpointUrl + "/" + attributName; LogService.GetLog().Debug(string.Format("Set Property {0} with value {1} for device {2}", attribute.name, postData, deviceId)); } var backgroundService = new BackgroundServiceUtil(); backgroundService.RunAsync(() => { var httpClient = new HttpClient(endpointUrl, HttpMethodEnum.PUT, postData, USERNAME, PASSWORD); var httpresponse = httpClient.Put(); callback.Invoke(httpresponse); }); }
public void GetDeviceProperties(string deviceId, GetDeviceMetadataDelegate callback) { //Validate the current sitename. if (!CommonUtil.ValidateCurrentSiteName()) { return; } var backgroundService = new BackgroundServiceUtil(); LogService.GetLog().Debug(string.Format("Get Properties for device {0}", deviceId)); backgroundService.RunAsync(() => { var device_url = GET_ATTRIBUTES_URL + "/" + deviceId; var httpClient = new HttpClient(device_url, HttpMethodEnum.GET, USERNAME, PASSWORD); var httpresponse = httpClient.Get(""); var deviceMetadataModel = JsonUtil.FromJson <DeviceMetadataModel>(httpresponse); var deviceModels = deviceMetadataModel.deviceModels; if (deviceModels != null) { DeviceModels deviceModel = null; foreach (var model in deviceModels) { if (model.attributes != null && model.attributes.Count > 0) { LogService.GetLog().Debug(string.Format ("No of Properties for device {0} retrieved : {1}", deviceId, model.attributes.Count)); deviceModel = model; break; } } _attributes = new Dictionary <string, Attributes>(); if (deviceModel != null && deviceModel.attributes != null) { foreach (var attribute in deviceModel.attributes) { _attributes.Add(attribute.description, attribute); } } callback.Invoke(_attributes); } }); }
public void GetMessage(Dictionary <string, string> parameters, MessageServiceDelegate callback) { //Validate the current sitename. if (!CommonUtil.ValidateCurrentSiteName()) { return; } var backgroundService = new BackgroundServiceUtil(); backgroundService.RunAsync(() => { var httpClient = new HttpClient(MESSAGE_URL, HttpMethodEnum.GET, USERNAME, PASSWORD); var queryString = HttpUtil.QueryString(parameters); var httpresponse = httpClient.Get(queryString); callback.Invoke(httpresponse); }); }