public static string GetErrorCode(Exception ex) { if (ex == null) { return(""); } string error_code = ex.GetType().ToString(); if (NotResponseException.IsNotResponse(ex)) { error_code = "notResponse"; } return(error_code); }
public static NormalResult EnableSendkey(bool enable) { try { // 因为 EnableSendkey 是可有可无的请求,如果 Url 为空就算了 if (string.IsNullOrEmpty(Base.Url)) { return(new NormalResult()); } BaseChannel <IRfid> channel = Base.GetChannel(); try { var result = channel.Object.EnableSendKey(enable); if (result.Value == -1) { Base.TriggerSetError(result, new SetErrorEventArgs { Error = result.ErrorInfo }); } else { Base.TriggerSetError(result, new SetErrorEventArgs { Error = null }); // 清除以前的报错 } return(result); } finally { Base.ReturnChannel(channel); } } catch (Exception ex) { Base.Clear(); Base.TriggerSetError(ex, new SetErrorEventArgs { Error = NotResponseException.IsNotResponse(ex) ? $"RFID 中心({Base.Url})没有响应" : $"RFID 中心出现异常: {ExceptionUtil.GetExceptionText(ex)}" }); return(new NormalResult { Value = -1, ErrorInfo = ex.Message }); } }