public void RemoveError(AcErrorType type) { if (!HasError(type)) return; _errors.Remove(_errors.FirstOrDefault(x => x.Type == type)); if (Errors.Count == 0) { OnPropertyChanged(nameof(HasErrors)); } }
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); } }
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); }
/// <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); } }
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; }
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); }
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(); } }
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); } }
private static string MessageFromType(AcErrorType type) { return(type.GetDescription() ?? @"?"); }
public AcErrorException(AcCommonObject target, AcErrorType type, params object[] args) { AcError = new AcError(target, type, args); }
private static string MessageFromType(AcErrorType type) { return type.GetDescription() ?? @"?"; }
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; }
public bool HasError(AcErrorType type) { return(_errors.Any(error => error.Type == type)); }
public void AddError(AcErrorType type, params object[] args) { AddError(new AcError(this, type, args)); }
public bool HasError(AcErrorType type) { return _errors.Any(error => error.Type == type); }