trying to localize
This commit is contained in:
parent
a93573dce8
commit
b9a75b71b8
32 changed files with 510 additions and 68 deletions
19
src/Yavsc.Abstract/Attributes/ActivityBillingAttribute.cs
Normal file
19
src/Yavsc.Abstract/Attributes/ActivityBillingAttribute.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Yavsc.Attributes
|
||||
{
|
||||
public class ActivityBillingAttribute : Attribute
|
||||
{
|
||||
public string BillingCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Identifie une entité de facturation
|
||||
/// </summary>
|
||||
/// <param name="billingCode">Code de facturation,
|
||||
/// Il doit avoir une valeur unique par usage.
|
||||
/// </param>
|
||||
public ActivityBillingAttribute(string billingCode) {
|
||||
BillingCode = billingCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Yavsc.Attributes
|
||||
{
|
||||
public class ActivitySettingsAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaRegularExpression : System.ComponentModel.DataAnnotations.RegularExpressionAttribute {
|
||||
public YaRegularExpression(string pattern): base (pattern)
|
||||
{
|
||||
this.ErrorMessage = pattern;
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
var prop = this.ErrorMessageResourceType.GetProperty(ErrorMessageResourceName);
|
||||
return (string) prop.GetValue(null, BindingFlags.Static, null, null, System.Globalization.CultureInfo.CurrentUICulture);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class YaRequiredAttribute : YaValidationAttribute
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a flag indicating whether the attribute should allow empty strings.
|
||||
/// </summary>
|
||||
public bool AllowEmptyStrings { get; set; }
|
||||
public YaRequiredAttribute (string msg) : base(msg)
|
||||
{
|
||||
ErrorMessage = msg;
|
||||
}
|
||||
public YaRequiredAttribute () : base("RequiredField")
|
||||
{
|
||||
|
||||
}
|
||||
public override bool IsValid(object value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only check string length if empty strings are not allowed
|
||||
var stringValue = value as string;
|
||||
if (stringValue != null && !AllowEmptyStrings) {
|
||||
return stringValue.Trim().Length != 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
47
src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs
Normal file
47
src/Yavsc.Abstract/Attributes/Validation/YaStringLength.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaStringLength: YaValidationAttribute
|
||||
{
|
||||
public long MinLen { get; set; } = -1;
|
||||
private long maxLen;
|
||||
public YaStringLength(long maxLen) : base(
|
||||
()=>
|
||||
"BadStringLength")
|
||||
{
|
||||
this.maxLen = maxLen;
|
||||
}
|
||||
|
||||
private long excedent=0;
|
||||
private long manquant=0;
|
||||
|
||||
public override bool IsValid(object value) {
|
||||
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
Console.WriteLine("Validating string length for "+value.ToString());
|
||||
|
||||
string stringValue = value as string;
|
||||
if (stringValue==null) return false;
|
||||
if (MinLen>=0)
|
||||
{
|
||||
if (stringValue.Length<MinLen)
|
||||
{
|
||||
manquant = MinLen-stringValue.Length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (maxLen>=0)
|
||||
{
|
||||
if (stringValue.Length>maxLen) {
|
||||
excedent = stringValue.Length-maxLen;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Yavsc.Attributes.Validation
|
||||
{
|
||||
public class YaValidationAttribute : System.ComponentModel.DataAnnotations.ValidationAttribute
|
||||
{
|
||||
public YaValidationAttribute(string msg) : base(msg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public YaValidationAttribute(Func<string> acr): base(acr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override string FormatErrorMessage(string name)
|
||||
{
|
||||
if (ErrorMessageResourceType == null) // failed :/
|
||||
return 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using Yavsc.Attributes.Validation;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
|
|
@ -7,7 +8,7 @@ namespace Yavsc.ApiControllers
|
|||
public string ApiKey { get ; set; }
|
||||
[Required]
|
||||
public string Component { get ; set; }
|
||||
[Required][StringLength(1024)]
|
||||
[Required][YaStringLength(1024)]
|
||||
public string ExceptionObjectJson { get ; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue