/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="ignoreUnexpectedAttributesAndElements">Ignore the unexpected attributes and elements in schema.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, bool ignoreUnexpectedAttributesAndElements, out IEdmModel model, out IEnumerable <EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, null); edmxReader.ignoreUnexpectedAttributesAndElements = ignoreUnexpectedAttributesAndElements; return(edmxReader.TryParse(Enumerable.Empty <IEdmModel>(), out model, out errors)); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="references">Models to be referenced by the created model.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, IEnumerable <IEdmModel> references, out IEdmModel model, out IEnumerable <EdmError> errors) { EdmUtil.CheckArgumentNull(references, "references"); EdmxReader edmxReader = new EdmxReader(reader, null); return(edmxReader.TryParse(references, out model, out errors)); }
/// <summary> /// Load and parse the referenced model but ignored any further referenced model. /// </summary> /// <param name="mainEdmxVersion">The main edm version.</param> /// <returns>A list of CsdlModel (no semantics) of the referenced models.</returns> private List <CsdlModel> LoadAndParseReferencedEdmxFiles(Version mainEdmxVersion) { List <CsdlModel> referencedAstModels = new List <CsdlModel>(); if (this.getReferencedModelReaderFunc == null) { // don't try to load Edm xml doc, but this.edmReferences's namespace-alias need to be used later. return(referencedAstModels); } foreach (var tmp in this.edmReferences) { if (!tmp.Includes.Any() && !tmp.IncludeAnnotations.Any()) { this.RaiseError(EdmErrorCode.ReferenceElementMustContainAtLeastOneIncludeOrIncludeAnnotationsElement, Strings.EdmxParser_InvalidReferenceIncorrectNumberOfIncludes); continue; } if (tmp.Uri != null && (tmp.Uri.EndsWith(CoreVocabularyConstants.VocabularyUrlSuffix, StringComparison.Ordinal) || tmp.Uri.EndsWith(CapabilitiesVocabularyConstants.VocabularyUrlSuffix, StringComparison.Ordinal) || tmp.Uri.EndsWith(AlternateKeysVocabularyConstants.VocabularyUrlSuffix, StringComparison.Ordinal))) { continue; } XmlReader referencedXmlReader = this.getReferencedModelReaderFunc(new Uri(tmp.Uri, UriKind.RelativeOrAbsolute)); if (referencedXmlReader == null) { this.RaiseError(EdmErrorCode.UnresolvedReferenceUriInEdmxReference, Strings.EdmxParser_UnresolvedReferenceUriInEdmxReference); continue; } // recursively use EdmxReader to parse sub edm: EdmxReader referencedEdmxReader = new EdmxReader(referencedXmlReader, /*getReferencedModelReaderFunc*/ null); referencedEdmxReader.source = tmp.Uri; referencedEdmxReader.ignoreUnexpectedAttributesAndElements = this.ignoreUnexpectedAttributesAndElements; Version referencedEdmxVersion; CsdlModel referencedAstModel; if (referencedEdmxReader.TryParseEdmxFileToCsdlModel(out referencedEdmxVersion, out referencedAstModel)) { if (!mainEdmxVersion.Equals(referencedEdmxVersion)) { // TODO: REF add exception message this.errors.Add(null); } referencedAstModel.AddParentModelReferences(tmp); referencedAstModels.Add(referencedAstModel); } this.errors.AddRange(referencedEdmxReader.errors); } return(referencedAstModels); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="references">Models to be referenced by the created model.</param> /// <param name="settings">EdmxReader settings for current parser.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <remarks>If getReferencedModelReaderFunc throws exception, it won't be caught internally but will be thrown out for caller to handle.</remarks> /// <returns>Success of the parse operation.</returns> /// <remarks> /// User should handle the disposal of XmlReader created by getReferencedModelReaderFunc. /// </remarks> public static bool TryParse(XmlReader reader, IEnumerable <IEdmModel> references, EdmxReaderSettings settings, out IEdmModel model, out IEnumerable <EdmError> errors) { if (settings == null) { return(TryParse(reader, references, out model, out errors)); } EdmxReader edmxReader = new EdmxReader(reader, settings.GetReferencedModelReaderFunc) { ignoreUnexpectedAttributesAndElements = settings.IgnoreUnexpectedAttributesAndElements }; return(edmxReader.TryParse(references, out model, out errors)); }
/// <summary> /// Load and parse the referenced model but ignored any further referenced model. /// </summary> /// <param name="mainEdmxVersion">The main edm version.</param> /// <returns>A list of CsdlModel (no semantics) of the referenced models.</returns> private List <CsdlModel> LoadAndParseReferencedEdmxFiles(Version mainEdmxVersion) { List <CsdlModel> referencedAstModels = new List <CsdlModel>(); if (this.getReferencedModelReaderFunc == null) { // don't try to load Edm xml doc, but this.edmReferences's namespace-alias need to be used later. return(referencedAstModels); } foreach (var tmp in this.edmReferences) { if (!tmp.Includes.Any() && !tmp.IncludeAnnotations.Any()) { this.RaiseError(EdmErrorCode.ReferenceElementMustContainAtLeastOneIncludeOrIncludeAnnotationsElement, Strings.EdmxParser_InvalidReferenceIncorrectNumberOfIncludes); continue; } XmlReader referencedXmlReader = this.getReferencedModelReaderFunc(new Uri(tmp.Uri, UriKind.RelativeOrAbsolute)); if (referencedXmlReader == null) { // TODO: fix loc string this.RaiseError(EdmErrorCode.UnresolvedReferenceUriInEdmxReference, "Unresolved Uri found in edmx:Reference, getReferencedModelReaderFunc should not return null when the URI is not a well-known schema."); continue; } // recusively use EdmxReader to parse sub edm: EdmxReader referencedEdmxReader = new EdmxReader(referencedXmlReader, /*getReferencedModelReaderFunc*/ null); referencedEdmxReader.ignoreUnexpectedAttributesAndElements = this.ignoreUnexpectedAttributesAndElements; Version referencedEdmxVersion; CsdlModel referencedAstModel; if (referencedEdmxReader.TryParseEdmxFileToCsdlModel(out referencedEdmxVersion, out referencedAstModel)) { if (!mainEdmxVersion.Equals(referencedEdmxVersion)) { // TODO: REF add exception message this.errors.Add(null); } referencedAstModel.AddParentModelReferences(tmp); referencedAstModels.Add(referencedAstModel); } this.errors.AddRange(referencedEdmxReader.errors); } return(referencedAstModels); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, out IEdmModel model, out IEnumerable <EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, null); return(edmxReader.TryParse(Enumerable.Empty <IEdmModel>(), out model, out errors)); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="reference">Model to be referenced by the created model.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, IEdmModel reference, out IEdmModel model, out IEnumerable <EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, null); return(edmxReader.TryParse(new[] { reference }, out model, out errors)); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="getReferencedModelReaderFunc">The function to load referenced model xml. If null, will stop loading the referenced models. Normally it should throw no exception.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <remarks>If getReferencedModelReaderFunc throws exception, it won't be caught internally but will be thrown out for caller to handle.</remarks> /// <returns>Success of the parse operation.</returns> /// <remarks> /// User should handle the disposal of XmlReader created by getReferencedModelReaderFunc. /// </remarks> public static bool TryParse(XmlReader reader, Func <Uri, XmlReader> getReferencedModelReaderFunc, out IEdmModel model, out IEnumerable <EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, getReferencedModelReaderFunc); return(edmxReader.TryParse(Enumerable.Empty <IEdmModel>(), out model, out errors)); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, out IEdmModel model, out IEnumerable<EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, null); return edmxReader.TryParse(Enumerable.Empty<IEdmModel>(), out model, out errors); }
/// <summary> /// Load and parse the referenced model but ignored any further referenced model. /// </summary> /// <param name="mainEdmxVersion">The main edm version.</param> /// <returns>A list of CsdlModel (no semantics) of the referenced models.</returns> private List<CsdlModel> LoadAndParseReferencedEdmxFiles(Version mainEdmxVersion) { List<CsdlModel> referencedAstModels = new List<CsdlModel>(); if (this.getReferencedModelReaderFunc == null) { // don't try to load Edm xml doc, but this.edmReferences's namespace-alias need to be used later. return referencedAstModels; } foreach (var tmp in this.edmReferences) { if (!tmp.Includes.Any() && !tmp.IncludeAnnotations.Any()) { this.RaiseError(EdmErrorCode.ReferenceElementMustContainAtLeastOneIncludeOrIncludeAnnotationsElement, Strings.EdmxParser_InvalidReferenceIncorrectNumberOfIncludes); continue; } if (tmp.Uri != null && (tmp.Uri.EndsWith(CoreVocabularyConstants.VocabularyUrlSuffix, StringComparison.Ordinal) || tmp.Uri.EndsWith(CapabilitiesVocabularyConstants.VocabularyUrlSuffix, StringComparison.Ordinal) || tmp.Uri.EndsWith(AlternateKeysVocabularyConstants.VocabularyUrlSuffix, StringComparison.Ordinal))) { continue; } XmlReader referencedXmlReader = this.getReferencedModelReaderFunc(new Uri(tmp.Uri, UriKind.RelativeOrAbsolute)); if (referencedXmlReader == null) { this.RaiseError(EdmErrorCode.UnresolvedReferenceUriInEdmxReference, Strings.EdmxParser_UnresolvedReferenceUriInEdmxReference); continue; } // recursively use EdmxReader to parse sub edm: EdmxReader referencedEdmxReader = new EdmxReader(referencedXmlReader, /*getReferencedModelReaderFunc*/ null); referencedEdmxReader.source = tmp.Uri; referencedEdmxReader.ignoreUnexpectedAttributesAndElements = this.ignoreUnexpectedAttributesAndElements; Version referencedEdmxVersion; CsdlModel referencedAstModel; if (referencedEdmxReader.TryParseEdmxFileToCsdlModel(out referencedEdmxVersion, out referencedAstModel)) { if (!mainEdmxVersion.Equals(referencedEdmxVersion)) { // TODO: REF add exception message this.errors.Add(null); } referencedAstModel.AddParentModelReferences(tmp); referencedAstModels.Add(referencedAstModel); } this.errors.AddRange(referencedEdmxReader.errors); } return referencedAstModels; }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="references">Models to be referenced by the created model.</param> /// <param name="settings">EdmxReader settings for current parser.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <remarks>If getReferencedModelReaderFunc throws exception, it won't be caught internally but will be thrown out for caller to handle.</remarks> /// <returns>Success of the parse operation.</returns> /// <remarks> /// User should handle the disposal of XmlReader created by getReferencedModelReaderFunc. /// </remarks> public static bool TryParse(XmlReader reader, IEnumerable<IEdmModel> references, EdmxReaderSettings settings, out IEdmModel model, out IEnumerable<EdmError> errors) { EdmUtil.CheckArgumentNull(references, "references"); if (settings == null) { return TryParse(reader, references, out model, out errors); } EdmxReader edmxReader = new EdmxReader(reader, settings.GetReferencedModelReaderFunc) { ignoreUnexpectedAttributesAndElements = settings.IgnoreUnexpectedAttributesAndElements }; return edmxReader.TryParse(references, out model, out errors); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="reference">Model to be referenced by the created model.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, IEdmModel reference, out IEdmModel model, out IEnumerable<EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, null); return edmxReader.TryParse(new[] { reference }, out model, out errors); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="references">Models to be referenced by the created model.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, IEnumerable<IEdmModel> references, out IEdmModel model, out IEnumerable<EdmError> errors) { EdmUtil.CheckArgumentNull(references, "references"); EdmxReader edmxReader = new EdmxReader(reader, null); return edmxReader.TryParse(references, out model, out errors); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="getReferencedModelReaderFunc">The function to load referenced model xml. If null, will stop loading the referenced models. Normally it should throw no exception.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <remarks>If getReferencedModelReaderFunc throws exception, it won't be caught internally but will be thrown out for caller to handle.</remarks> /// <returns>Success of the parse operation.</returns> /// <remarks> /// User should handle the disposal of XmlReader created by getReferencedModelReaderFunc. /// </remarks> public static bool TryParse(XmlReader reader, Func<Uri, XmlReader> getReferencedModelReaderFunc, out IEdmModel model, out IEnumerable<EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, getReferencedModelReaderFunc); return edmxReader.TryParse(Enumerable.Empty<IEdmModel>(), out model, out errors); }
/// <summary> /// Tries parsing the given EDMX artifact for an IEdmModel. /// </summary> /// <param name="reader">XmlReader containing the EDMX artifact.</param> /// <param name="ignoreUnexpectedAttributesAndElements">Ignore the unexpected attributes and elements in schema.</param> /// <param name="model">The model generated by parsing</param> /// <param name="errors">Errors reported while parsing.</param> /// <returns>Success of the parse operation.</returns> public static bool TryParse(XmlReader reader, bool ignoreUnexpectedAttributesAndElements, out IEdmModel model, out IEnumerable<EdmError> errors) { EdmxReader edmxReader = new EdmxReader(reader, null); edmxReader.ignoreUnexpectedAttributesAndElements = ignoreUnexpectedAttributesAndElements; return edmxReader.TryParse(Enumerable.Empty<IEdmModel>(), out model, out errors); }