From e264cb7f431f009f9cac20eb7beea3d54c410120 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 5 Sep 2019 15:06:55 +0100 Subject: [PATCH] Path validation * invalid path message * its validation attribute --- .../Validation/ValidRemoteUserDirAttribute.cs | 32 +++++++++++++++++++ ...ttributes.Validation.Resources.Designer.cs | 24 ++++++++------ ...sc.Attributes.Validation.Resources.en.resx | 1 + ...c.Attributes.Validation.Resources.pt.resx} | 1 + ...Yavsc.Attributes.Validation.Resources.resx | 1 + 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs rename src/Yavsc.Abstract/Resources/{Yavsc.Attributes.Validation.Resources pt.resx => Yavsc.Attributes.Validation.Resources.pt.resx} (97%) diff --git a/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs b/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs new file mode 100644 index 00000000..5b662870 --- /dev/null +++ b/src/Yavsc.Abstract/Attributes/Validation/ValidRemoteUserDirAttribute.cs @@ -0,0 +1,32 @@ + +using System; +using System.ComponentModel.DataAnnotations; +using Yavsc.Helpers; + +namespace Yavsc.Attributes.Validation +{ + /// + /// Valid Remote User Dir Attribute + /// + public class ValidRemoteUserFilePathAttribute : ValidationAttribute + { + public ValidRemoteUserFilePathAttribute() + { + UseDefaultErrorMessage(); + } + void UseDefaultErrorMessage() + { + if (ErrorMessageResourceType==null) { + ErrorMessageResourceType = typeof(Yavsc.Attributes.Validation.Resources); + ErrorMessageResourceName = "InvalidPath"; + } + } + + public override bool IsValid(object value) + { + if (value == null) return true; + var str = (string) value; + return str.IsValidYavscPath(); + } + } +} \ No newline at end of file diff --git a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.Designer.cs b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.Designer.cs index 2ac3ea78..b275ec3d 100644 --- a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.Designer.cs +++ b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.Designer.cs @@ -1,12 +1,12 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Mono Runtime Version: 4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +// +// 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 Yavsc.Attributes.Validation { using System; @@ -54,5 +54,11 @@ namespace Yavsc.Attributes.Validation { return ResourceManager.GetString("InvalidStringLength", resourceCulture); } } + + public static string InvalidPath { + get { + return ResourceManager.GetString("InvalidPath", resourceCulture); + } + } } } diff --git a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.en.resx b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.en.resx index 4ceb9e7d..8dcda16e 100644 --- a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.en.resx +++ b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.en.resx @@ -63,4 +63,5 @@ --> Please, fill in this field Invalid string length ({0}..{1}) + Invalid file path \ No newline at end of file diff --git a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources pt.resx b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.pt.resx similarity index 97% rename from src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources pt.resx rename to src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.pt.resx index 82f63d19..187d3376 100644 --- a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources pt.resx +++ b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.pt.resx @@ -63,5 +63,6 @@ --> Por favor, preencha este campo comprimento inválido da corrente ({0}..{1}) + Camino de arquivo invalido \ No newline at end of file diff --git a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.resx b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.resx index 5191f9de..0722114d 100644 --- a/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.resx +++ b/src/Yavsc.Abstract/Resources/Yavsc.Attributes.Validation.Resources.resx @@ -63,4 +63,5 @@ --> Veuillez renseigner ce champ Longueur de chaine invalide ({0}..{1}) + Chemin de fichier invalide \ No newline at end of file