Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / EntityDesignerUtils.cs / 1 / 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 { internal static readonly string _edmxNamespace = "http://schemas.microsoft.com/ado/2007/06/edmx"; 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); XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDocument.NameTable); nsMgr.AddNamespace("edmx", _edmxNamespace); nsMgr.AddNamespace("edm", XmlConstants.ModelNamespace); nsMgr.AddNamespace("ssdl", XmlConstants.TargetNamespace); nsMgr.AddNamespace("map", StorageMslConstructs.NamespaceURI); // 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(); } } } } } // 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 { internal static readonly string _edmxNamespace = "http://schemas.microsoft.com/ado/2007/06/edmx"; 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); XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDocument.NameTable); nsMgr.AddNamespace("edmx", _edmxNamespace); nsMgr.AddNamespace("edm", XmlConstants.ModelNamespace); nsMgr.AddNamespace("ssdl", XmlConstants.TargetNamespace); nsMgr.AddNamespace("map", StorageMslConstructs.NamespaceURI); // 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(); } } } } } // 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
- GeometryCollection.cs
- VisualCollection.cs
- BinaryExpressionHelper.cs
- BaseResourcesBuildProvider.cs
- ParagraphVisual.cs
- ConfigurationSectionCollection.cs
- ClaimSet.cs
- AxisAngleRotation3D.cs
- EntityDataSourceConfigureObjectContextPanel.cs
- PerspectiveCamera.cs
- BooleanToVisibilityConverter.cs
- MailFileEditor.cs
- DecoderBestFitFallback.cs
- BitVector32.cs
- VarRefManager.cs
- EmbossBitmapEffect.cs
- PrinterSettings.cs
- SignedXml.cs
- BoundsDrawingContextWalker.cs
- RegexCompilationInfo.cs
- ExtensibleClassFactory.cs
- FormViewPageEventArgs.cs
- XPathDocumentIterator.cs
- RowBinding.cs
- ToolboxItemFilterAttribute.cs
- GeneralTransform3DGroup.cs
- WebPartConnectVerb.cs
- MetabaseServerConfig.cs
- DataGridViewIntLinkedList.cs
- TraceUtils.cs
- ExtendedPropertyDescriptor.cs
- ClrProviderManifest.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- BoundsDrawingContextWalker.cs
- ScaleTransform3D.cs
- DurationConverter.cs
- TextServicesPropertyRanges.cs
- EntityStoreSchemaGenerator.cs
- HighContrastHelper.cs
- RectAnimationUsingKeyFrames.cs
- Context.cs
- ProcessManager.cs
- TraceProvider.cs
- TextBoxBase.cs
- ConstructorBuilder.cs
- MessageQueueEnumerator.cs
- COM2ComponentEditor.cs
- AttributeEmitter.cs
- COM2Properties.cs
- DataGridColumn.cs
- HitTestFilterBehavior.cs
- Clause.cs
- ToolstripProfessionalRenderer.cs
- MaskInputRejectedEventArgs.cs
- DiffuseMaterial.cs
- EntityProviderServices.cs
- InfoCardTraceRecord.cs
- SiteMapHierarchicalDataSourceView.cs
- TextEditorCopyPaste.cs
- SafeThreadHandle.cs
- ContextMenuStrip.cs
- ExchangeUtilities.cs
- mediaeventshelper.cs
- ScopelessEnumAttribute.cs
- SqlClientWrapperSmiStream.cs
- CellCreator.cs
- MenuRenderer.cs
- TextServicesHost.cs
- CompilationLock.cs
- wgx_render.cs
- ColorKeyFrameCollection.cs
- ValuePatternIdentifiers.cs
- InheritanceContextChangedEventManager.cs
- ButtonBaseAutomationPeer.cs
- HttpDigestClientCredential.cs
- DataGridViewRowsAddedEventArgs.cs
- TimeIntervalCollection.cs
- XNodeNavigator.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- BulletedListEventArgs.cs
- DecoderExceptionFallback.cs
- HierarchicalDataBoundControlAdapter.cs
- DateTimeConverter.cs
- FontUnitConverter.cs
- GenericRootAutomationPeer.cs
- WebPartCatalogCloseVerb.cs
- DefaultParameterValueAttribute.cs
- AssertSection.cs
- Match.cs
- DoubleLink.cs
- SortQuery.cs
- CfgArc.cs
- StandardBindingReliableSessionElement.cs
- RequestCachePolicyConverter.cs
- FreeFormDesigner.cs
- InvalidDataException.cs
- Path.cs
- AdPostCacheSubstitution.cs
- StructuredTypeInfo.cs
- RenderContext.cs