Exception IExceptionHandler.HandleException(Exception exception, Guid handlingInstanceId)
        {
            DataAccessException dbExcep = exception as DataAccessException;

            if (dbExcep != null)
            {
                AlarmException alarmException;
                string         errorCode = dbExcep.ErrorCode;
                string         msg       = dbExcep.Message;
                string         addMsg    = string.Empty;

                string languageCode;
                if (ApplicationContext.Current != null)
                {
                    languageCode = ApplicationContext.Current.LanguageCode;
                }
                else
                {
                    languageCode = ApplicationContext.DefaultLanguageCode;
                }

                FindAlarmTextAction findAlarmTextAction = new FindAlarmTextAction();
                FindAlarmTextParams findAlarmTextParams = new FindAlarmTextParams();

                findAlarmTextParams.AlarmId      = errorCode;
                findAlarmTextParams.LanguageCode = languageCode;

                IList <FindAlarmTextResult> alarmTextList = findAlarmTextAction.Execute(findAlarmTextParams);

                if (alarmTextList.Count == 1)
                {
                    msg = alarmTextList[0].AlarmText;
                    if (exception.InnerException != null && exception.InnerException.Message.Length > 0)
                    {
                        addMsg = exception.InnerException.Message;
                    }
                    alarmException = new AlarmException(errorCode, msg, null, addMsg, null);

                    return(alarmException);
                }

                return(exception);
            }
            return(exception);
        }
Ejemplo n.º 2
0
        public static void Execute(string errorCode, int?currentPosition, string languageCode)
        {
            if (string.IsNullOrEmpty(languageCode))
            {
                if (ApplicationContext.Current != null)
                {
                    languageCode = ApplicationContext.Current.LanguageCode;
                }
                else
                {
                    languageCode = ApplicationContext.DefaultLanguageCode;
                }
            }

            if (!String.IsNullOrEmpty(errorCode))
            {
                FindAlarmTextAction findAlarmTextAction = new FindAlarmTextAction();
                FindAlarmTextParams findAlarmTextParams = new FindAlarmTextParams();

                findAlarmTextParams.AlarmId      = errorCode;
                findAlarmTextParams.LanguageCode = languageCode;

                IList <FindAlarmTextResult> alarmTextList = findAlarmTextAction.Execute(findAlarmTextParams);

                if (alarmTextList.Count != 1)
                {
                    AlarmException alarmException = new AlarmException(errorCode, "", currentPosition);

                    throw alarmException;
                }
                else
                {
                    AlarmException alarmException = new AlarmException(errorCode, alarmTextList[0].AlarmText, currentPosition);

                    throw alarmException;
                }
            }
        }