Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / EntityDesignerUtils.cs / 1305376 / EntityDesignerUtils.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.IO; using System.Text; using System.Xml; using System.Data.Metadata.Edm; using System.Data.Mapping; namespace System.Data.Entity.Design { internal static class EntityDesignerUtils { private static readonly EFNamespaceSet v1Namespaces = new EFNamespaceSet { Edmx = "http://schemas.microsoft.com/ado/2007/06/edmx", Csdl = XmlConstants.ModelNamespace_1, Msl = StorageMslConstructs.NamespaceUriV1, Ssdl = XmlConstants.TargetNamespace_1 }; private static readonly EFNamespaceSet v2Namespaces = new EFNamespaceSet { Edmx = "http://schemas.microsoft.com/ado/2008/10/edmx", Csdl = XmlConstants.ModelNamespace_2, Msl = StorageMslConstructs.NamespaceUriV2, Ssdl = XmlConstants.TargetNamespace_2 }; internal static readonly string _edmxFileExtension = ".edmx"; ////// Extract the Conceptual, Mapping and Storage nodes from an EDMX input streams, and extract the value of the metadataArtifactProcessing property. /// /// /// /// /// /// internal static void ExtractConceptualMappingAndStorageNodes(StreamReader edmxInputStream, out XmlElement conceptualSchemaNode, out XmlElement mappingNode, out XmlElement storageSchemaNode, out string metadataArtifactProcessingValue) { // load up an XML document representing the edmx file XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(edmxInputStream); EFNamespaceSet set = v2Namespaces; if (xmlDocument.DocumentElement.NamespaceURI == v1Namespaces.Edmx) { set = v1Namespaces; } XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDocument.NameTable); nsMgr.AddNamespace("edmx", set.Edmx); nsMgr.AddNamespace("edm", set.Csdl); nsMgr.AddNamespace("ssdl", set.Ssdl); nsMgr.AddNamespace("map", set.Msl); // find the ConceptualModel Schema node conceptualSchemaNode = (XmlElement)xmlDocument.SelectSingleNode( "/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edm:Schema", nsMgr); // find the StorageModel Schema node storageSchemaNode = (XmlElement)xmlDocument.SelectSingleNode( "/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema", nsMgr); // find the Mapping node mappingNode = (XmlElement)xmlDocument.SelectSingleNode( "/edmx:Edmx/edmx:Runtime/edmx:Mappings/map:Mapping", nsMgr); // find the Connection node metadataArtifactProcessingValue = String.Empty; XmlNodeList connectionProperties = xmlDocument.SelectNodes( "/edmx:Edmx/edmx:Designer/edmx:Connection/edmx:DesignerInfoPropertySet/edmx:DesignerProperty", nsMgr); if (connectionProperties != null) { foreach (XmlNode propertyNode in connectionProperties) { foreach (XmlAttribute a in propertyNode.Attributes) { // treat attribute names case-sensitive (since it is xml), but attribute value case-insensitive to be accommodating . if (a.Name.Equals("Name", StringComparison.Ordinal) && a.Value.Equals("MetadataArtifactProcessing", StringComparison.OrdinalIgnoreCase)) { foreach (XmlAttribute a2 in propertyNode.Attributes) { if (a2.Name.Equals("Value", StringComparison.Ordinal)) { metadataArtifactProcessingValue = a2.Value; break; } } } } } } } // utility method to ensure an XmlElement (containing the C, M or S element // from the Edmx file) is sent out to a stream in the same format internal static void OutputXmlElementToStream(XmlElement xmlElement, Stream stream) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.Indent = true; // set up output document XmlDocument outputXmlDoc = new XmlDocument(); XmlNode importedElement = outputXmlDoc.ImportNode(xmlElement, true); outputXmlDoc.AppendChild(importedElement); // write out XmlDocument XmlWriter writer = null; try { writer = XmlWriter.Create(stream, settings); outputXmlDoc.WriteTo(writer); } finally { if (writer != null) { writer.Close(); } } } private struct EFNamespaceSet { public string Edmx; public string Csdl; public string Msl; public string Ssdl; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.IO; using System.Text; using System.Xml; using System.Data.Metadata.Edm; using System.Data.Mapping; namespace System.Data.Entity.Design { internal static class EntityDesignerUtils { private static readonly EFNamespaceSet v1Namespaces = new EFNamespaceSet { Edmx = "http://schemas.microsoft.com/ado/2007/06/edmx", Csdl = XmlConstants.ModelNamespace_1, Msl = StorageMslConstructs.NamespaceUriV1, Ssdl = XmlConstants.TargetNamespace_1 }; private static readonly EFNamespaceSet v2Namespaces = new EFNamespaceSet { Edmx = "http://schemas.microsoft.com/ado/2008/10/edmx", Csdl = XmlConstants.ModelNamespace_2, Msl = StorageMslConstructs.NamespaceUriV2, Ssdl = XmlConstants.TargetNamespace_2 }; internal static readonly string _edmxFileExtension = ".edmx"; ////// Extract the Conceptual, Mapping and Storage nodes from an EDMX input streams, and extract the value of the metadataArtifactProcessing property. /// /// /// /// /// /// internal static void ExtractConceptualMappingAndStorageNodes(StreamReader edmxInputStream, out XmlElement conceptualSchemaNode, out XmlElement mappingNode, out XmlElement storageSchemaNode, out string metadataArtifactProcessingValue) { // load up an XML document representing the edmx file XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(edmxInputStream); EFNamespaceSet set = v2Namespaces; if (xmlDocument.DocumentElement.NamespaceURI == v1Namespaces.Edmx) { set = v1Namespaces; } XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDocument.NameTable); nsMgr.AddNamespace("edmx", set.Edmx); nsMgr.AddNamespace("edm", set.Csdl); nsMgr.AddNamespace("ssdl", set.Ssdl); nsMgr.AddNamespace("map", set.Msl); // find the ConceptualModel Schema node conceptualSchemaNode = (XmlElement)xmlDocument.SelectSingleNode( "/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edm:Schema", nsMgr); // find the StorageModel Schema node storageSchemaNode = (XmlElement)xmlDocument.SelectSingleNode( "/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema", nsMgr); // find the Mapping node mappingNode = (XmlElement)xmlDocument.SelectSingleNode( "/edmx:Edmx/edmx:Runtime/edmx:Mappings/map:Mapping", nsMgr); // find the Connection node metadataArtifactProcessingValue = String.Empty; XmlNodeList connectionProperties = xmlDocument.SelectNodes( "/edmx:Edmx/edmx:Designer/edmx:Connection/edmx:DesignerInfoPropertySet/edmx:DesignerProperty", nsMgr); if (connectionProperties != null) { foreach (XmlNode propertyNode in connectionProperties) { foreach (XmlAttribute a in propertyNode.Attributes) { // treat attribute names case-sensitive (since it is xml), but attribute value case-insensitive to be accommodating . if (a.Name.Equals("Name", StringComparison.Ordinal) && a.Value.Equals("MetadataArtifactProcessing", StringComparison.OrdinalIgnoreCase)) { foreach (XmlAttribute a2 in propertyNode.Attributes) { if (a2.Name.Equals("Value", StringComparison.Ordinal)) { metadataArtifactProcessingValue = a2.Value; break; } } } } } } } // utility method to ensure an XmlElement (containing the C, M or S element // from the Edmx file) is sent out to a stream in the same format internal static void OutputXmlElementToStream(XmlElement xmlElement, Stream stream) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.Indent = true; // set up output document XmlDocument outputXmlDoc = new XmlDocument(); XmlNode importedElement = outputXmlDoc.ImportNode(xmlElement, true); outputXmlDoc.AppendChild(importedElement); // write out XmlDocument XmlWriter writer = null; try { writer = XmlWriter.Create(stream, settings); outputXmlDoc.WriteTo(writer); } finally { if (writer != null) { writer.Close(); } } } private struct EFNamespaceSet { public string Edmx; public string Csdl; public string Msl; public string Ssdl; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XsltFunctions.cs
- Activator.cs
- HandleExceptionArgs.cs
- XhtmlBasicObjectListAdapter.cs
- CustomAttributeSerializer.cs
- ResourceExpressionBuilder.cs
- ListViewTableRow.cs
- CompilerErrorCollection.cs
- Timeline.cs
- SQLDateTimeStorage.cs
- SecurityIdentifierElementCollection.cs
- TaskbarItemInfo.cs
- VScrollProperties.cs
- OdbcParameter.cs
- TrailingSpaceComparer.cs
- Property.cs
- IsolatedStorage.cs
- TypeCacheManager.cs
- Convert.cs
- SafeRightsManagementHandle.cs
- Sql8ConformanceChecker.cs
- ConnectionPointCookie.cs
- LineGeometry.cs
- StructuredType.cs
- ShowExpandedMultiValueConverter.cs
- SapiRecoContext.cs
- DesignerWithHeader.cs
- TargetException.cs
- StrokeFIndices.cs
- ConfigurationSectionHelper.cs
- DataServiceQueryException.cs
- InfoCardSymmetricCrypto.cs
- StretchValidation.cs
- SafeReversePInvokeHandle.cs
- ITextView.cs
- SiteOfOriginPart.cs
- CacheAxisQuery.cs
- UIAgentAsyncEndRequest.cs
- InvokeProviderWrapper.cs
- PeerCollaborationPermission.cs
- QueryableDataSourceEditData.cs
- SqlGatherConsumedAliases.cs
- TreeNodeBindingCollection.cs
- DecimalAnimationUsingKeyFrames.cs
- Path.cs
- WebControlAdapter.cs
- KeyTimeConverter.cs
- TextView.cs
- TableLayoutPanelCodeDomSerializer.cs
- DataContext.cs
- MethodBuilder.cs
- FormViewCommandEventArgs.cs
- VisualBrush.cs
- WebPartRestoreVerb.cs
- TargetConverter.cs
- DigitShape.cs
- TransactionFormatter.cs
- LogLogRecordHeader.cs
- CodeMethodInvokeExpression.cs
- AccessibleObject.cs
- AssemblyUtil.cs
- ProfileParameter.cs
- PersonalizationProviderCollection.cs
- ResourceContainer.cs
- XsltArgumentList.cs
- DesignerFrame.cs
- RelationshipSet.cs
- AdornedElementPlaceholder.cs
- TdsEnums.cs
- EmptyTextWriter.cs
- ThreadExceptionEvent.cs
- CompositeActivityCodeGenerator.cs
- TraceLog.cs
- ClientRuntimeConfig.cs
- Panel.cs
- XmlDataSource.cs
- FlagsAttribute.cs
- ObjectDataSourceEventArgs.cs
- EmptyStringExpandableObjectConverter.cs
- ObjectListField.cs
- KerberosSecurityTokenAuthenticator.cs
- PanelDesigner.cs
- HeaderUtility.cs
- LineVisual.cs
- Axis.cs
- ComContractElementCollection.cs
- Base64Encoding.cs
- ImportCatalogPart.cs
- WriterOutput.cs
- DataGridViewCellStyleChangedEventArgs.cs
- XamlParser.cs
- AsymmetricKeyExchangeDeformatter.cs
- UnmanagedMarshal.cs
- TextElementEnumerator.cs
- ToolStripDropDownButton.cs
- CredentialManagerDialog.cs
- AvtEvent.cs
- ResourceWriter.cs
- SQLChars.cs
- SqlConnectionFactory.cs