public static AwEntity GetAwEntity(string str) { try { return(FormatterFactory.ProcessAsync(str)); } catch (Exception ex) { LogHelper.Fatal("反序列化失败," + str); } return(null); }
/// <summary> /// 农业物联网信息服务平台数据交换协议 处理 /// </summary> /// <param name="str"></param> public static async Task <XResponseMessage> Process(string str) { if (str.IsNullOrWhiteSpace()) { throw new ArgumentNullException("str"); } AwEntity obj; #region 反序列化为实体对象 try { //obj = FormatterFactory.ProcessAsync(str).GetAwaiter().GetResult(); obj = FormatterFactory.ProcessAsync(str); } catch (Exception ex) { ServiceLogger.Current.WriteError("反序列化失败," + str); return(ResultHelper.CreateExceptionMessage(ex, "数据无法解析", ErrorType.NotSupportedProtocalType)); } if (obj == null) { ServiceLogger.Current.WriteError("数据格式异常," + str); return(ResultHelper.CreateMessage("数据格式异常", ErrorType.CanNotProcessRequestData)); } #endregion #region 协议解析 try { var awEntity = obj; //ServiceLogger.Current.WriteDebugLog("{0}", awEntity.Description); var result = await ProcessEntity(awEntity); //ServiceLogger.Current.WriteLine(result.ToString()); return(result ?? new XResponseMessage() { Success = ErrorType.NoError }); //return null; } catch (Exception ex) { //ServiceLogger.Current.WriteException(ex); ServiceLogger.Current.WriteException(ex); return(ResultHelper.CreateMessage("协议解析错误", ErrorType.CanNotProcessRequestData, null, ex)); } #endregion }