private PropertyValidatorDescriptor ValidatorFromNode(XElement item)
        {
            PropertyValidatorDescriptor descriptor = new PropertyValidatorDescriptor();
            XElement   elem;
            XAttribute attr;

            if ((attr = item.Attribute("messageTemplate")) != null)
            {
                descriptor.MessageTemplate = attr.Value;
            }
            if ((attr = item.Attribute("name")) != null)
            {
                descriptor.Name = attr.Value;
            }
            if ((attr = item.Attribute("tag")) != null)
            {
                descriptor.Tag = attr.Value;
            }
            if ((attr = item.Attribute("typeDescription")) != null)
            {
                descriptor.TypeDescription = attr.Value;
            }
            if ((elem = item.Element("parameters")) != null)
            {
                AddParameters(elem, descriptor.Parameters);
            }

            return(descriptor);
        }
		// add by yandezhi
		public ClientVdtAttribute(PropertyValidatorDescriptor propDesp)
		{
			this.messageTemplate = propDesp.MessageTemplate;
			if (propDesp.GetValidator() is IClientValidatable)
			{
				this.clientValidateMethodName =
					((IClientValidatable)propDesp.GetValidator()).ClientValidateMethodName;
			}
		}
Beispiel #3
0
        private static PropertyValidatorDescriptor PreparePropertyValidatorDescriptor()
        {
            PropertyValidatorDescriptor propValidDesp = new PropertyValidatorDescriptor();

            propValidDesp.Name            = "测试";
            propValidDesp.MessageTemplate = "测试MessageTemplate";
            propValidDesp.Tag             = "测试属性";
            propValidDesp.Parameters.Add(PreparePropertyValidatorParameterDescriptor());
            propValidDesp.TypeDescription = "MCS.Library.Validation.StringEmptyValidator,MCS.Library";

            return(propValidDesp);
        }
Beispiel #4
0
        private static PropertyValidatorDescriptor DefalutPreparePropertyValidatorDescriptor()
        {
            PropertyValidatorDescriptor propValidDesp = new PropertyValidatorDescriptor();

            propValidDesp.Name            = "测试Name";
            propValidDesp.MessageTemplate = "MessageTemplate";
            propValidDesp.Tag             = "测试Tag";
            propValidDesp.TypeDescription = "MCS.Library.Validation.StringEmptyValidator,MCS.Library";
            propValidDesp.Parameters.CopyFrom(PropertyValidatorParameterDescriptorSerializationTest.PreparePropertyValidatorParametDescriptorCollection());

            return(propValidDesp);
        }
Beispiel #5
0
        public void PropertyValidatorJSONConverterTest()
        {
            RegisterConverter();

            PropertyValidatorDescriptor pv = PreparePropertyValidatorDescriptor();

            string result = JSONSerializerExecute.Serialize(pv);

            Console.WriteLine(result);

            PropertyValidatorDescriptor deserializedDesp = JSONSerializerExecute.Deserialize <PropertyValidatorDescriptor>(result);

            string reSerialized = JSONSerializerExecute.Serialize(deserializedDesp);

            Assert.AreEqual(result, reSerialized);
        }
		public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
		{
			PropertyValidatorDescriptor propValiDesp = new PropertyValidatorDescriptor();
			propValiDesp.Name = DictionaryHelper.GetValue(dictionary, "name", string.Empty);
			propValiDesp.TypeDescription = DictionaryHelper.GetValue(dictionary, "typeDescription", string.Empty);
			propValiDesp.MessageTemplate = DictionaryHelper.GetValue(dictionary, "messageTemplate", string.Empty);
			propValiDesp.Tag = DictionaryHelper.GetValue(dictionary, "tag", string.Empty);

			if (dictionary.ContainsKey("validatorParameters") == true)
			{
				PropertyValidatorParameterDescriptorCollection parameters = JSONSerializerExecute.Deserialize<PropertyValidatorParameterDescriptorCollection>(dictionary["validatorParameters"]);
				propValiDesp.Parameters.Clear();
				propValiDesp.Parameters.CopyFrom(parameters);
			}

			return propValiDesp;
		}
        private void ValidatorToNode(PropertyValidatorDescriptor descriptor, XElement containerElement)
        {
            XElement elem = new XElement("validator");

            elem.Add(new XAttribute("messageTemplate", descriptor.MessageTemplate));
            elem.Add(new XAttribute("name", descriptor.Name));
            elem.Add(new XAttribute("tag", descriptor.Tag));
            elem.Add(new XAttribute("typeDescription", descriptor.TypeDescription));
            if (descriptor.Parameters != null && descriptor.Parameters.Count > 0)
            {
                var xParams = new XElement("parameters");
                elem.Add(xParams);
                foreach (var para in descriptor.Parameters)
                {
                    xParams.Add(new XElement("parameter", new XAttribute("dataType", para.DataType), new XAttribute("paraName", para.ParamName), new XAttribute("paraValue", para.ParamValue)));
                }
            }
        }
Beispiel #8
0
        public void PropertyValidatorSerializeTest()
        {
            PropertyValidatorDescriptor pv = PreparePropertyValidatorDescriptor();

            XElementFormatter formatter = new XElementFormatter();

            XElement root = formatter.Serialize(pv);

            Console.WriteLine(root.ToString());

            PropertyValidatorDescriptor newPropertyValue = (PropertyValidatorDescriptor)formatter.Deserialize(root);

            XElement rootReserialized = formatter.Serialize(newPropertyValue);

            Assert.AreEqual(root.ToString(), rootReserialized.ToString());
            Assert.AreEqual(pv.Tag, newPropertyValue.Tag);
            Assert.AreEqual(pv.TypeDescription, newPropertyValue.TypeDescription);
            Assert.AreEqual(pv.Name, newPropertyValue.Name);
            Assert.AreEqual(pv.Parameters.Count, newPropertyValue.Parameters.Count);
        }
Beispiel #9
0
        public static void Output(this PropertyValidatorDescriptor propertyValidator, TextWriter writer, int indent = 0)
        {
            string indentChars = new string('\t', indent);

            writer.WriteLine("{0}Name={1}, Type={2}, MessageTemplate={3}",
                             indentChars,
                             propertyValidator.Name,
                             propertyValidator.TypeDescription,
                             propertyValidator.MessageTemplate);

            if (propertyValidator.Parameters.Count > 0)
            {
                indent++;

                WriteLine(writer, "Begin Parameters", indent);

                indent++;
                propertyValidator.Parameters.ForEach(p => p.Output(writer, indent));
                indent--;

                WriteLine(writer, "End Parameters", indent);
            }
        }
Beispiel #10
0
        public void PropertyStringEmptyValidatorTest()
        {
            PropertyDefine pd = new PropertyDefine();

            pd.Name = "UserName";

            PropertyValidatorDescriptor pvd = new PropertyValidatorDescriptor();

            pvd.MessageTemplate = "属性UserName不能为空";
            pvd.TypeDescription = "MCS.Library.Validation.StringEmptyValidator, MCS.Library";

            pd.Validators.Add(pvd);

            PropertyValue pv = new PropertyValue(pd);

            ValidationResults results = new ValidationResults();

            pv.Validate(results);

            Console.WriteLine(results);

            Assert.AreEqual(1, results.ResultCount);
            Assert.AreEqual(pvd.MessageTemplate, results.First().Message);
        }
		private static PropertyValidatorDescriptor PreparePropertyValidatorDescriptor()
		{
			PropertyValidatorDescriptor propValidDesp = new PropertyValidatorDescriptor();

			propValidDesp.Name = "测试";
			propValidDesp.MessageTemplate = "测试MessageTemplate";
			propValidDesp.Tag = "测试属性";
			propValidDesp.Parameters.Add(PreparePropertyValidatorParameterDescriptor());
			propValidDesp.TypeDescription = "MCS.Library.Validation.StringEmptyValidator,MCS.Library";

			return propValidDesp;
		}
		private static PropertyValidatorDescriptor DefalutPreparePropertyValidatorDescriptor()
		{
			PropertyValidatorDescriptor propValidDesp = new PropertyValidatorDescriptor();

			propValidDesp.Name = "测试Name";
			propValidDesp.MessageTemplate = "MessageTemplate";
			propValidDesp.Tag = "测试Tag";
			propValidDesp.TypeDescription = "MCS.Library.Validation.StringEmptyValidator,MCS.Library";
			propValidDesp.Parameters.CopyFrom(PropertyValidatorParameterDescriptorSerializationTest.PreparePropertyValidatorParametDescriptorCollection());

			return propValidDesp;
		}
		public void PropertyStringEmptyValidatorTest()
		{
			PropertyDefine pd = new PropertyDefine();

			pd.Name = "UserName";

			PropertyValidatorDescriptor pvd = new PropertyValidatorDescriptor();

			pvd.MessageTemplate = "属性UserName不能为空";
			pvd.TypeDescription = "MCS.Library.Validation.StringEmptyValidator, MCS.Library";

			pd.Validators.Add(pvd);

			PropertyValue pv = new PropertyValue(pd);

			ValidationResults results = new ValidationResults();

			pv.Validate(results);

			Console.WriteLine(results);

			Assert.AreEqual(1, results.ResultCount);
			Assert.AreEqual(pvd.MessageTemplate, results.First().Message);
		}