Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / AspNet / EntityDesignerBuildProvider.cs / 1305376 / 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 csdlResourceName = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.CSpaceSchemaExtension); string ssdlResourceName = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.SSpaceSchemaExtension); string mslResourceName = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.CSSpaceSchemaExtension); SetupEmbeddedResource(assemblyBuilder, this, conceptualSchemaElement, csdlResourceName); SetupEmbeddedResource(assemblyBuilder, this, storageSchemaElement, ssdlResourceName); SetupEmbeddedResource(assemblyBuilder, this, mappingElement, mslResourceName); } } private static void SetupEmbeddedResource(AssemblyBuilder assemblyBuilder, BuildProvider prov, XmlElement xmlElement, string resourceName) { using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, resourceName)) { 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 csdlResourceName = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.CSpaceSchemaExtension); string ssdlResourceName = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.SSpaceSchemaExtension); string mslResourceName = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPathPrefix + XmlConstants.CSSpaceSchemaExtension); SetupEmbeddedResource(assemblyBuilder, this, conceptualSchemaElement, csdlResourceName); SetupEmbeddedResource(assemblyBuilder, this, storageSchemaElement, ssdlResourceName); SetupEmbeddedResource(assemblyBuilder, this, mappingElement, mslResourceName); } } private static void SetupEmbeddedResource(AssemblyBuilder assemblyBuilder, BuildProvider prov, XmlElement xmlElement, string resourceName) { using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, resourceName)) { 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
- ToolStripItemEventArgs.cs
- GuidelineCollection.cs
- Figure.cs
- DetailsViewInsertedEventArgs.cs
- SubqueryRules.cs
- WindowsFormsLinkLabel.cs
- IInstanceTable.cs
- ResourceExpression.cs
- FixedSOMLineCollection.cs
- Literal.cs
- ShapingWorkspace.cs
- VirtualDirectoryMapping.cs
- OleDbFactory.cs
- XmlSchemaSubstitutionGroup.cs
- IResourceProvider.cs
- NavigationProgressEventArgs.cs
- AsyncOperationManager.cs
- Rectangle.cs
- ParagraphResult.cs
- ComplexTypeEmitter.cs
- FileEnumerator.cs
- NamedPermissionSet.cs
- TraceSection.cs
- ViewGenerator.cs
- OdbcReferenceCollection.cs
- StyleTypedPropertyAttribute.cs
- sqlstateclientmanager.cs
- ItemDragEvent.cs
- FrugalList.cs
- WorkflowApplicationUnhandledExceptionEventArgs.cs
- TemplateBuilder.cs
- AutomationPatternInfo.cs
- LicFileLicenseProvider.cs
- DataGridCaption.cs
- IsolationInterop.cs
- ObfuscateAssemblyAttribute.cs
- MenuItemBinding.cs
- UrlMapping.cs
- CachedCompositeFamily.cs
- SecurityContext.cs
- DesignerVerbCollection.cs
- FontUnitConverter.cs
- EntityException.cs
- ContentWrapperAttribute.cs
- DelegateTypeInfo.cs
- ServiceOperationInvoker.cs
- DefaultMemberAttribute.cs
- ListBindingConverter.cs
- TextTreeExtractElementUndoUnit.cs
- DataViewSettingCollection.cs
- DBParameter.cs
- DataGridViewBand.cs
- Sorting.cs
- HwndAppCommandInputProvider.cs
- HiddenField.cs
- WebPartMovingEventArgs.cs
- MemberListBinding.cs
- XmlNodeReader.cs
- RowToParametersTransformer.cs
- XmlCodeExporter.cs
- X509ChainElement.cs
- XamlSerializer.cs
- DeclarationUpdate.cs
- VectorConverter.cs
- PopupRoot.cs
- DataGridViewColumn.cs
- ValidationErrorEventArgs.cs
- ContentPresenter.cs
- Normalization.cs
- NavigationWindow.cs
- SmtpTransport.cs
- QueryableDataSourceEditData.cs
- XmlChoiceIdentifierAttribute.cs
- RuntimeWrappedException.cs
- __ConsoleStream.cs
- CancelAsyncOperationRequest.cs
- _IPv4Address.cs
- ReverseInheritProperty.cs
- BufferModeSettings.cs
- ObjectStateEntryDbDataRecord.cs
- Html32TextWriter.cs
- RelationshipFixer.cs
- BindableTemplateBuilder.cs
- COM2ExtendedTypeConverter.cs
- DbInsertCommandTree.cs
- Script.cs
- IPGlobalProperties.cs
- EventLogPermissionAttribute.cs
- QueryExpression.cs
- TimersDescriptionAttribute.cs
- XmlTypeMapping.cs
- UniqueContractNameValidationBehavior.cs
- SerializableAttribute.cs
- IteratorDescriptor.cs
- TextAction.cs
- InvalidBodyAccessException.cs
- DrawingAttributeSerializer.cs
- IndividualDeviceConfig.cs
- ELinqQueryState.cs
- CancellableEnumerable.cs