localizing bug record creations

This commit is contained in:
2019-06-16 21:09:50 +01:00
parent 4e67b9378a
commit 446fc70f5d
7 changed files with 63 additions and 99 deletions

View File

@ -4,17 +4,16 @@ namespace Yavsc.Attributes.Validation
{
public class YaStringLength: YaValidationAttribute
{
public long MinLen { get; set; } = -1;
public long MinimumLength { get; set; } = -1;
private long maxLen;
public YaStringLength(long maxLen) : base(
()=>
"BadStringLength")
public YaStringLength(long maxLen) : base( ()=> "BadStringLength")
{
this.maxLen = maxLen;
}
private long excedent=0;
private long manquant=0;
// hugly ...
static long excedent=0;
static long manquant=0;
public override bool IsValid(object value) {
@ -24,23 +23,24 @@ namespace Yavsc.Attributes.Validation
string stringValue = value as string;
if (stringValue==null) return false;
if (MinLen>=0)
if (MinimumLength>=0)
{
if (stringValue.Length<MinLen)
{
manquant = MinLen-stringValue.Length;
}
if (stringValue.Length< MinimumLength)
return false;
}
if (maxLen>=0)
{
if (stringValue.Length>maxLen) {
excedent = stringValue.Length-maxLen;
return false;
}
}
return true;
}
public override string FormatErrorMessage(string name)
{
var temp = base.FormatErrorMessage(name);
return string.Format(temp, MinimumLength, maxLen);
}
}
}

View File

@ -15,18 +15,32 @@ namespace Yavsc.Attributes.Validation
}
/// <summary>
/// Get given string from resources
/// specified by ErrorMessageResourceType
/// </summary>
/// <param name="stringName"></param>
/// <returns></returns>
public virtual string GetResourceString(string stringName)
{
var prop = this.ErrorMessageResourceType.GetProperty(stringName);
if (prop==null)
{
return " !e! noprop "+stringName+" in "+ErrorMessageResourceType.Name;
}
else {
return (string) prop.GetValue(null, null);
}
}
public override string FormatErrorMessage(string name)
{
if (ErrorMessageResourceType == null) // failed :/
return name;
return base.FormatErrorMessage(name);
if (ErrorMessageResourceName == null) // re failed :/
return name;
var prop = this.ErrorMessageResourceType.GetProperty(ErrorMessageResourceName);
if (prop==null) // re re failed :/
return "noprop "+ErrorMessageResourceName+" in "+ErrorMessageResourceType.Name;
return (string) prop.GetValue(null, null);
return base.FormatErrorMessage(name);
return GetResourceString(ErrorMessageResourceName);
}
}
}

View File

@ -15,10 +15,14 @@ namespace Yavsc.Models.IT.Fixing
public long? FeatureId { get; set; }
[StringLength(240, ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug), ErrorMessageResourceName="TitleTooLong")]
[YaStringLength(240, MinimumLength=4 ,
ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug),
ErrorMessageResourceName="TitleSizeError")]
public string Title { get; set; }
[StringLength(4096)]
[YaStringLength(4096,
ErrorMessageResourceType=typeof(Yavsc.Models.IT.Fixing.Bug),
ErrorMessageResourceName="DescSizeError")]
public string Description { get; set; }
public BugStatus Status { get; set; }

View File

@ -1,12 +1,12 @@
//------------------------------------------------------------------------------
// <auto-generated>
// ------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
// Mono 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>
//------------------------------------------------------------------------------
// </autogenerated>
// ------------------------------------------------------------------------------
namespace Yavsc.Models.IT.Fixing {
using System;
@ -43,9 +43,15 @@ namespace Yavsc.Models.IT.Fixing {
}
}
public static string TitleTooLong {
public static string TitleSizeError {
get {
return ResourceManager.GetString("TitleTooLong", resourceCulture);
return ResourceManager.GetString("TitleSizeError", resourceCulture);
}
}
public static string DescSizeError {
get {
return ResourceManager.GetString("DescSizeError", resourceCulture);
}
}
}

View File

@ -58,5 +58,8 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TitleTooLong" comment="bug title validation"><value>The title is too long</value></data>
<data name="TitleSizeError" comment="bug title validation"><value>The title is too long ({0}..{1})</value></data>
<data name="DescSizeError" comment="bug title validation"><value>The description field is too long ({0} to {1})</value></data>
</root>

View File

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<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>
<!--
route name for the api controller used to tag the 'BlogPost' entity
-->
<data name="TitleTooLong" comment="validation du titre d'un bug"><value>Le titre est trop long</value></data>
</root>

View File

@ -58,5 +58,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="TitleTooLong" comment="bug title validation"><value>The title is too long</value></data>
<data name="TitleSizeError" comment="bug title validation"><value>Le titre est trop court ou trop long (sa taille va de {0} à {1})</value></data>
<data name="DescSizeError" comment="bug title validation"><value>Le champ description est trop court ou trop long (sa taille va de {0} à {1})</value></data>
</root>