| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using System.Collections;
- using System.Dynamic;
- using Muchinfo.MTPClient.Resources;
- using System;
- namespace Muchinfo.MTPClient.CustomException
- {
- public class MuchinfoException : System.Exception
- {
-
- public static CommonResx ErrorResx
- {
- get; set;
- }
- /// <summary>
- /// 服务端返回码
- /// </summary>
- public int ReturnCode { get; set; }
- /// <summary>
- /// 服务端返回信息描述
- /// </summary>
- public string ReturnDesc
- {
- get;
- set;
- }
- /// <summary>
- ///
- /// </summary>
- public Type TypeClass { get; set; }
- /// <summary>
- /// 异常信息
- /// </summary>
- /// <value>The exception message.</value>
- public Exception InnerExcption { get; set; }
- public MuchinfoException(int returnCode)
- {
- ReturnCode = returnCode;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="MuchinfoException"/> class.
- /// </summary>
- /// <param name="returnCode">The return code.</param>
- public MuchinfoException(int returnCode, string returnDesc)
- {
- ReturnCode = returnCode;
- ReturnDesc = returnDesc;
- }
- public MuchinfoException(int returnCode, string returnDesc, Type type)
- {
- ReturnCode = returnCode;
- ReturnDesc = returnDesc;
- TypeClass = type;
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="MuchinfoException" /> class.
- /// </summary>
- /// <param name="returnCode">The return code.</param>
- /// <param name="innerException">The inner exception.</param>
- public MuchinfoException(int returnCode, Exception innerException)
- : base(innerException == null ? string.Empty : innerException.ToString(), innerException)
- {
- ReturnCode = returnCode;
- }
- /// <summary>
- /// 获取描述当前异常的消息。
- /// </summary>
- /// <returns>解释异常原因的错误消息或空字符串 ("")。</returns>
- public override string Message
- {
- get
- {
- var message = ErrorDesc(ReturnCode);
- message = string.IsNullOrWhiteSpace(message) ? ReturnDesc : message ;
- if (string.IsNullOrWhiteSpace(message))
- {
- message = Client_Resource.CustomException_UnknowCode + ReturnCode;
- }
- else
- {
- message += Environment.NewLine + Client_Resource.CustomException_Code + ReturnCode;
- }
- return message;
- }
- }
- public static string ErrorDesc(int returnCode)
- {
- var retStr = string.Empty;
- var strCode = returnCode + string.Empty;
- if (ErrorResx != null && ErrorResx.ResourceHashtable != null &&
- ErrorResx.ResourceHashtable.ContainsKey(strCode))
- {
- retStr = ErrorResx.ResourceHashtable[strCode] as string;
- }
- else
- {
- retStr = ErrorResources.ResourceManager.GetString(returnCode + string.Empty);
- }
- if (string.IsNullOrEmpty(retStr))
- {
- retStr = ClientErrorResources.ResourceManager.GetString(returnCode + string.Empty);
- }
- return retStr;
- }
- /// <summary>
- /// 初始化错误资源
- /// </summary>
- public static void InitErrorResx()
- {
- var errorCodeManager=new ErrorCodeManager();
- ErrorResx = errorCodeManager.GetErrorCode();
- }
- /// <summary>
- /// 保存并设置资源内容
- /// </summary>
- /// <param name="resxHashtable"></param>
- /// <param name="ver"></param>
- public static void ErrorResxSaveRep(Hashtable resxHashtable,ulong ver)
- {
- var errorCodeManager = new ErrorCodeManager();
- ErrorResx = new CommonResx() { ResourceHashtable = resxHashtable, Version = ver };
- errorCodeManager.SaveErrorCode(resxHashtable,ver);
- }
- }
- }
|