/// <summary> /// Tries to load the root element from the provided edmxDocument /// </summary> private bool TryLoadRootElementFromEdmx(XElement edmxDocument, SchemaConstants schemaConstants, string sectionName, string rootElementName, out XElement rootElement) { rootElement = null; XNamespace edmxNs = schemaConstants.EdmxNamespace; XNamespace sectionNs = GetNamespace(schemaConstants); XElement runtime = edmxDocument.Element(edmxNs + "Runtime"); if (runtime == null) { return(false); } XElement section = runtime.Element(edmxNs + sectionName); if (section == null) { return(false); } string templateVersion; if (!TemplateMetadata.TryGetValue(MetadataConstants.TT_TEMPLATE_VERSION, out templateVersion)) { templateVersion = MetadataConstants.DEFAULT_TEMPLATE_VERSION; } if (schemaConstants.MinimumTemplateVersion > new Version(templateVersion)) { _textTransformation.Errors.Add(new CompilerError( _textTransformation.Host.TemplateFile ?? CodeGenerationTools.GetResourceString("Template_CurrentlyRunningTemplate"), 0, 0, string.Empty, CodeGenerationTools.GetResourceString("Template_UnsupportedSchema")) { IsWarning = true }); } rootElement = section.Element(sectionNs + rootElementName); return(rootElement != null); }
/// <summary> /// Selects a namespace from the supplied constants. /// </summary> protected override string GetNamespace(SchemaConstants constants) { return(constants.CsdlNamespace); }
/// <summary> /// Selects a namespace from the supplied constants. /// </summary> protected abstract string GetNamespace(SchemaConstants constants);
private Tuple<XmlNode, XmlNamespaceManager> LoadMappingMetadata(string inputFile) { var xmlDoc = new XmlDocument(); //xmlDoc.Load(Host.ResolvePath(inputFile)); xmlDoc.Load(inputFile); var schemaConstantsList = new SchemaConstants[] { MetadataConstants.V3_SCHEMA_CONSTANTS, MetadataConstants.V2_SCHEMA_CONSTANTS, MetadataConstants.V1_SCHEMA_CONSTANTS, }; foreach (var schemaConstants in schemaConstantsList) { var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("ef", schemaConstants.MslNamespace); nsmgr.AddNamespace("edmx", schemaConstants.EdmxNamespace); var mappingNode = xmlDoc.DocumentElement.SelectSingleNode("./*/edmx:Mappings", nsmgr); if (mappingNode != null) return Tuple.Create(mappingNode, nsmgr); } throw new Exception(CodeGenerationTools.GetResourceString("Template_UnsupportedSchema")); }
/// <summary> /// Selects a namespace from the supplied constants. /// </summary> protected override string GetNamespace(SchemaConstants constants) { return constants.SsdlNamespace; }
/// <summary> /// Tries to load the root element from the provided edmxDocument /// </summary> private bool TryLoadRootElementFromEdmx(XElement edmxDocument, SchemaConstants schemaConstants, string sectionName, string rootElementName, out XElement rootElement) { rootElement = null; XNamespace edmxNs = schemaConstants.EdmxNamespace; XNamespace sectionNs = GetNamespace(schemaConstants); XElement runtime = edmxDocument.Element(edmxNs + "Runtime"); if (runtime == null) { return false; } XElement section = runtime.Element(edmxNs + sectionName); if (section == null) { return false; } string templateVersion; if (!TemplateMetadata.TryGetValue(MetadataConstants.TT_TEMPLATE_VERSION, out templateVersion)) { templateVersion = MetadataConstants.DEFAULT_TEMPLATE_VERSION; } if (schemaConstants.MinimumTemplateVersion > new Version(templateVersion)) { _textTransformation.Errors.Add(new CompilerError( _textTransformation.Host.TemplateFile ?? CodeGenerationTools.GetResourceString("Template_CurrentlyRunningTemplate"), 0, 0, string.Empty, CodeGenerationTools.GetResourceString("Template_UnsupportedSchema")) { IsWarning = true }); } rootElement = section.Element(sectionNs + rootElementName); return rootElement != null; }