From a1f6b41accb47e4c1e1e0474148afa94732377da Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Apr 2022 21:52:26 +0800 Subject: ... --- .../Timeline/Models/Validation/NameValidator.cs | 10 +- .../Models/Validation/Resource.Designer.cs | 312 +++++++++++---------- BackEnd/Timeline/Models/Validation/Resource.resx | 3 + .../Models/Validation/TimelineNameValidator.cs | 7 +- 4 files changed, 175 insertions(+), 157 deletions(-) (limited to 'BackEnd/Timeline/Models/Validation') diff --git a/BackEnd/Timeline/Models/Validation/NameValidator.cs b/BackEnd/Timeline/Models/Validation/NameValidator.cs index 2220de6f..c7c18738 100644 --- a/BackEnd/Timeline/Models/Validation/NameValidator.cs +++ b/BackEnd/Timeline/Models/Validation/NameValidator.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Text.RegularExpressions; namespace Timeline.Models.Validation @@ -7,10 +8,17 @@ namespace Timeline.Models.Validation { private static Regex UniqueIdRegex { get; } = new Regex(@"^[a-zA-Z0-9]{32}$"); + public List DisallowedNames { get; set; } = new List(); + public const int MaxLength = 26; protected override (bool, string) DoValidate(string value) { + if (DisallowedNames.Contains(value)) + { + return (false, Resource.NameDisallowed); + } + if (value.Length == 0) { return (false, Resource.NameCantBeEmpty); diff --git a/BackEnd/Timeline/Models/Validation/Resource.Designer.cs b/BackEnd/Timeline/Models/Validation/Resource.Designer.cs index 47ad4248..4f52e047 100644 --- a/BackEnd/Timeline/Models/Validation/Resource.Designer.cs +++ b/BackEnd/Timeline/Models/Validation/Resource.Designer.cs @@ -1,153 +1,159 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Models.Validation { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resource { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resource() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Models.Validation.Resource", typeof(Resource).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to it can't be null. - /// - internal static string CantBeNull { - get { - return ResourceManager.GetString("CantBeNull", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to name can't be empty. - /// - internal static string NameCantBeEmpty { - get { - return ResourceManager.GetString("NameCantBeEmpty", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to name can't be longer than {0}. - /// - internal static string NameCantBeLongerThan { - get { - return ResourceManager.GetString("NameCantBeLongerThan", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to name can't has the same pattern of unique id. - /// - internal static string NameCantBeUniqueIdPattern { - get { - return ResourceManager.GetString("NameCantBeUniqueIdPattern", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to name can only consists of alphabet, number, '_' and '-' . - /// - internal static string NameInvalidChar { - get { - return ResourceManager.GetString("NameInvalidChar", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to nickname can't be longer than 25. - /// - internal static string NicknameTooLong { - get { - return ResourceManager.GetString("NicknameTooLong", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to it is not of type {0}. - /// - internal static string NotOfType { - get { - return ResourceManager.GetString("NotOfType", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Failed to create validator instance.. - /// - internal static string ValidateWithAttributeExceptionCreateFail { - get { - return ResourceManager.GetString("ValidateWithAttributeExceptionCreateFail", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Given type is not a IValidator instance.. - /// - internal static string ValidateWithAttributeExceptionNotValidator { - get { - return ResourceManager.GetString("ValidateWithAttributeExceptionNotValidator", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to validation passed. - /// - internal static string ValidationPassed { - get { - return ResourceManager.GetString("ValidationPassed", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Timeline.Models.Validation { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// This class was generated by MSBuild using the GenerateResource task. + /// To add or remove a member, edit your .resx file then rerun MSBuild. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Models.Validation.Resource", typeof(Resource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to it can't be null. + /// + internal static string CantBeNull { + get { + return ResourceManager.GetString("CantBeNull", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to name can't be empty. + /// + internal static string NameCantBeEmpty { + get { + return ResourceManager.GetString("NameCantBeEmpty", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to name can't be longer than {0}. + /// + internal static string NameCantBeLongerThan { + get { + return ResourceManager.GetString("NameCantBeLongerThan", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to name can't has the same pattern of unique id. + /// + internal static string NameCantBeUniqueIdPattern { + get { + return ResourceManager.GetString("NameCantBeUniqueIdPattern", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to this special value is not allowed. + /// + internal static string NameDisallowed { + get { + return ResourceManager.GetString("NameDisallowed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to name can only consists of alphabet, number, '_' and '-' . + /// + internal static string NameInvalidChar { + get { + return ResourceManager.GetString("NameInvalidChar", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to nickname can't be longer than 25. + /// + internal static string NicknameTooLong { + get { + return ResourceManager.GetString("NicknameTooLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to it is not of type {0}. + /// + internal static string NotOfType { + get { + return ResourceManager.GetString("NotOfType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to create validator instance.. + /// + internal static string ValidateWithAttributeExceptionCreateFail { + get { + return ResourceManager.GetString("ValidateWithAttributeExceptionCreateFail", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Given type is not a IValidator instance.. + /// + internal static string ValidateWithAttributeExceptionNotValidator { + get { + return ResourceManager.GetString("ValidateWithAttributeExceptionNotValidator", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to validation passed. + /// + internal static string ValidationPassed { + get { + return ResourceManager.GetString("ValidationPassed", resourceCulture); + } + } + } +} diff --git a/BackEnd/Timeline/Models/Validation/Resource.resx b/BackEnd/Timeline/Models/Validation/Resource.resx index 68ba3810..9bec20a5 100644 --- a/BackEnd/Timeline/Models/Validation/Resource.resx +++ b/BackEnd/Timeline/Models/Validation/Resource.resx @@ -120,6 +120,9 @@ it can't be null + + this special value is not allowed + name can't be empty diff --git a/BackEnd/Timeline/Models/Validation/TimelineNameValidator.cs b/BackEnd/Timeline/Models/Validation/TimelineNameValidator.cs index f1ab54e8..7cd49fd2 100644 --- a/BackEnd/Timeline/Models/Validation/TimelineNameValidator.cs +++ b/BackEnd/Timeline/Models/Validation/TimelineNameValidator.cs @@ -1,5 +1,6 @@ using System; - +using System.Collections.Generic; + namespace Timeline.Models.Validation { public class TimelineNameValidator : NameValidator @@ -12,8 +13,8 @@ namespace Timeline.Models.Validation { public TimelineNameAttribute() : base(typeof(TimelineNameValidator)) - { - + { + } } } -- cgit v1.2.3