/// <summary> /// 更新某个设备 /// </summary> /// <param name="para"></param> /// <param name="deviceId"></param> /// <param name="token"></param> /// <returns></returns> public ResultMsg <Result> UpdateDeviceByDeviceId(DeviceAddParas para, int deviceId, string token = null) { var result = new ResultMsg <Result>(); //验证 var vry = PrimaryKeyVerify(deviceId, ref token); if (!vry.IsSuccess()) { vry.CopyTo(result); return(result); } //1、先定义该API接口路径,可以从http://api.nlecloud.com/页面的得知 String apiPath = String.Format("{0}/{1}", mApiHost, NLECloudAPIUrl.DeviceUpdateUrl); //2、根据该API接口的请求参数中 得知需要创建个URI Parameters String类型参数,所以该参数直接跟在apiPath中 apiPath = apiPath.Replace("{deviceid}", deviceId.ToString());//将API地址中的{projectid}替换成真实项目ID //3、由于调用该API需要Token,所以我们定义了一个通用的对象HttpReqEntity,在AccessToken当成头部请求信息提交过去 HttpReqEntity req = new HttpReqEntity(); req.Method = HttpMethod.PUT; req.Datas = JsonFormatter.Serialize(para); req.Headers.Add("AccessToken", token); //4、定义该API接口返回的对象 result = RequestAPIHelper.RequestServer <HttpReqEntity>(apiPath, req); return(result); }
/// <summary> /// 添加一个新设备 /// </summary> /// <param name="para"></param> /// <param name="token"></param> /// <returns></returns> public ResultMsg <int> AddDevice(DeviceAddParas para, string token = null) { var result = new ResultMsg <int>(); #region --ToUse-- //if (String.IsNullOrEmpty(txtToken)) //if (!vry.IsSuccess()) //{ // vry.CopyTo(result); // return result; //} #endregion //1、先定义该API接口路径,可以从http://api.nlecloud.com/页面的得知 String apiPath = String.Format("{0}/{1}", mApiHost, NLECloudAPIUrl.Devices); //2、根据该API接口 的请求参数中 得知需要创建个URI Parameters String类型参数,所以该参数直接跟在apiPath中 //apiPath = apiPath.Replace("{projectId}", projectId.ToString());//将API地址中的{gatewayTag}替换成真实设备标识 //3、由于调用该API需要Token,所以我们定义了一个通用的对象HttpReqEntity,在AccessToken当成头部请求信息提交过去 HttpReqEntity req = new HttpReqEntity(); req.Method = HttpMethod.POST; req.Datas = JsonFormatter.Serialize(para); req.Headers.Add("AccessToken", token); //4、定义该API接口返回的对象 result = RequestAPIHelper.RequestServer <HttpReqEntity, int>(apiPath, req); return(result); }
/// <summary> /// 添加新设备 /// </summary> /// <returns></returns> public ResultMsg <int> AddDevice() { DeviceAddParas deviceAddPara = new DeviceAddParas() { Protocol = 1, IsTrans = true, ProjectIdOrTag = "6571", Name = "新添加的设备", Tag = "newesetDevice", }; ResultMsg <int> opResult = SDK.AddDevice(deviceAddPara, this.Token); return(opResult); }
/// <summary> /// 更新设备 /// </summary> /// <returns></returns> public ResultMsg <Result> UpdateDevice() { DeviceAddParas deviceUpdatePara = new DeviceAddParas() { Protocol = 1, IsTrans = true, ProjectIdOrTag = "6571",//项目ID Name = "新添加的设备名字被更新了", Tag = "newesetDevice", }; int deviceId = 6637; ResultMsg <Result> opResult = SDK.UpdateDeviceByDeviceId(deviceUpdatePara, deviceId, this.Token); return(opResult); }