/// <summary> /// 处理传感器采集数据 /// </summary> /// <param name="facilityAddDatas"></param> public static async Task <XResponseMessage> ProcessFacilityAddData(IEnumerable <FacilityAddData> facilityAddDatas) { if (facilityAddDatas == null) { throw new ArgumentNullException("facilityAddDatas"); } var result = new XResponseMessage(); var addDatas = facilityAddDatas as IList <FacilityAddData> ?? facilityAddDatas.ToList(); if (addDatas.Count > 0 && addDatas != null) { try { addDatas.ForEach(async item => { // 添加设施 var facilityDb = await AddFacility(item); // 添加设备 await AddDevice(item, facilityDb); // 添加摄像机 await AddCamera(item, facilityDb); }); } catch (Exception ex) { return(ResultHelper.CreateExceptionMessage(ex, "添加设施、设备、摄像机出错")); } } return(ResultHelper.CreateMessage("", ErrorType.NoError)); }
private static async Task <XResponseMessage> ProcessQueryFacilitys(QueryDataBlock cd, dynamic data) { XResponseMessage xResponseMessage = null; if (cd.FarmCode != null) { var farm = cd.FarmCode.Farm; var result = await QueryDataProcessor.ProcessGetFacilities(farm); if (result != null && result.Success != ErrorType.NoError) { xResponseMessage = result; xResponseMessage.IsTrue = true; } if (result != null) { if (!result.Message.IsNullOrWhiteSpace()) { xResponseMessage.Message += result.Message + " "; } if (result.Data != null) { data.QueryFacilitys = result.Data; } } } xResponseMessage.IsTrue = false; return(xResponseMessage); }
private static async Task <XResponseMessage> ProcessQueryFacilityType(QueryDataBlock queryDataBlock, dynamic data) { XResponseMessage xResponseMessage = null; if (queryDataBlock.FacilityType) { var result = await QueryDataProcessor.ProcessFacilityTypeGet(); if (result != null && result.Success != ErrorType.NoError) { xResponseMessage = result; xResponseMessage.IsTrue = true; } if (result != null) { if (!result.Message.IsNullOrWhiteSpace()) { xResponseMessage.Message += result.Message + " "; } if (result.Data != null) { data.QueryFacilityType = result.Data; } } } xResponseMessage.IsTrue = false; return(xResponseMessage); }
/// <summary> /// 处理上传基地状态 /// </summary> /// <param name="cd"></param> /// <param name="data"></param> /// <param name="message"></param> /// <param name="xResponseMessage"></param> /// <returns></returns> private static bool ProcessUploadFarmStatus(RuntimeDataBlock cd, dynamic data, ref string message, out XResponseMessage xResponseMessage) { if (cd.UploadFarmStatus != null) { var result = RuntimeDataProcessor.ProcessUploadFarmStatus(cd.UploadFarmStatus); if (result != null && result.Success != ErrorType.NoError) { xResponseMessage = result; return(true); } if (result != null) { if (!result.Message.IsNullOrWhiteSpace()) { message += result.Message + " "; } if (result.Data != null) { data.UploadFarmStatus = result.Data; } } } xResponseMessage = null; return(false); }
/// <summary> /// 处理设施添加数据 /// </summary> /// <param name="cd"></param> /// <param name="data"></param> /// <param name="message"></param> /// <param name="xResponseMessage"></param> /// <returns></returns> private static async Task <XResponseMessage> ProcessFacilityAddDatas(ManageDataBlock cd, dynamic data) { XResponseMessage xResponseMessage = new XResponseMessage(); if (cd.FacilityAddDatas != null && cd.FacilityAddDatas.Any()) { var result = await ManageDataProcessor.ProcessFacilityAddData(cd.FacilityAddDatas); if (result != null && result.Success != ErrorType.NoError) { xResponseMessage = result; xResponseMessage.IsTrue = true; } if (result != null) { if (!result.Message.IsNullOrWhiteSpace()) { xResponseMessage.Message += result.Message + " "; } if (result.Data != null) { data.FacilityAddDatas = result.Data; } } } xResponseMessage.IsTrue = false; return(xResponseMessage); }
/// <summary> /// 处理运行数据 /// </summary> /// <param name="runtimeDataBlock"></param> public static XResponseMessage ProcessRuntimeData(RuntimeDataBlock runtimeDataBlock) { if (runtimeDataBlock == null) { throw new ArgumentNullException("runtimeDataBlock"); } dynamic data = new ExpandoObject(); var message = ""; XResponseMessage xResponseMessage; //上传示范点状态 if (ProcessUploadFarmStatus(runtimeDataBlock, data, ref message, out xResponseMessage)) { return(xResponseMessage); } var result2 = new XResponseMessage() { Success = ErrorType.NoError, Message = message, Data = data, }; return(result2); }
/// <summary> /// 处理查询数据 /// </summary> /// <param name="queryDataBlock"></param> public static async Task <XResponseMessage> ProcessQueryData(QueryDataBlock queryDataBlock) { if (queryDataBlock == null) { throw new ArgumentNullException("queryDataBlock"); } dynamic data = new ExpandoObject(); var message = ""; XResponseMessage xResponseMessage = new XResponseMessage { Message = message, Success = ErrorType.NoContent, IsTrue = false, Data = data }; //获取设施类型 xResponseMessage = (XResponseMessage) await ProcessQueryFacilityType(queryDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } //获取设备类型 xResponseMessage = (XResponseMessage) await ProcessQueryDeviceType(queryDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } //查询基地下所有设施 xResponseMessage = (XResponseMessage) await ProcessQueryFacilitys(queryDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } //获取设施下所有设备,包含采集设备、控制设备、音视频设备 xResponseMessage = (XResponseMessage) await ProcessQueryFacilityDevices(queryDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } var result2 = new XResponseMessage() { Success = ErrorType.NoError, Message = message, Data = data, }; return(result2); }
/// <summary> /// 处理管理数据 /// </summary> /// <param name="manageDataBlock"></param> public static async Task <XResponseMessage> ProcessManageData(ManageDataBlock manageDataBlock) { if (manageDataBlock == null) { throw new ArgumentNullException("manageDataBlock"); } dynamic data = new ExpandoObject(); var message = ""; XResponseMessage xResponseMessage = new XResponseMessage { IsTrue = false, Success = ErrorType.NoContent, Data = data, Message = message }; //添加设施、(传感器、音视频)设备 xResponseMessage = (XResponseMessage) await ProcessFacilityAddDatas(manageDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } //更新设施数据 xResponseMessage = (XResponseMessage) await ProcessFacilityUpdateDatas(manageDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } //更新设备(采集、控制设备,音视频设备)数据 xResponseMessage = (XResponseMessage) await ProcessDeviceUpdateData(manageDataBlock, data); if (xResponseMessage.IsTrue) { message = xResponseMessage.Message; return(xResponseMessage); } var result2 = new XResponseMessage() { Success = ErrorType.NoError, Message = message, Data = data, }; return(result2); }
/// <summary> /// 处理普通数据 /// </summary> /// <param name="commonDataBlock"></param> public static XResponseMessage ProcessCommonData(CommonDataBlock commonDataBlock) { if (commonDataBlock == null) { throw new ArgumentNullException("commonDataBlock"); } dynamic data = new ExpandoObject(); var message = ""; var result2 = new XResponseMessage() { Success = ErrorType.NoError, Message = message, Data = data, }; return(result2); }
/// <summary> /// 回发消息 /// </summary> /// <param name="message"></param> public void Response(XResponseMessage message = null) { //if (SocketSession == null) return; //Monitor.Enter(SocketSession); //try //{ // SocketSession?.Send((message ?? ResponseWrapper).ToString()); //} //catch (Exception e) //{ // // 异常处理代码 // LogHelper.Debug(e.ToString()); //} //finally //{ // Monitor.Exit(SocketSession); // 解除锁定 //} try { if (SocketSession == null || SocketSession.Disposed) { return; } lock (SocketSession) { SocketSession?.Send((message ?? ResponseWrapper).ToString()); } } catch (Exception ex) { //throw; } //finally //{ // Monitor.Exit(SocketSession); //} }