private bool ValidateModel(EdmModel model) { bool modelIsValid = true; Action <DataModelErrorEventArgs> onErrorAction = (Action <DataModelErrorEventArgs>)(e => { MetadataItem instance = e.Item; if (instance != null && MetadataItemHelper.IsInvalid(instance)) { return; } modelIsValid = false; if (this.OnError == null) { return; } this.OnError((object)this, e); }); if (model.NamespaceNames.Count <string>() > 1 || model.Containers.Count <EntityContainer>() != 1) { onErrorAction(new DataModelErrorEventArgs() { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer }); } DataModelValidator dataModelValidator = new DataModelValidator(); dataModelValidator.OnError += (EventHandler <DataModelErrorEventArgs>)((_, e) => onErrorAction(e)); dataModelValidator.Validate(model, true); return(modelIsValid); }
private static void AppendSchemaErrors(StringBuilder builder, MetadataItem item) { if (!MetadataItemHelper.HasSchemaErrors(item)) { return; } builder.Append(Strings.MetadataItemErrorsFoundDuringGeneration); foreach (EdmSchemaError schemaError in MetadataItemHelper.GetSchemaErrors(item)) { builder.AppendLine(); builder.Append(schemaError.ToString()); } }
protected internal override void VisitEdmAssociationType(AssociationType item) { StringBuilder builder = new StringBuilder(); EdmSerializationVisitor.AppendSchemaErrors(builder, (MetadataItem)item); if (MetadataItemHelper.IsInvalid((MetadataItem)item)) { this.AppendMetadataItem <AssociationType>(builder, item, (Action <EdmSerializationVisitor, AssociationType>)((v, i) => v.InternalVisitEdmAssociationType(i))); this.WriteComment(builder.ToString()); } else { this.WriteComment(builder.ToString()); this.InternalVisitEdmAssociationType(item); } }
protected internal override void VisitEdmAssociationType(AssociationType item) { var builder = new StringBuilder(); AppendSchemaErrors(builder, item); if (MetadataItemHelper.IsInvalid(item)) { AppendMetadataItem(builder, item, (v, i) => v.InternalVisitEdmAssociationType(i)); WriteComment(builder.ToString()); } else { WriteComment(builder.ToString()); InternalVisitEdmAssociationType(item); } }
private bool ValidateModel(EdmModel model) { bool modelIsValid = true; Action <DataModelErrorEventArgs> onErrorAction = e => { // Ssdl serializer writes metadata items marked as invalid as comments // therefore we should not report errors for those. var metadataItem = e.Item as MetadataItem; if (metadataItem == null || !MetadataItemHelper.IsInvalid(metadataItem)) { modelIsValid = false; if (OnError != null) { OnError(this, e); } } }; if (model.NamespaceNames.Count() > 1 || model.Containers.Count() != 1) { onErrorAction( new DataModelErrorEventArgs { ErrorMessage = Strings.Serializer_OneNamespaceAndOneContainer, }); } var validator = new DataModelValidator(); validator.OnError += (_, e) => onErrorAction(e); validator.Validate(model, true); return(modelIsValid); }