Exemplo n.º 1
0
 public void RemoveError(AcErrorType type) {
     if (!HasError(type)) return;
     _errors.Remove(_errors.FirstOrDefault(x => x.Type == type));
     if (Errors.Count == 0) {
         OnPropertyChanged(nameof(HasErrors));
     }
 }
Exemplo n.º 2
0
        public AcError(AcCommonObject target, AcErrorType type, params object[] args)
        {
            Target   = target;
            Type     = type;
            Category = CategoryFromType(type);

            try {
                Message = string.Format(MessageFromType(type), args.Select(x => (x as Exception)?.Message ?? x).ToArray());
            } catch (FormatException) {
                Message = Regex.Replace(MessageFromType(type), @"\{\d+\}", "?");
            }

            BaseException = args.OfType <Exception>().FirstOrDefault();

            if (Category != AcErrorCategory.CarSkin &&
                (type != AcErrorType.Data_JsonIsMissing || !Equals(args.FirstOrDefault(), @"ui_skin.json")) &&
                type != AcErrorType.Car_ParentIsMissing &&
                type != AcErrorType.Track_PreviewIsMissing &&
                type != AcErrorType.Track_OutlineIsMissing &&
                type != AcErrorType.Track_MapIsMissing)
            {
                Logging.Write(Message);
            }

            foreach (var exception in args.OfType <Exception>())
            {
                Logging.Warning(exception);
            }
        }
Exemplo n.º 3
0
        private static bool IsSeveralAllowed(AcErrorType errorType)
        {
            var type    = typeof(AcErrorType);
            var memInfo = type.GetMember(errorType.ToString());

            return(memInfo[0].GetCustomAttributes(typeof(SeveralAllowedAttribute), false).Length > 0);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Add error if condition is true, remove existing if exists otherwise.
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="type"></param>
 /// <param name="args"></param>
 public void ErrorIf(bool condition, AcErrorType type, params object[] args) {
     if (condition) {
         AddError(new AcError(this, type, args));
     } else {
         RemoveError(type);
     }
 }
Exemplo n.º 5
0
        private static AcErrorCategory CategoryFromType(AcErrorType type) {
            AcErrorCategory result;
            if (Enum.TryParse(type.ToString().Split(new[] { '_' }, 2)[0], out result)) {
                return result;
            }

            Logging.Warning($"Can’t get category for AcErrorType: {type}");
            return AcErrorCategory.Unspecific;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Add error if condition is true, remove existing if exists otherwise.
 /// </summary>
 /// <param name="condition"></param>
 /// <param name="type"></param>
 /// <param name="args"></param>
 public void ErrorIf(bool condition, AcErrorType type, params object[] args)
 {
     if (condition)
     {
         AddError(new AcError(this, type, args));
     }
     else
     {
         RemoveError(type);
     }
 }
Exemplo n.º 7
0
        private static AcErrorCategory CategoryFromType(AcErrorType type)
        {
            AcErrorCategory result;

            if (Enum.TryParse(type.ToString().Split(new[] { '_' }, 2)[0], out result))
            {
                return(result);
            }

            Logging.Warning($"Can’t get category for AcErrorType: {type}");
            return(AcErrorCategory.Unspecific);
        }
Exemplo n.º 8
0
 public void RemoveError(AcErrorType type)
 {
     if (!HasError(type))
     {
         return;
     }
     _errors.Remove(_errors.FirstOrDefault(x => x.Type == type));
     if (Errors.Count == 0)
     {
         OnPropertyChanged(nameof(HasErrors));
         CommandManager.InvalidateRequerySuggested();
     }
 }
Exemplo n.º 9
0
        public AcError(AcCommonObject target, AcErrorType type, params object[] args) {
            Target = target;
            Type = type;
            Category = CategoryFromType(type);

            try {
                Message = string.Format(MessageFromType(type), args.Select(x => (x as Exception)?.Message ?? x).ToArray());
            } catch (FormatException) {
                Message = Regex.Replace(MessageFromType(type), @"\{\d+\}", "?");
            }

            BaseException = args.OfType<Exception>().FirstOrDefault();

            if (Category != AcErrorCategory.CarSkin &&
                    (type != AcErrorType.Data_JsonIsMissing || !Equals(args.FirstOrDefault(), @"ui_skin.json"))) {
                Logging.Write(Message);
            }

            foreach (var exception in args.OfType<Exception>()) {
                Logging.Warning(exception);
            }
        }
Exemplo n.º 10
0
 private static string MessageFromType(AcErrorType type)
 {
     return(type.GetDescription() ?? @"?");
 }
Exemplo n.º 11
0
 public AcErrorException(AcCommonObject target, AcErrorType type, params object[] args)
 {
     AcError = new AcError(target, type, args);
 }
Exemplo n.º 12
0
 private static string MessageFromType(AcErrorType type) {
     return type.GetDescription() ?? @"?";
 }
Exemplo n.º 13
0
 private static bool IsSeveralAllowed(AcErrorType errorType) {
     var type = typeof(AcErrorType);
     var memInfo = type.GetMember(errorType.ToString());
     return memInfo[0].GetCustomAttributes(typeof(SeveralAllowedAttribute), false).Length > 0;
 }
Exemplo n.º 14
0
 public bool HasError(AcErrorType type)
 {
     return(_errors.Any(error => error.Type == type));
 }
Exemplo n.º 15
0
 public void AddError(AcErrorType type, params object[] args)
 {
     AddError(new AcError(this, type, args));
 }
Exemplo n.º 16
0
 public bool HasError(AcErrorType type) {
     return _errors.Any(error => error.Type == type);
 }
Exemplo n.º 17
0
 public AcErrorException(AcCommonObject target, AcErrorType type, params object[] args) {
     AcError = new AcError(target, type, args);
 }
Exemplo n.º 18
0
 public void AddError(AcErrorType type, params object[] args) {
     AddError(new AcError(this, type, args));
 }