public static void ShowError(string title, FaultException ex, Control owner) { if (ex.Code.Name == ERR_SYSTEM.ERR_SYSTEM_MODULE_SINGLE_INSTANCE.ToString()) { return; } if (App.Environment.ClientInfo.SessionKey != null) { if (int.Parse(ex.Code.Name) == ERR_SYSTEM.ERR_SYSTEM_SESSION_TERMINATED_BY_ADMIN || int.Parse(ex.Code.Name) == ERR_SYSTEM.ERR_SYSTEM_SESSION_NOT_EXISTS_OR_DUPLICATE || int.Parse(ex.Code.Name) == ERR_SYSTEM.ERR_SYSTEM_SESSION_TERMINATED_BY_SELF) { MainProcess.LogoutFromSystem(false); App.Environment.ClientInfo.UserName = null; App.Environment.ClientInfo.SessionKey = null; MainProcess.ShowLogin(); return; } } if (owner == null || owner.IsDisposed || owner.Disposing) { var frmMain = MainProcess.GetMainForm(); if (frmMain != null && !frmMain.IsDisposed && !frmMain.Disposing) { ShowError(title, ex, frmMain); } else { EventLog.WriteEntry( "IMSS.Client", string.Format("{0}\r\n{1}", ex.ToMessage(), ex.Reason), EventLogEntryType.Error); } return; } if (owner.InvokeRequired) { owner.Invoke(new ShowErrorInfoInvoker(ShowError), title, ex, owner); return; } if (!owner.InvokeRequired) { var frmDialog = new frmInfo { Text = title, lbErrorInfo = { Text = string.Format("<b>{0}</b>\r\n{1}", ex.ToMessage(), ex.Reason) } }; if (ex.Code.Name == "101") { try { File.AppendAllText("LastErrors.log", string.Format("{0}\r\n-------------\r\n", ex.Reason)); } catch { } } frmDialog.ShowDialog(owner); } }
/// <summary> /// Lấy thông tin mã lỗi /// </summary> /// <param name="ex">Lỗi trả lại từ Server</param> /// <returns></returns> public static string ToMessage(this FaultException ex) { return(ex.ToMessage(new object[] { })); }