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;
}
///
/// 服务端返回码
///
public int ReturnCode { get; set; }
///
/// 服务端返回信息描述
///
public string ReturnDesc
{
get;
set;
}
///
///
///
public Type TypeClass { get; set; }
///
/// 异常信息
///
/// The exception message.
public Exception InnerExcption { get; set; }
public MuchinfoException(int returnCode)
{
ReturnCode = returnCode;
}
///
/// Initializes a new instance of the class.
///
/// The return code.
public MuchinfoException(int returnCode, string returnDesc)
{
ReturnCode = returnCode;
ReturnDesc = returnDesc;
}
public MuchinfoException(int returnCode, string returnDesc, Type type)
{
ReturnCode = returnCode;
ReturnDesc = returnDesc;
TypeClass = type;
}
///
/// Initializes a new instance of the class.
///
/// The return code.
/// The inner exception.
public MuchinfoException(int returnCode, Exception innerException)
: base(innerException == null ? string.Empty : innerException.ToString(), innerException)
{
ReturnCode = returnCode;
}
///
/// 获取描述当前异常的消息。
///
/// 解释异常原因的错误消息或空字符串 ("")。
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;
}
///
/// 初始化错误资源
///
public static void InitErrorResx()
{
var errorCodeManager=new ErrorCodeManager();
ErrorResx = errorCodeManager.GetErrorCode();
}
///
/// 保存并设置资源内容
///
///
///
public static void ErrorResxSaveRep(Hashtable resxHashtable,ulong ver)
{
var errorCodeManager = new ErrorCodeManager();
ErrorResx = new CommonResx() { ResourceHashtable = resxHashtable, Version = ver };
errorCodeManager.SaveErrorCode(resxHashtable,ver);
}
}
}