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;
 }
Example #3
0
 public bool Validate(SchemaValidationResult errors)
 {
     object testSubject = this;
     return SchemaManager.Validate("urn:IEEE-1671:2010:Common", "IdentificationNumber", testSubject, errors);
 }
Example #4
0
 public bool Validate(SchemaValidationResult errors)
 {
     object testSubject = this;
     return SchemaManager.Validate("urn:IEEE-1671:2010:Common", "DatumType", testSubject, errors);
 }
Example #5
0
 public bool Validate(SchemaValidationResult errors)
 {
     object testSubject = this;
     return SchemaManager.Validate("urn:IEEE-1671:2010:Common", "hexadecimalArray", testSubject, errors);
 }
 public bool Validate( SchemaValidationResult errors )
 {
     object testSubject = this;
     return SchemaManager.Validate( ATMLCommon.HardwareCommonNameSpace, GetType().Name,
                                    testSubject, errors );
 }
 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();
 }
 public bool Validate(SchemaValidationResult errors)
 {
     object testSubject = this;
     return SchemaManager.Validate("urn:IEEE-1671:2010:HardwareCommon", "Switching", testSubject, errors);
 }
 public new bool Validate( SchemaValidationResult errors )
 {
     object testSubject = this;
     return SchemaManager.Validate( TestStationNameSpace, "TestStationDescription", testSubject, errors );
 }
        private static bool ProcessRestrictions( string value,
            SchemaValidationResult errors,
            XmlSchemaSimpleTypeRestriction restriction,
            string typeName,
            string name)
        {
            bool isValid = true;
            if (restriction == null)
                return false;

            foreach (object facet in restriction.Facets)
            {
                if (facet is XmlSchemaMinInclusiveFacet)
                {
                    var lf = facet as XmlSchemaMinInclusiveFacet;
                    if (!string.IsNullOrEmpty( value ))
                    {
                        int iResult;
                        double dResult;
                        if (( typeName.Contains( "int" ) && int.TryParse( value, out iResult ) &&
                              iResult < int.Parse( lf.Value ) )
                            ||
                            ( typeName.Contains( "dou" ) && double.TryParse( value, out dResult ) &&
                              dResult < double.Parse( lf.Value ) ))
                        {
                            errors.AddError( String.Format( "The value of {0} must not be less than {1}", name, lf.Value ) );
                            isValid = false;
                        }
                    }
                }
                else if (facet is XmlSchemaMinExclusiveFacet)
                {
                    var lf = facet as XmlSchemaMinExclusiveFacet;
                    if (!string.IsNullOrEmpty( value ))
                    {
                        int iResult;
                        double dResult;
                        if (( typeName.Contains( "int" ) && int.TryParse( value, out iResult ) &&
                              iResult <= int.Parse( lf.Value ) )
                            ||
                            ( typeName.Contains( "dou" ) && double.TryParse( value, out dResult ) &&
                              dResult <= double.Parse( lf.Value ) ))
                        {
                            errors.AddError( String.Format( "The value of {0} must not be less than or equal to {1}",
                                                            name,
                                                            lf.Value ) );
                            isValid = false;
                        }
                    }
                }
                else if (facet is XmlSchemaMaxInclusiveFacet)
                {
                    var lf = facet as XmlSchemaMaxInclusiveFacet;
                    if (!string.IsNullOrEmpty( value ))
                    {
                        int iResult;
                        double dResult;
                        if (( typeName.Contains( "int" ) && int.TryParse( value, out iResult ) &&
                              iResult > int.Parse( lf.Value ) )
                            ||
                            ( typeName.Contains( "dou" ) && double.TryParse( value, out dResult ) &&
                              dResult > double.Parse( lf.Value ) ))
                        {
                            errors.AddError( String.Format( "The value of {0} must not be greater than {1}", name,
                                                            lf.Value ) );
                            isValid = false;
                        }
                    }
                }
                else if (facet is XmlSchemaMaxExclusiveFacet)
                {
                    var lf = facet as XmlSchemaMaxExclusiveFacet;
                    if (!string.IsNullOrEmpty( value ))
                    {
                        int iResult;
                        double dResult;
                        if (( typeName.Contains( "int" ) && int.TryParse( value, out iResult ) &&
                              iResult >= int.Parse( lf.Value ) )
                            ||
                            ( typeName.Contains( "dou" ) && double.TryParse( value, out dResult ) &&
                              dResult >= double.Parse( lf.Value ) ))
                        {
                            errors.AddError( String.Format( "The value of {0} must not be greater than or equal to {1}",
                                                            name, lf.Value ) );
                            isValid = false;
                        }
                    }
                }
                else if (facet is XmlSchemaLengthFacet)
                {
                    var lf = facet as XmlSchemaLengthFacet;
                    if (!String.IsNullOrEmpty( value ) && value.Length > int.Parse( lf.Value ))
                    {
                        errors.AddError( String.Format( "The value's length must not excede {0} characters", lf.Value ) );
                        isValid = false;
                    }
                }
                else if (facet is XmlSchemaMinLengthFacet)
                {
                    var lf = facet as XmlSchemaMinLengthFacet;
                    if (!String.IsNullOrEmpty( value ) && value.Length < int.Parse( lf.Value ))
                    {
                        errors.AddError( String.Format( "The value's length must not be less than {0} characters",
                                                        lf.Value ) );
                        isValid = false;
                    }
                }
                else if (facet is XmlSchemaMaxLengthFacet)
                {
                    var lf = facet as XmlSchemaMaxLengthFacet;
                    if (!String.IsNullOrEmpty( value ) && value.Length > int.Parse( lf.Value ))
                    {
                        errors.AddError( String.Format( "The value's length must not be greater than {0} characters",
                                                        lf.Value ) );
                        isValid = false;
                    }
                }
                else if (facet is XmlSchemaPatternFacet)
                {
                    var spf = facet as XmlSchemaPatternFacet;
                    Console.WriteLine( spf.Id + @" : " + spf.Value );
                    if (value != null && !Regex.Match( value, spf.Value ).Success)
                    {
                        errors.AddError( String.Format( "The \"{0}\" value must match the regular expression: {1}", name,
                                                        spf.Value ) );
                        isValid = false;
                    }
                }
                else if (facet is XmlSchemaEnumerationFacet)
                {
                    //TODO:XmlSchemaEnumerationFacet
                    int i = 0;
                }
                else if (facet is XmlSchemaTotalDigitsFacet)
                {
                    //TODO:XmlSchemaTotalDigitsFacet
                    int i = 0;
                }
                else if (facet is XmlSchemaWhiteSpaceFacet)
                {
                    //TODO:XmlSchemaWhiteSpaceFacet
                    int i = 0;
                }
            }

            return isValid;
        }
        private void HardwareItemDescriptionControl_Validating( object sender, CancelEventArgs e )
        {
            tabInterface.BackColor = Color.White;
            operationalRequirementsControl.HasErrors = false;
            interfaceListControl.HasErrors = false;
            legalDocumentListControl.HasErrors = false;
            errorProvider.SetError( interfaceListControl, "" );
            errorProvider.SetError( operationalRequirementsControl, "" );
            errorProvider.SetError( legalDocumentListControl, "" );

            foreach (TabPage tabPage in tabPanelControl.TabPages)
                tabPage.ToolTipText = "";

            //-------------------------------------------------------------------------------------------------------//
            //--- TODO: Would like to generically walk all the tab controls to validate and set the tooltip text. ---//
            //-------------------------------------------------------------------------------------------------------//
            string defError;
            if (factoryDefaultsListControl.FactoryDefaults != null &&
                !factoryDefaultsListControl.Validate( out defError ))
            {
                errorProvider.SetError(factoryDefaultsListControl, defError );
                tabDefaults.ToolTipText = defError;
                OnError(sender, errorProvider.GetError(this));
            }

            if (identificationControl.Identification == null
                || string.IsNullOrEmpty( identificationControl.Identification.ModelName ))
            {
                errorProvider.SetError(identificationControl, Resources.errmsg_An_Identification_Model_Name_is_required_);
                tabIdentification.ToolTipText = Resources.errmsg_An_Identification_Model_Name_is_required_;
                e.Cancel = true;
                OnError(sender, errorProvider.GetError(this));
            }

            if (operationalRequirementsControl.OperationalRequirements != null)
            {
                var errors = new SchemaValidationResult();
                if (!operationalRequirementsControl.OperationalRequirements.Validate( errors ))
                {
                    errorProvider.SetError( operationalRequirementsControl, errors.ErrorMessage );
                    tabRequirements.ToolTipText = errors.ErrorMessage;
                    tabOperational.ToolTipText = errors.ErrorMessage;
                    operationalRequirementsControl.HasErrors = true;
                    OnError( sender, errors.ErrorMessage );
                }
            }

            if (interfaceListControl.PhysicalInterface != null
                && ( interfaceListControl.PhysicalInterface.Items == null || (interfaceListControl.PhysicalInterface.Items != null
                && interfaceListControl.PhysicalInterface.Items.Count == 0 )) )
            {
                errorProvider.SetError( interfaceListControl, Resources.errmsg_at_least_one_interface_item );
                tabInterface.ToolTipText = Resources.errmsg_at_least_one_interface_item;
                interfaceListControl.HasErrors = true;
                OnError( sender, errorProvider.GetError( this ) );
            }

            if (legalDocumentListControl.LegalDocuments != null)
            {
                string error;
                if (!legalDocumentListControl.Validate( out error ))
                {
                    tabLegal.ToolTipText = error;
                    legalDocumentListControl.HasErrors = true;
                    errorProvider.SetError(legalDocumentListControl, error );
                    OnError(sender, errorProvider.GetError(this));
                }
            }
        }
        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 );
        }
        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;
        }
        public static bool ValidateElement( XmlSchemaElement element, object value, SchemaValidationResult errors )
        {
            bool isValid = true;
            XmlSchemaType schemaType = element.ElementSchemaType;
            bool isNillable = element.IsNillable;
            string defaultValue = element.DefaultValue;
            decimal minOccurrs = element.MinOccurs;
            decimal maxOccurrs = element.MaxOccurs;
            //SchemaValidationResult errors = new SchemaValidationResult(element.Name );

            var complexType = schemaType as XmlSchemaComplexType;
            var simpleType = schemaType as XmlSchemaSimpleType;

            if (minOccurrs > 0 && value == null && !isNillable)
            {
                isValid = false;
                errors.AddError( string.Format( "{0} cannot be null", element.Name ) );
            }
            else if (complexType != null)
            {
                var collection = value as ICollection;
                if (collection != null)
                {
                    XmlSchemaParticle contentTypeParticle = complexType.ContentTypeParticle;
                    XmlSchemaParticle particle = complexType.Particle;
                    XmlSchemaContentModel model = complexType.ContentModel;
                    var sequence = particle as XmlSchemaSequence;
                    if (sequence != null)
                    {
                        ProcessSequence( errors, sequence, collection, minOccurrs );
                    }
                }
            }
            else if (simpleType != null)
            {
                var union = simpleType.Content as XmlSchemaSimpleTypeUnion;
                var list = simpleType.Content as XmlSchemaSimpleTypeList;
                var restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;

                if (restriction != null)
                {
                    XmlQualifiedName qname = simpleType.BaseXmlSchemaType.QualifiedName;
                    String typeName = qname.Name;
                    isValid &= ProcessRestrictions( value == null ? null : value.ToString(), errors, restriction,
                                                    typeName, simpleType.Name );
                }

                foreach (XmlSchemaObject contraint in element.Constraints)
                {
                    var key = contraint as XmlSchemaKey;
                    var keyRef = contraint as XmlSchemaKeyref;
                    var unique = contraint as XmlSchemaUnique;
                    if (key != null)
                    {
                    }
                    if (keyRef != null)
                    {
                    }
                    if (unique != null)
                    {
                    }
                }
            }

            XmlTypeCode tc = schemaType.TypeCode;
            //validationResult.AddResult( errors );
            return isValid;
        }
        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();
        }
 public static bool ValidateAttribute( XmlSchemaAttribute attribute, string value, SchemaValidationResult errors )
 {
     bool isValid = true;
     XmlSchemaSimpleType attributeSchemaType = attribute.AttributeSchemaType;
     XmlSchemaUse use = attribute.Use;
     string name = attribute.Name;
     bool required = ( use == XmlSchemaUse.Required );
     if (required && string.IsNullOrEmpty( value ))
     {
         isValid = false;
         errors.AddError( string.Format( "{0} is required\n", name ) );
     }
     if (attributeSchemaType.Content is XmlSchemaSimpleTypeRestriction)
     {
         XmlQualifiedName qname = attributeSchemaType.BaseXmlSchemaType.QualifiedName;
         String typeName = qname.Name;
         var restriction = (XmlSchemaSimpleTypeRestriction) attributeSchemaType.Content;
         isValid &= ProcessRestrictions( value, errors, restriction, typeName, name );
     }
     return isValid;
 }
 public bool Validate( SchemaValidationResult errors )
 {
     object testSubject = this;
     return SchemaManager.Validate( TestEquipmentNameSpace, "OperatingSystem", testSubject,
                                    errors );
 }
 public bool Validate( SchemaValidationResult errors )
 {
     object testSubject = this;
     return SchemaManager.Validate( "urn:IEEE-1671.4:2009.03:TestConfiguration", "TestConfiguration", testSubject,
                                    errors );
 }
 public bool Validate(SchemaValidationResult errors)
 {
     object testSubject = this;
     return SchemaManager.Validate("urn:IEEE-1671:2010:HardwareCommon", "FacilitiesRequirements", testSubject, errors);
 }
 public bool Validate(SchemaValidationResult errors)
 {
     object testSubject = this;
     return SchemaManager.Validate("urn:IEEE-1671.2:2012:InstrumentDescription", "Bus", testSubject, errors);
 }
 public new bool Validate( SchemaValidationResult errors )
 {
     object testSubject = this;
     return SchemaManager.Validate( ATMLCommon.TestEquipmentNameSpace, "TerminalBlock", testSubject,
                                    errors );
 }
 private static void ProcessSequence( SchemaValidationResult errors, XmlSchemaSequence sequence,
     ICollection collection,
     decimal minOccurrs)
 {
     foreach (XmlSchemaObject item in sequence.Items)
     {
         var se = item as XmlSchemaElement;
         var gr = item as XmlSchemaGroupRef;
         var sc = item as XmlSchemaChoice;
         var ss = item as XmlSchemaSequence;
         var sa = item as XmlSchemaAny;
         if (se != null)
         {
             decimal max = se.MaxOccurs;
             decimal min = se.MinOccurs;
             string maxString = se.MaxOccursString;
             string minString = se.MinOccursString;
             if (collection.Count > max)
                 errors.AddError( string.Format( "{0} count may not be more than {1}", se.Name,
                                                 string.IsNullOrEmpty( maxString ) ? "" + max : maxString ) );
             if (collection.Count < min && minOccurrs > 0)
                 errors.AddError( string.Format( "{0} count may not be less than {1}", se.Name,
                                                 ( string.IsNullOrEmpty( minString ) ? "" + min : minString ) ) );
         }
         else if (sc != null)
         {
             foreach (XmlSchemaObject scItem in sc.Items)
             {
                 var scse = scItem as XmlSchemaElement;
                 var scgr = scItem as XmlSchemaGroupRef;
                 var scsc = scItem as XmlSchemaChoice;
                 var scss = scItem as XmlSchemaSequence;
                 var scsa = scItem as XmlSchemaAny;
             }
         }
         else if (ss != null)
         {
             //ProcessSequence(errors, ss, ICollection collection,
         }
     }
 }
 public bool Validate( SchemaValidationResult errors )
 {
     object testSubject = this;
     return SchemaManager.Validate( ATMLCommon.HardwareCommonNameSpace, "TriggerPropertyGroup",
                                    testSubject, errors );
 }
Example #24
0
 public new bool Validate(SchemaValidationResult schemaValidationResult)
 {
     object testSubject = this;
     bool isValid = SchemaManager.Validate("urn:IEEE-1671:2010:Common", "Connector", testSubject,
                                           schemaValidationResult);
     return isValid;
 }
        void TestEquipmentControl_Validating(object sender, CancelEventArgs e)
        {
            TestEquipment testEquipment = TestEquipment;
            if (testEquipment != null)
            {
                if (testEquipment.FacilitiesRequirements != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.FacilitiesRequirements.Validate( svr ))
                        tabFacilities.ToolTipText = svr.ErrorMessage;
                }
                if (testEquipment.Controllers != null)
                {
                    foreach (Controller controller in testEquipment.Controllers)
                    {
                        var svr = new SchemaValidationResult();
                        if (!controller.Validate(svr))
                            tabControllers.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Software != null)
                {
                    foreach (ItemDescription itemDescription in testEquipment.Software)
                    {
                        var svr = new SchemaValidationResult();
                        if (!itemDescription.Validate(svr))
                            tabSoftware.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Paths != null)
                {
                    foreach (Path item in testEquipment.Paths)
                    {
                        var svr = new SchemaValidationResult();
                        if (!item.Validate(svr))
                            tabPaths.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Specifications != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.Specifications.Validate(svr))
                        tabSpecifications.ToolTipText = svr.ErrorMessage;
                }
                if (testEquipment.Switching != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.Switching.Validate(svr))
                        tabSwitching.ToolTipText = svr.ErrorMessage;
                }
                if (testEquipment.Resources != null)
                {
                    foreach (Resource item in testEquipment.Resources)
                    {
                        var svr = new SchemaValidationResult();
                        if (!item.Validate(svr))
                            tabResources.ToolTipText = svr.ErrorMessage;
                    }
                }
                if (testEquipment.Capabilities != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.Capabilities.Validate(svr))
                        tabCapabilities.ToolTipText = svr.ErrorMessage;
                }
                if (testEquipment.TerminalBlocks != null)
                {
                    var svr = new SchemaValidationResult();
                    if (!testEquipment.TerminalBlocks.Validate(svr))
                        tabTerminalBlocks.ToolTipText = svr.ErrorMessage;
                }

            }
        }
 public void AddResult( SchemaValidationResult result )
 {
     _results.Add( result );
 }