Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / AspNet / EntityDesignerBuildProvider.cs / 1 / EntityDesignerBuildProvider.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.CodeDom; using System.CodeDom.Compiler; using System.Globalization; using System.IO; using System.Text; using System.Web.Hosting; using System.Web.Compilation; using System.Xml; using System.Data.Metadata.Edm; namespace System.Data.Entity.Design.AspNet { ////// The ASP .NET Build provider for the CSDL in ADO .NET /// /// [BuildProviderAppliesTo(BuildProviderAppliesTo.Code)] public class EntityDesignerBuildProvider : System.Web.Compilation.BuildProvider { ////// Default constructor /// public EntityDesignerBuildProvider() { } ////// We want ASP .NET to always reset the app domain when we have to rebuild /// /// ///public override BuildProviderResultFlags GetResultFlags(CompilerResults results) { return BuildProviderResultFlags.ShutdownAppDomainOnChange; } /// /// Extract the CSDL, SSDL and MSL nodes from the EDMX file and store them /// as embedded resources /// /// public override void GenerateCode(AssemblyBuilder assemblyBuilder) { using (StreamReader edmxInputStream = new StreamReader(VirtualPathProvider.OpenFile(base.VirtualPath))) { // load up an XML document representing the edmx file XmlElement conceptualSchemaElement; XmlElement mappingElement; XmlElement storageSchemaElement; string embedAsResourcePropertyValue; EntityDesignerUtils.ExtractConceptualMappingAndStorageNodes(edmxInputStream, out conceptualSchemaElement, out mappingElement, out storageSchemaElement, out embedAsResourcePropertyValue); if (null == conceptualSchemaElement) { throw new XmlException("No Conceptual Schema node to embed as a resource", null, 0, 0); } if (null == storageSchemaElement) { throw new XmlException("No Storage Schema node to embed as a resource", null, 0, 0); } if (null == mappingElement) { throw new XmlException("No Mapping node to embed as a resource", null, 0, 0); } // construct output paths where the CSDL/MSL/SSDL resources will be placed string virtualPathPrefix = base.VirtualPath.Replace(EntityDesignerUtils._edmxFileExtension, String.Empty); string conceptualVirtualPath = virtualPathPrefix + XmlConstants.CSpaceSchemaExtension; string storageVirtualPath = virtualPathPrefix + XmlConstants.SSpaceSchemaExtension; string mappingVirtualPath = virtualPathPrefix + XmlConstants.CSSpaceSchemaExtension; SetupEmbeddedResource(assemblyBuilder, this, conceptualSchemaElement, conceptualVirtualPath); SetupEmbeddedResource(assemblyBuilder, this, storageSchemaElement, storageVirtualPath); SetupEmbeddedResource(assemblyBuilder, this, mappingElement, mappingVirtualPath); } } private static void SetupEmbeddedResource(AssemblyBuilder assemblyBuilder, BuildProvider prov, XmlElement xmlElement, string resourcePath) { // derive the resource name string name = resourcePath.Replace("/", "."); if (name.StartsWith(".", StringComparison.Ordinal)) { name = name.Substring(1); } using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, name)) { EntityDesignerUtils.OutputXmlElementToStream(xmlElement, resStream); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Collections.Generic; using System.CodeDom; using System.CodeDom.Compiler; using System.Globalization; using System.IO; using System.Text; using System.Web.Hosting; using System.Web.Compilation; using System.Xml; using System.Data.Metadata.Edm; namespace System.Data.Entity.Design.AspNet { ////// The ASP .NET Build provider for the CSDL in ADO .NET /// /// [BuildProviderAppliesTo(BuildProviderAppliesTo.Code)] public class EntityDesignerBuildProvider : System.Web.Compilation.BuildProvider { ////// Default constructor /// public EntityDesignerBuildProvider() { } ////// We want ASP .NET to always reset the app domain when we have to rebuild /// /// ///public override BuildProviderResultFlags GetResultFlags(CompilerResults results) { return BuildProviderResultFlags.ShutdownAppDomainOnChange; } /// /// Extract the CSDL, SSDL and MSL nodes from the EDMX file and store them /// as embedded resources /// /// public override void GenerateCode(AssemblyBuilder assemblyBuilder) { using (StreamReader edmxInputStream = new StreamReader(VirtualPathProvider.OpenFile(base.VirtualPath))) { // load up an XML document representing the edmx file XmlElement conceptualSchemaElement; XmlElement mappingElement; XmlElement storageSchemaElement; string embedAsResourcePropertyValue; EntityDesignerUtils.ExtractConceptualMappingAndStorageNodes(edmxInputStream, out conceptualSchemaElement, out mappingElement, out storageSchemaElement, out embedAsResourcePropertyValue); if (null == conceptualSchemaElement) { throw new XmlException("No Conceptual Schema node to embed as a resource", null, 0, 0); } if (null == storageSchemaElement) { throw new XmlException("No Storage Schema node to embed as a resource", null, 0, 0); } if (null == mappingElement) { throw new XmlException("No Mapping node to embed as a resource", null, 0, 0); } // construct output paths where the CSDL/MSL/SSDL resources will be placed string virtualPathPrefix = base.VirtualPath.Replace(EntityDesignerUtils._edmxFileExtension, String.Empty); string conceptualVirtualPath = virtualPathPrefix + XmlConstants.CSpaceSchemaExtension; string storageVirtualPath = virtualPathPrefix + XmlConstants.SSpaceSchemaExtension; string mappingVirtualPath = virtualPathPrefix + XmlConstants.CSSpaceSchemaExtension; SetupEmbeddedResource(assemblyBuilder, this, conceptualSchemaElement, conceptualVirtualPath); SetupEmbeddedResource(assemblyBuilder, this, storageSchemaElement, storageVirtualPath); SetupEmbeddedResource(assemblyBuilder, this, mappingElement, mappingVirtualPath); } } private static void SetupEmbeddedResource(AssemblyBuilder assemblyBuilder, BuildProvider prov, XmlElement xmlElement, string resourcePath) { // derive the resource name string name = resourcePath.Replace("/", "."); if (name.StartsWith(".", StringComparison.Ordinal)) { name = name.Substring(1); } using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, name)) { EntityDesignerUtils.OutputXmlElementToStream(xmlElement, resStream); } } } } // 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
- ImageDrawing.cs
- BitConverter.cs
- DockPatternIdentifiers.cs
- TransactionException.cs
- EntityDataSourceQueryBuilder.cs
- XmlComplianceUtil.cs
- LinearGradientBrush.cs
- OleDbRowUpdatedEvent.cs
- ToolboxItemCollection.cs
- HWStack.cs
- RelatedEnd.cs
- ForceCopyBuildProvider.cs
- AQNBuilder.cs
- SmiGettersStream.cs
- SqlAliasesReferenced.cs
- AttributeData.cs
- QuaternionAnimation.cs
- KoreanCalendar.cs
- ConfigurationValues.cs
- ReadOnlyObservableCollection.cs
- CodeMethodReturnStatement.cs
- BitmapEffectInput.cs
- WebBrowserPermission.cs
- IntSecurity.cs
- PowerStatus.cs
- shaper.cs
- ProfileProvider.cs
- MenuAdapter.cs
- CryptoApi.cs
- ObjectKeyFrameCollection.cs
- ArglessEventHandlerProxy.cs
- BamlTreeMap.cs
- OptimalTextSource.cs
- XmlnsCache.cs
- ObjectViewFactory.cs
- UIElementParagraph.cs
- XmlTextReader.cs
- XPathMultyIterator.cs
- FixedTextView.cs
- TextEncodedRawTextWriter.cs
- ParallelActivityDesigner.cs
- WindowVisualStateTracker.cs
- DataSourceProvider.cs
- RadialGradientBrush.cs
- XmlSchemaSubstitutionGroup.cs
- Int64AnimationUsingKeyFrames.cs
- Attributes.cs
- TextDecorationUnitValidation.cs
- Span.cs
- InternalTransaction.cs
- UrlMappingsModule.cs
- SettingsProviderCollection.cs
- SmiSettersStream.cs
- Transform.cs
- ViewBase.cs
- ImageCodecInfoPrivate.cs
- OutputCacheSettingsSection.cs
- Resources.Designer.cs
- ProgressChangedEventArgs.cs
- Main.cs
- StateWorkerRequest.cs
- XmlTypeAttribute.cs
- EditingCommands.cs
- CalendarDesigner.cs
- WebServiceReceive.cs
- PeerContact.cs
- OverrideMode.cs
- WindowsEditBox.cs
- CapabilitiesSection.cs
- PolygonHotSpot.cs
- RoutedEvent.cs
- DoWhileDesigner.xaml.cs
- FormsAuthenticationUser.cs
- diagnosticsswitches.cs
- JsonQueryStringConverter.cs
- UnsafeNativeMethods.cs
- MetabaseReader.cs
- SessionPageStateSection.cs
- DataColumnPropertyDescriptor.cs
- StackOverflowException.cs
- Control.cs
- MimeFormatExtensions.cs
- InheritablePropertyChangeInfo.cs
- HtmlHistory.cs
- DrawingCollection.cs
- ColorContextHelper.cs
- ArrayEditor.cs
- SortDescription.cs
- SeparatorAutomationPeer.cs
- PrinterSettings.cs
- BulletedList.cs
- SecurityRuntime.cs
- TagPrefixInfo.cs
- ObjectListCommandsPage.cs
- COAUTHIDENTITY.cs
- QueryReaderSettings.cs
- PathGeometry.cs
- safemediahandle.cs
- DataGridViewControlCollection.cs
- ControlPaint.cs