Example #1
0
        public static GetVersionResult GetVersion()
        {
            try
            {
                //if (string.IsNullOrEmpty(Base.Url))
                //    return new NormalResult();

                BaseChannel <IFingerprint> channel = Base.GetChannel();
                try
                {
                    var result = channel.Object.GetVersion(out string version,
                                                           out string cfg_info,
                                                           out string strError);
                    if (result == -1)
                    {
                        Base.TriggerSetError(result,
                                             new SetErrorEventArgs {
                            Error = strError
                        });
                    }
                    else
                    {
                        Base.TriggerSetError(result,
                                             new SetErrorEventArgs {
                            Error = null
                        });                                          // 清除以前的报错
                    }
                    return(new GetVersionResult
                    {
                        Version = version,
                        CfgInfo = cfg_info,
                        Value = result,
                        ErrorInfo = strError
                    });
                }
                finally
                {
                    Base.ReturnChannel(channel);
                }
            }
            catch (Exception ex)
            {
                Base.TriggerSetError(ex,
                                     new SetErrorEventArgs
                {
                    Error = $"指纹中心出现异常: {ExceptionUtil.GetAutoText(ex)}"
                });
                return(new GetVersionResult
                {
                    Value = -1,
                    ErrorInfo = ex.Message,
                    ErrorCode = NotResponseException.GetErrorCode(ex)
                });
            }
        }
Example #2
0
        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);
        }
Example #3
0
        public static NormalResult GetState(string style)
        {
            try
            {
                // 因为 GetState 是可有可无的请求,如果 Url 为空就算了
                if (string.IsNullOrEmpty(Base.Url))
                {
                    return(new NormalResult());
                }

                BaseChannel <IFingerprint> channel = Base.GetChannel();
                try
                {
                    var result = channel.Object.GetState(style);
                    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.TriggerSetError(ex,
                                     new SetErrorEventArgs
                {
                    Error = $"指纹中心出现异常: {ExceptionUtil.GetAutoText(ex)}"
                });
                return(new NormalResult
                {
                    Value = -1,
                    ErrorInfo = ex.Message,
                    ErrorCode = NotResponseException.GetErrorCode(ex)
                });
            }
        }
Example #4
0
        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
                });
            }
        }