| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:ExceptionManager.cs
- * 2.功能描述:客户端逻辑处理的共通处理(同一用户登录、权限判断等等)
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈冰 2014/08/30 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using System.ServiceModel;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- namespace Dongke.IBOSS.PRD.Client.CommonModule
- {
- /// <summary>
- /// 系统异常管理
- /// </summary>
- public class ExceptionManager
- {
- #region 常量定义
- private const string REPEAT_LOGIN = "RepeatLogin"; // 重复登录
- private const string VALIDATION_KEY = "ValidationKey"; // 私有秘钥验证失败
- private const string LOGININFO_ERROR = "LoginInfoError"; // 用户登录信息验证失败
- private const string SYSTEMDATETIMEERROR = "SystemDateTimeError"; // 服务器日期异常
- #endregion
- #region 公开方法
- /// <summary>
- /// 对捕获的异常进行甑别,如果有验证非法则重启程序。
- /// </summary>
- /// <param name="ex">捕获的异常</param>
- public static void AuthenticateFailRequest(Exception ex)
- {
- // 提示信息的内容
- string errorMessage;
- // 程序是否关闭
- bool isCloseApplication = false;
- if (ex is ProtocolException)
- {
- // 重复登录
- if (ex.Message.Contains(REPEAT_LOGIN))
- {
- errorMessage = Messages.MSG_CMN_W008;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains(VALIDATION_KEY))
- {
- errorMessage = Messages.MSG_CMN_W009;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains(LOGININFO_ERROR))
- {
- errorMessage = Messages.MSG_CMN_W010;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains(SYSTEMDATETIMEERROR))
- {
- errorMessage = Messages.MSG_CMN_W022;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains("LicInfoError"))
- {
- errorMessage = "授权信息错误,请联系管理员。";
- isCloseApplication = true;
- }
- else
- {
- throw ex;
- }
- }
- else
- {
- throw ex;
- }
- // 写错误日志
- OutputLog.Trace(LogPriority.Warning,
- "Authorization",
- "Authorization()",
- ex.ToString());
- // 提示对话框
- MessageBox.Show(errorMessage, Messages.MSG_TITLE_W01,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- if (isCloseApplication)
- {
- System.Diagnostics.Process.GetCurrentProcess().Close();
- System.Environment.Exit(0);
- }
- }
- /// <summary>
- /// 对画面最终事件的异常进行处理
- /// </summary>
- /// <param name="fileName">源文件名称</param>
- /// <param name="eventName">事件名称</param>
- /// <param name="formTitle">窗体名称</param>
- /// <param name="ex">异常</param>
- public static void HandleEventException(string fileName, string eventName, string formTitle, Exception ex)
- {
- //提示信息的内容
- string errorMessage = string.Empty;
- MessageBoxIcon mbi = MessageBoxIcon.Warning;
- #region 需要退出系统重新登录的异常处理逻辑
- //程序是否关闭
- bool isCloseApplication = false;
- if (ex.Message.Contains(REPEAT_LOGIN))
- {
- errorMessage = Messages.MSG_CMN_W008;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains(VALIDATION_KEY))
- {
- errorMessage = Messages.MSG_CMN_W009;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains(LOGININFO_ERROR))
- {
- errorMessage = Messages.MSG_CMN_W010;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains(SYSTEMDATETIMEERROR))
- {
- errorMessage = Messages.MSG_CMN_W022;
- isCloseApplication = true;
- }
- else if (ex.Message.Contains("LicInfoError"))
- {
- errorMessage = "授权信息错误,请联系管理员。";
- mbi = MessageBoxIcon.Error;
- isCloseApplication = true;
- }
- if (isCloseApplication)
- {
- // 写错误日志
- OutputLog.Trace(LogPriority.Warning,
- "Authorization",
- "Authorization()",
- ex.ToString());
- // 提示对话框
- MessageBox.Show(errorMessage, Messages.MSG_TITLE_W01,
- MessageBoxButtons.OK,
- mbi);
- System.Diagnostics.Process.GetCurrentProcess().Close();
- System.Environment.Exit(0);
- return;
- }
- #endregion
- bool isError = false;
- bool isPrint = false;
- if (ex is ClientPrintException)
- {
- ex = ex.InnerException;
- isPrint = true;
- }
- if (ex is EndpointNotFoundException)
- {
- // 无法连接到远程的WEB服务器
- errorMessage = Messages.MSG_CMN_E002;
- }
- //// 与远程WEB服务器通讯出现异常
- //else if (ex is CommunicationException)
- //{
- // errorMessage = Messages.MSG_CMN_E003;
- //}
- // 与远程WEB服务器连接超时
- else if (ex is TimeoutException)
- {
- errorMessage = Messages.MSG_CMN_E004;
- }
- // 内存不足
- else if (ex is OutOfMemoryException)
- {
- errorMessage = Messages.MSG_CMN_E005;
- }
- else if (isPrint)
- {
- errorMessage = "客户端打印异常,请联系系统管理员。";
- isError = true;
- }
- else
- {
- errorMessage = Messages.MSG_CMN_E001;
- isError = true;
- }
- // 写错误日志
- OutputLog.Trace(LogPriority.Error, fileName, eventName, ex.ToString());
- // 提示对话框
- MessageBox.Show(errorMessage, formTitle,
- MessageBoxButtons.OK,
- isError ? MessageBoxIcon.Error : MessageBoxIcon.Warning);
- }
- #endregion
- }
- }
|