diff options
Diffstat (limited to 'BackEnd/Timeline/Models/Validation')
-rw-r--r-- | BackEnd/Timeline/Models/Validation/NameValidator.cs | 9 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Validation/NicknameValidator.cs | 3 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Validation/Resource.Designer.cs | 153 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Validation/Resource.resx | 150 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Validation/Validator.cs | 11 |
5 files changed, 313 insertions, 13 deletions
diff --git a/BackEnd/Timeline/Models/Validation/NameValidator.cs b/BackEnd/Timeline/Models/Validation/NameValidator.cs index b74c40b7..2220de6f 100644 --- a/BackEnd/Timeline/Models/Validation/NameValidator.cs +++ b/BackEnd/Timeline/Models/Validation/NameValidator.cs @@ -1,6 +1,5 @@ using System.Linq;
using System.Text.RegularExpressions;
-using static Timeline.Resources.Models.Validation.NameValidator;
namespace Timeline.Models.Validation
{
@@ -14,26 +13,26 @@ namespace Timeline.Models.Validation {
if (value.Length == 0)
{
- return (false, MessageEmptyString);
+ return (false, Resource.NameCantBeEmpty);
}
if (value.Length > MaxLength)
{
- return (false, MessageTooLong);
+ return (false, string.Format(Resource.NameCantBeLongerThan, MaxLength));
}
foreach ((char c, int i) in value.Select((c, i) => (c, i)))
{
if (!(char.IsLetterOrDigit(c) || c == '-' || c == '_'))
{
- return (false, MessageInvalidChar);
+ return (false, Resource.NameInvalidChar);
}
}
// Currently name can't be longer than 26. So this is not needed. But reserve it for future use.
if (UniqueIdRegex.IsMatch(value))
{
- return (false, MessageUnqiueId);
+ return (false, Resource.NameCantBeUniqueIdPattern);
}
return (true, GetSuccessMessage());
diff --git a/BackEnd/Timeline/Models/Validation/NicknameValidator.cs b/BackEnd/Timeline/Models/Validation/NicknameValidator.cs index 1d6ab163..43365dce 100644 --- a/BackEnd/Timeline/Models/Validation/NicknameValidator.cs +++ b/BackEnd/Timeline/Models/Validation/NicknameValidator.cs @@ -1,5 +1,4 @@ using System;
-using static Timeline.Resources.Models.Validation.NicknameValidator;
namespace Timeline.Models.Validation
{
@@ -8,7 +7,7 @@ namespace Timeline.Models.Validation protected override (bool, string) DoValidate(string value)
{
if (value.Length > 25)
- return (false, MessageTooLong);
+ return (false, Resource.NicknameTooLong);
return (true, GetSuccessMessage());
}
diff --git a/BackEnd/Timeline/Models/Validation/Resource.Designer.cs b/BackEnd/Timeline/Models/Validation/Resource.Designer.cs new file mode 100644 index 00000000..47ad4248 --- /dev/null +++ b/BackEnd/Timeline/Models/Validation/Resource.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------
+// <auto-generated>
+// 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.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Timeline.Models.Validation {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // 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() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [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;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to it can't be null.
+ /// </summary>
+ internal static string CantBeNull {
+ get {
+ return ResourceManager.GetString("CantBeNull", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to name can't be empty.
+ /// </summary>
+ internal static string NameCantBeEmpty {
+ get {
+ return ResourceManager.GetString("NameCantBeEmpty", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to name can't be longer than {0}.
+ /// </summary>
+ internal static string NameCantBeLongerThan {
+ get {
+ return ResourceManager.GetString("NameCantBeLongerThan", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to name can't has the same pattern of unique id.
+ /// </summary>
+ internal static string NameCantBeUniqueIdPattern {
+ get {
+ return ResourceManager.GetString("NameCantBeUniqueIdPattern", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to name can only consists of alphabet, number, '_' and '-' .
+ /// </summary>
+ internal static string NameInvalidChar {
+ get {
+ return ResourceManager.GetString("NameInvalidChar", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to nickname can't be longer than 25.
+ /// </summary>
+ internal static string NicknameTooLong {
+ get {
+ return ResourceManager.GetString("NicknameTooLong", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to it is not of type {0}.
+ /// </summary>
+ internal static string NotOfType {
+ get {
+ return ResourceManager.GetString("NotOfType", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Failed to create validator instance..
+ /// </summary>
+ internal static string ValidateWithAttributeExceptionCreateFail {
+ get {
+ return ResourceManager.GetString("ValidateWithAttributeExceptionCreateFail", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Given type is not a IValidator instance..
+ /// </summary>
+ internal static string ValidateWithAttributeExceptionNotValidator {
+ get {
+ return ResourceManager.GetString("ValidateWithAttributeExceptionNotValidator", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to validation passed.
+ /// </summary>
+ 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 new file mode 100644 index 00000000..68ba3810 --- /dev/null +++ b/BackEnd/Timeline/Models/Validation/Resource.resx @@ -0,0 +1,150 @@ +<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="CantBeNull" xml:space="preserve">
+ <value>it can't be null</value>
+ </data>
+ <data name="NameCantBeEmpty" xml:space="preserve">
+ <value>name can't be empty</value>
+ </data>
+ <data name="NameCantBeLongerThan" xml:space="preserve">
+ <value>name can't be longer than {0}</value>
+ </data>
+ <data name="NameCantBeUniqueIdPattern" xml:space="preserve">
+ <value>name can't has the same pattern of unique id</value>
+ </data>
+ <data name="NameInvalidChar" xml:space="preserve">
+ <value>name can only consists of alphabet, number, '_' and '-' </value>
+ </data>
+ <data name="NicknameTooLong" xml:space="preserve">
+ <value>nickname can't be longer than 25</value>
+ </data>
+ <data name="NotOfType" xml:space="preserve">
+ <value>it is not of type {0}</value>
+ </data>
+ <data name="ValidateWithAttributeExceptionCreateFail" xml:space="preserve">
+ <value>Failed to create validator instance.</value>
+ </data>
+ <data name="ValidateWithAttributeExceptionNotValidator" xml:space="preserve">
+ <value>Given type is not a IValidator instance.</value>
+ </data>
+ <data name="ValidationPassed" xml:space="preserve">
+ <value>validation passed</value>
+ </data>
+</root>
\ No newline at end of file diff --git a/BackEnd/Timeline/Models/Validation/Validator.cs b/BackEnd/Timeline/Models/Validation/Validator.cs index ec6cc0af..d334960e 100644 --- a/BackEnd/Timeline/Models/Validation/Validator.cs +++ b/BackEnd/Timeline/Models/Validation/Validator.cs @@ -1,6 +1,5 @@ using System;
using System.ComponentModel.DataAnnotations;
-using static Timeline.Resources.Models.Validation.Validator;
namespace Timeline.Models.Validation
{
@@ -56,7 +55,7 @@ namespace Timeline.Models.Validation if (PermitNull)
return (true, GetSuccessMessage());
else
- return (false, ValidatorMessageNull);
+ return (false, Resource.CantBeNull);
}
if (value is T v)
@@ -65,11 +64,11 @@ namespace Timeline.Models.Validation }
else
{
- return (false, ValidatorMessageBadType);
+ return (false, string.Format(Resource.NotOfType, typeof(T).Name));
}
}
- protected static string GetSuccessMessage() => ValidatorMessageSuccess;
+ protected static string GetSuccessMessage() => Resource.ValidationPassed;
protected abstract (bool, string) DoValidate(T value);
}
@@ -99,7 +98,7 @@ namespace Timeline.Models.Validation throw new ArgumentNullException(nameof(validatorType));
if (!typeof(IValidator).IsAssignableFrom(validatorType))
- throw new ArgumentException(ValidateWithAttributeExceptionNotValidator, nameof(validatorType));
+ throw new ArgumentException(Resource.ValidateWithAttributeExceptionNotValidator, nameof(validatorType));
try
{
@@ -107,7 +106,7 @@ namespace Timeline.Models.Validation }
catch (Exception e)
{
- throw new ArgumentException(ValidateWithAttributeExceptionCreateFail, e);
+ throw new ArgumentException(Resource.ValidateWithAttributeExceptionCreateFail, e);
}
}
|