示例#1
0
 /// <summary>
 /// handle XML validation errors
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 internal void SchemaValidationEventHandler(object sender, ValidationEventArgs args)
 {
     if (args.Severity.Equals(XmlSeverityType.Error))
     {
         isValid = false;
         WriteToLog(ParserValidationArgs.NewError(args.Message).ToString());
     }
     else
     {
         WriteToLog(ParserValidationArgs.NewWarning(args.Message).ToString());
     }
 }
        /// <summary>
        /// Post-parse validations
        /// </summary>
        /// <param name="vd"></param>
        protected void Validate(ParserValidationDelegate vd)
        {
            //TODO: walk through collection to make sure that cross relations are correct.

            foreach (DatabaseElement database in databases)
            {
                foreach (SqlEntityElement sqlentity in database.SqlEntities)
                {
                    if (sqlentity.GetPrimaryKeyColumns().Count == 0 && (sqlentity.AllowDelete || sqlentity.AllowInsert || sqlentity.AllowUpdate))
                    {
                        vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any primary key columns defined."));
                    }

                    if (!sqlentity.HasUpdatableColumns() && sqlentity.GenerateUpdateStoredProcScript)
                    {
                        vd(ParserValidationArgs.NewWarning("SqlEntity " + sqlentity.Name + " does not have any editable columns and does not have generateupdatestoredprocscript=\"false\" specified."));
                    }
                }
            }

            // make sure that all columns are represented in entities
            foreach (EntityElement entity in entities)
            {
                if (entity.SqlEntity.Name.Length > 0)
                {
                    foreach (ColumnElement column in entity.SqlEntity.Columns)
                    {
                        if (!column.Obsolete && EntityElement.FindAnyFieldByColumnName(entities, column.Name) == null && !entity.HasEntityMappedColumn(column))
                        {
                            vd(ParserValidationArgs.NewWarning("could not find property representing column " + column.Name + " in entity " + entity.Name + "."));
                        }
                    }
                }

                foreach (PropertyElement property in entity.Fields)
                {
                    // make sure that obsolete columns are not mapped to properties
                    if (property.Column.Obsolete && property.Column.Name.Length > 0)
                    {
                        vd(ParserValidationArgs.NewWarning("property " + property.Name + " in entity " + entity.Name + " is mapped to column " + property.Column.Name + " which is obsolete."));
                    }

                    // have property descriptions "inherit" from a column if they are not populated
                    if (property.Column.Description.Length > 0 && property.Description.Length == 0)
                    {
                        property.Description = property.Column.Description;
                    }
                }
            }

            // make sure that enum values are unique
            foreach (EnumElement enumtype in enumtypes)
            {
                Hashtable values = new Hashtable();
                foreach (EnumValueElement value in enumtype.Values)
                {
                    if (values.Contains(value.Code))
                    {
                        vd(ParserValidationArgs.NewError("Enum " + enumtype.Name + " has the code '" + value.Code + "' specified more than once."));
                    }
                    else
                    {
                        values.Add(value.Code, value.Code);
                    }
                }
            }

            // find and assign types to collections if available (the TypeElement is needed for templates that need to add namespaces)
            foreach (CollectionElement collection in Collections)
            {
                if (types.Contains(collection.Type.Name))
                {
                    collection.Type = (TypeElement)types[collection.Type.Name];
                }
            }

            foreach (TaskElement task in generator.Tasks)
            {
                IWriter w = GetWriter(task.Writer);
                if (w == null)
                {
                    vd(ParserValidationArgs.NewError("Task specified writer '" + task.Writer + "' that was not defined."));
                }

                // check to make sure the styler exists if it is specified (optional)
                if (task.Styler.Length > 0)
                {
                    IStyler s = GetStyler(task.Styler);
                    if (s == null)
                    {
                        vd(ParserValidationArgs.NewError("Task specified styler '" + task.Styler + "' that was not defined."));
                    }
                }
            }
        }