/// <summary> /// 上传控制指令 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="facilitySerialnum"></param> /// <returns></returns> public dynamic UploadControlResult(AwEntity entity, IApiTransport transport, ControlResult controlResult) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } //if (controlResult.FacilityCode.IsNullOrWhiteSpace()) throw new ArgumentNullException("facilitySerialnum"); Guard(entity); entity.Description = "上传控制指令"; entity.DataBlockObject.DataContentRequest.ControlDataBlock = new ControlDataBlock() { ControlResults = new[] { new ControlResult() { Serialnum = controlResult.Serialnum, Result = controlResult.Result, Time = controlResult.Time } }.ToList() }; var response = transport.Process(entity); //if (response.Success == ErrorType.NoError) //{ // if (response.Data != null && response.Data != null) // return response.Data; //} //return null; return(response.Success == ErrorType.NoError); }
public bool UploadFarmStatus(AwEntity entity, IApiTransport transport, FarmStatus fs) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } Guard(entity); entity.Description = "上传基地运行记录"; entity.DataBlockObject.DataContentRequest.RuntimeDataBlock = new RuntimeDataBlock() { UploadFarmStatus = fs }; var response = transport.Process(entity); return(response.Success == ErrorType.NoError); }
/// <summary> /// 获取基地下所有设施 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <returns></returns> public IEnumerable <FacilityModel> GetFacilities(AwEntity entity, IApiTransport transport) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } Guard(entity); //entity.Description = "获取所有设施类型"; entity.Description = "获取所有设施"; entity.DataBlockObject.DataContentRequest.QueryDataBlock = new QueryDataBlock() { FarmCode = new QueryFacilitys() { Farm = entity.DataBlockObject.Source.FarmCode } }; var response = transport.Process(entity); if (response.Success != ErrorType.NoError) { return(new List <FacilityModel>()); } if (response.Data == null || response.Data.QueryFacilitys == null) { return(new List <FacilityModel>()); } try { string str = response.Data.QueryFacilitys.ToString(); var ie = ObjectContainer.Current.Resolve <FormatterBase>(DataProtocalType.Json.ToString()) .Deserialize <IEnumerable <FacilityModel> >(str); return(ie); } catch (Exception ex) { XTrace.WriteException(ex); } return(new List <FacilityModel>()); }
/// <summary> /// 获取控制指令 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="facilitySerialnum"></param> /// <returns></returns> public IEnumerable <ControlCmd> GetControlCommand(AwEntity entity, IApiTransport transport, string facilitySerialnum) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (facilitySerialnum.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(facilitySerialnum)); } Guard(entity); entity.Description = "获取控制设备指令"; entity.DataBlockObject.DataContentRequest.ControlDataBlock = new ControlDataBlock() { ControlQueries = new[] { new ControlQuery() { FacilityCode = facilitySerialnum, Time = DateTime.Now } }.ToList() }; ; //使用ControlData基础数据块 var response = transport.Process(entity); if (response.Success == ErrorType.NoError && response.Data != null) { string str = response.Data.ToString(); var cmd = ObjectContainer.Current.Resolve <FormatterBase>(DataProtocalType.Json.ToString()) .Deserialize <IEnumerable <ControlCmd> >(str); return(cmd); } else { return(Enumerable.Empty <ControlCmd>()); } }
/// <summary> /// 添加设施信息 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="addData"></param> /// <returns></returns> public bool AddFacility(AwEntity entity, IApiTransport transport, FacilityModel addData) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (addData == null) { throw new ArgumentNullException(nameof(addData)); } Guard(entity); entity.Description = "添加设施信息"; entity.DataBlockObject.DataContentRequest.ManageDataBlock = new ManageDataBlock() { FacilityAdd = addData }; var response = transport.Process(entity); return(response.Success == ErrorType.NoError); }
/// <summary> /// 查询设备(采集、控制)信息 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="deviceCode"></param> /// <returns></returns> public XResponseMessage QueryDevice(AwEntity entity, IApiTransport transport, string deviceCode) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (deviceCode == null) { throw new ArgumentNullException(nameof(deviceCode)); } Guard(entity); entity.Description = "查询设备信息"; entity.DataBlockObject.DataContentRequest.QueryDataBlock = new QueryDataBlock() { DeviceCode = deviceCode }; var response = transport.Process(entity); return(response); }
/// <summary> /// 添加设备(多媒体设备)信息 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="addDevice"></param> /// <returns></returns> public bool AddMedia(AwEntity entity, IApiTransport transport, MediaData addDevice) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (addDevice == null) { throw new ArgumentNullException(nameof(addDevice)); } Guard(entity); entity.Description = "添加多媒体设备信息"; entity.DataBlockObject.DataContentRequest.ManageDataBlock = new ManageDataBlock() { MediaAdd = addDevice }; var response = transport.Process(entity); return(response.Success == ErrorType.NoError); }
/// <summary> /// 更新设备(采集、控制)信息 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="updateDevice"></param> /// <returns></returns> public bool UpdateDevice(AwEntity entity, IApiTransport transport, DeviceModel updateDevice) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (updateDevice == null) { throw new ArgumentNullException(nameof(updateDevice)); } Guard(entity); entity.Description = "更新设备信息"; entity.DataBlockObject.DataContentRequest.ManageDataBlock = new ManageDataBlock() { DeviceUpdate = updateDevice }; var response = transport.Process(entity); return(response.Success == ErrorType.NoError); }
//public bool UploadDeviceData(AwEntity entity, IApiTransport transport, List<DeviceModel> devices) //{ // if (transport == null) throw new ArgumentNullException("transport"); // Guard(entity); // if (devices == null || !devices.Any()) return false; // entity.Description = "上传设备数据"; // var sds = devices.Select(dev => new SensorData // { // //FacilityCode = dev.FacilitySerialnum, // DeviceCode = dev.Serialnum, // //DeviceType = dev.DeviceTypeSerialnum, // Value = dev.ProcessedValue, // ShowValue = dev.ShowValue, // //Unit = dev.Unit, // Time = dev.UpdateTime // }); // entity.DataBlockObject.DataContentRequest.CollectDataBlock = new CollectDataBlock // { // SensorDatas = sds.ToList() // }; // var response = transport.Process(entity); // return response.Success == ErrorType.NoError; //} /// <summary> /// 上传采集、控制、摄像机设备数据 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="collectData"></param> /// <returns></returns> public bool UploadDeviceData(AwEntity entity, IApiTransport transport, CollectDataBlock collectData) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (collectData == null) { throw new ArgumentNullException(nameof(collectData)); } Guard(entity); entity.Description = "上传设备数据"; entity.DataBlockObject.DataContentRequest.CollectDataBlock = new CollectDataBlock() { SensorDatas = collectData.SensorDatas, MediaDatas = collectData.MediaDatas }; var response = transport.Process(entity); return(response.Success == ErrorType.NoError); }
/// <summary> /// 获取所有设施类型 /// </summary> /// <param name="entity"></param> /// /// <param name="transport"></param> /// <returns></returns> /// <summary> /// 获取设施下所有设备 /// </summary> /// <param name="entity"></param> /// <param name="transport"></param> /// <param name="facilitySerialnum"></param> /// <returns></returns> public dynamic GetFacilityDevices(AwEntity entity, IApiTransport transport, string facilitySerialnum) { if (transport == null) { throw new ArgumentNullException(nameof(transport)); } if (facilitySerialnum.IsNullOrWhiteSpace()) { throw new ArgumentNullException(nameof(facilitySerialnum)); } Guard(entity); entity.Description = "获取设施下所有设备"; entity.DataBlockObject.DataContentRequest.QueryDataBlock = new QueryDataBlock() { Facility = new QueryFacilityDevices() { Facility = facilitySerialnum } }; var sw = new Stopwatch(); sw.Start(); var response = transport.Process(entity); sw.Stop(); var time = sw.ElapsedMilliseconds; if (response.Success != ErrorType.NoError) { return(null); } if (response.Data != null && response.Data.QueryFacilityDevices != null) { return(response.Data.QueryFacilityDevices); } return(null); }