| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using SKMC.Api.Client.Config;
- using SKMC.Api.Client.UI;
- using SKMC.Api.Common.Logger;
- using SKMC.Api.Machine.Control;
- using System;
- namespace SKMC.Api.Common.Exceptions
- {
- /// <summary>
- /// 异常包装类
- /// </summary>
- public class ExceptionWrapper
- {
- private static readonly ILogger log = LogFactory.Get();
- private static readonly IMachineBoardControl machineBoardControl = ObjectFactory.Resolve<IMachineBoardControl>();
- private static readonly CommonCacher commonCacher = ObjectFactory.Resolve<CommonCacher>();
- public static string Throws(Exception exception, string dialogViewName = ClientConstants.Views_CommonException)
- {
- if (exception == null) return null;
- if (typeof(ExceptionBase).IsAssignableFrom(exception.GetType()))
- {
- ExceptionBase exceptionBase = exception as ExceptionBase;
- ExceptionConfig exceptionConfig = commonCacher.GetExceptionConfig(exceptionBase);
- exceptionBase.Level = exceptionConfig.Level;
- // 停机异常
- if (exceptionConfig.Level == 4)
- {
- machineBoardControl.IsAlarm = true;
- machineBoardControl.StopAction.Invoke();
- log.Error($"严重异常: {exception}");
- return ClientDialogs.CreateExceptionDialog(exceptionBase, dialogViewName);
- }
- // 普通异常
- if (exceptionConfig.Level == 2)
- {
- machineBoardControl.IsAlarm = true;
- machineBoardControl.PauseAction.Invoke();
- log.Error($"普通异常: {exception},{exception.StackTrace}");
- return ClientDialogs.CreateExceptionDialog(exceptionBase, dialogViewName);
- }
- // 单站异常
- if (exceptionConfig.Level == 1)
- {
- if (exceptionBase.StationId > 0)
- {
- machineBoardControl.PauseOneAction.Invoke(exceptionBase.StationId);
- }
- log.Error($"单站异常: {exception}");
- return ClientDialogs.CreateExceptionDialog(exceptionBase, dialogViewName);
- }
- else
- {
- log.Error($"其他异常: {exception}");
- return null;
- }
- }
- // 未知异常
- else
- {
- machineBoardControl.IsAlarm = true;
- machineBoardControl.StopAction.Invoke();
- log.Error($"未知异常: {exception.Message}", exception);
- ClientDialogs.CreateExceptionDialog(exception);
- return null;
- }
- }
- }
- }
|