HasErrors() 공개 메소드

public HasErrors ( ) : bool
리턴 bool
 public bool Validate( out string error )
 {
     bool isValid = true;
     StringBuilder sb = new StringBuilder();
     foreach (NamedValue factoryDefault in _factoryDefaults)
     {
         SchemaValidationResult svr = new SchemaValidationResult();
         isValid &= factoryDefault.Validate( svr );
         if (svr.HasErrors())
             sb.Append( svr.ErrorMessage ).Append( ", " );
     }
     if( sb.ToString().EndsWith( ", " ) )
         sb.Length = sb.Length - 2;
     error = sb.ToString();
     return isValid;
 }
 public bool Validate(out string error)
 {
     error = null;
     bool isValid = true;
     var sb = new StringBuilder();
     if (_legalDocuments.Items != null)
     {
         foreach (var document in _legalDocuments.Items)
         {
             var svr = new SchemaValidationResult();
             isValid &= document.Validate(svr);
             if (svr.HasErrors())
                 sb.Append( svr.ErrorMessage ).Append( ", " );
         }
         if (sb.ToString().EndsWith( ", " ))
             sb.Length = sb.Length - 2;
         error = sb.ToString();
     }
     return isValid;
 }
예제 #3
0
        private static bool ProcessPropertyInfo( object testSubject, SchemaValidationResult validationResults,
            PropertyInfo propertyInfo,
            Dictionary<string, XmlSchemaObject> xmlSchemaObjects, bool isValid)
        {
            string name = propertyInfo.Name;
            object oValue = propertyInfo.GetValue( testSubject, null );
            bool ok2Run = false;
            if (oValue != null)
            {
                MethodInfo mmi = oValue.GetType().GetMethod( "Validate" );
                var collection = oValue as ICollection;
                if (collection != null)
                {
                    //Need to get the type of each item schema
                    foreach (object obj in collection)
                    {
                        MethodInfo mi = obj.GetType().GetMethod( "Validate" );
                        if (mi != null)
                        {
                            var result = new SchemaValidationResult( name );
                            object[] p = {result};
                            try
                            {
                                mi.Invoke( obj, p );
                                object po = p[0];
                                validationResults.AddResult( result );
                            }
                            catch (Exception)
                            {
                                int i = 0;
                            }
                        }
                    }
                    ok2Run = true;
                }
                else if (mmi != null)
                {
                    var result = new SchemaValidationResult( name );
                    object[] p = {result};
                    mmi.Invoke( oValue, p );
                    validationResults.AddResult( result );
                    isValid = !result.HasErrors();
                }
                else
                {
                    ok2Run = true;
                }
            }
            else
            {
                ok2Run = true;
            }
            if (xmlSchemaObjects.ContainsKey( name ) && ok2Run)
            {
                string value = oValue != null ? oValue.ToString() : null;
                XmlSchemaObject schemaObject = xmlSchemaObjects[name];
                var attribute = schemaObject as XmlSchemaAttribute;
                var element = schemaObject as XmlSchemaElement;
                if (attribute != null)
                    isValid &= ValidateAttribute( attribute, value, validationResults );
                if (element != null)
                {
                    string ename = element.Name;
                    string enamespace = element.QualifiedName.Namespace;
                    bool isNillable = element.IsNillable;
                    isValid &= ValidateElement( element, oValue, validationResults );
                    var sct = element.ElementSchemaType as XmlSchemaComplexType;
                    if (sct != null)
                    {
                        //Validate(sct, o, errors);
                        int i = 0;
                    }

                    //Validate(enamespace, ename, o, errors);
                }
            }
            else
            {
                int i = 0;
            }
            return isValid;
        }
예제 #4
0
        public static void ValidateToSchema( object item )
        {
            MethodInfo miValidate = item.GetType().GetMethod( "Validate" );
            if (miValidate == null)
                throw new Exception( string.Format( "{0} does not support the Validate Method", item.GetType().Name ) );

            var errors = new SchemaValidationResult();
            object[] p = {errors};
            miValidate.Invoke( item, p );
            if (errors.HasErrors())
            {
                throw new Exception( string.Format(
                    "This {0} has failed validation against the ATML Schema with the following errors:\n{1}",
                    item.GetType().Name, errors.ErrorMessage ) );
            }

            MessageBox.Show( string.Format(
                "This {0} has passed all validation against the ATML Schema.",
                item.GetType().Name ), @"V a l i d a t i o n", MessageBoxButtons.OK, MessageBoxIcon.Information );
        }
예제 #5
0
        public static bool ValidateComplexType( XmlSchemaComplexType complexType, object testSubject,
            SchemaValidationResult parentValidationResult)
        {
            bool isValid = true;
            var result = new SchemaValidationResult( testSubject.GetType().Name, testSubject );
            var xmlSchemaObjects = new Dictionary<string, XmlSchemaObject>();
            XmlSchemaContentModel contentModel = complexType.ContentModel;
            ExtractSequenceItems( complexType, xmlSchemaObjects );
            parentValidationResult.AddResult( result );

            if (contentModel != null)
                ExtractContentItems( contentModel, xmlSchemaObjects );

            ExtractAttributes( complexType, xmlSchemaObjects );

            PropertyInfo[] props = testSubject.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in props)
            {
                try
                {
                    isValid &= ProcessPropertyInfo( testSubject, result, propertyInfo, xmlSchemaObjects, isValid );
                }
                catch (Exception e)
                {
                    int i = 0;
                }
            }
            return result.HasErrors();
        }
예제 #6
0
 public static bool Validate( string nameSpace, string elementName, object testSubject,
     SchemaValidationResult schemaValidationResult)
 {
     bool isValid = true;
     XmlSchemaComplexType complexType;
     XmlSchemaElement element;
     if (GetComplexType( nameSpace, elementName, out complexType ))
     {
         isValid &= ValidateComplexType( complexType, testSubject, schemaValidationResult );
     }
     else
     {
         if (Instance._schemaTypes.ContainsKey( nameSpace + ":" + elementName ))
         {
             int i = 0;
         }
         if (GetElement( nameSpace, elementName, out element ))
         {
             isValid &= ValidateElement( element, testSubject, schemaValidationResult );
         }
     }
     return !schemaValidationResult.HasErrors();
 }