Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- DockingAttribute.cs
- XmlSchemaDocumentation.cs
- WhitespaceSignificantCollectionAttribute.cs
- SoapTypeAttribute.cs
- HttpApplication.cs
- PointAnimationUsingPath.cs
- EpmCustomContentSerializer.cs
- SeekableReadStream.cs
- SystemColors.cs
- XamlSerializationHelper.cs
- GradientSpreadMethodValidation.cs
- WinHttpWebProxyFinder.cs
- QuotedStringWriteStateInfo.cs
- JsonWriterDelegator.cs
- XmlSchemaObjectTable.cs
- _SafeNetHandles.cs
- ObjectMemberMapping.cs
- SqlRowUpdatedEvent.cs
- SqlServer2KCompatibilityAnnotation.cs
- DataTableTypeConverter.cs
- WebFormDesignerActionService.cs
- Overlapped.cs
- TextBox.cs
- TraceHandler.cs
- XamlTreeBuilder.cs
- PropertyTab.cs
- WebCodeGenerator.cs
- DocumentReferenceCollection.cs
- VariantWrapper.cs
- MembershipPasswordException.cs
- MemberHolder.cs
- ProfileService.cs
- CqlBlock.cs
- ResourceDisplayNameAttribute.cs
- TextDecorations.cs
- SessionIDManager.cs
- AccessDataSourceView.cs
- MimeMultiPart.cs
- ExpressionCopier.cs
- DPTypeDescriptorContext.cs
- SettingsPropertyValue.cs
- Pkcs7Recipient.cs
- ForwardPositionQuery.cs
- SystemThemeKey.cs
- ChangeNode.cs
- FixedTextContainer.cs
- LookupBindingPropertiesAttribute.cs
- ViewSimplifier.cs
- UrlPropertyAttribute.cs
- UrlAuthFailedErrorFormatter.cs
- XmlIncludeAttribute.cs
- XMLSyntaxException.cs
- ExpressionBuilderContext.cs
- MailDefinitionBodyFileNameEditor.cs
- DesignerAdRotatorAdapter.cs
- MasterPage.cs
- Function.cs
- GeometryHitTestResult.cs
- ResourceProperty.cs
- EditorResources.cs
- WebPageTraceListener.cs
- CounterSample.cs
- Material.cs
- StringAnimationBase.cs
- TextServicesPropertyRanges.cs
- EntitySetRetriever.cs
- EditorPartChrome.cs
- XmlSerializableReader.cs
- ArraySet.cs
- AppDomainFactory.cs
- _CookieModule.cs
- XmlFormatReaderGenerator.cs
- FileDataSourceCache.cs
- BaseUriHelper.cs
- StoreAnnotationsMap.cs
- ManipulationPivot.cs
- LazyInitializer.cs
- CriticalFinalizerObject.cs
- TemplateControlBuildProvider.cs
- XmlILAnnotation.cs
- WebSysDescriptionAttribute.cs
- TextSpanModifier.cs
- IgnoreDataMemberAttribute.cs
- ZoneMembershipCondition.cs
- DistributedTransactionPermission.cs
- EditCommandColumn.cs
- FormViewUpdateEventArgs.cs
- CollectionViewSource.cs
- LinkConverter.cs
- PageAsyncTaskManager.cs
- Base64Encoding.cs
- TransformerConfigurationWizardBase.cs
- ConfigurationPropertyAttribute.cs
- TrackingProfile.cs
- QilReference.cs
- FullTextState.cs
- MetaModel.cs
- CommandID.cs
- SamlAssertion.cs
- CmsInterop.cs