Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntityDesign / Design / System / Data / Entity / Design / AspNet / EntityModelBuildProvider.cs / 1305376 / EntityModelBuildProvider.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.Hosting;
using System.Web.Compilation;
using System.Xml;
using System.Data.Entity.Design;
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 EntityModelBuildProvider : System.Web.Compilation.BuildProvider
{
///
/// Default constructor
///
public EntityModelBuildProvider()
{
}
///
/// We want ASP .NET to always reset the app domain when we have to rebuild
///
///
///
public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
{
return BuildProviderResultFlags.ShutdownAppDomainOnChange;
}
///
///
///
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
public override void GenerateCode(AssemblyBuilder assemblyBuilder)
{
// look at the assembly builder to see which language we should use in the App_Code directory
EntityCodeGenerator generator = null;
if (assemblyBuilder.CodeDomProvider.FileExtension.ToLowerInvariant() == "cs")
{
generator = new EntityCodeGenerator(LanguageOption.GenerateCSharpCode);
}
else
{
generator = new EntityCodeGenerator(LanguageOption.GenerateVBCode);
}
// generate the code for our CSDL file
IList errors = null;
using (XmlReader input = XmlReader.Create(VirtualPathProvider.OpenFile(base.VirtualPath)))
{
using (StringWriter output = new StringWriter(CultureInfo.InvariantCulture))
{
// Read from input and generate into output, put errors in a class member
errors = generator.GenerateCode(input, output);
if (errors.Count == 0)
{
output.Flush();
assemblyBuilder.AddCodeCompileUnit(this, new CodeSnippetCompileUnit(output.ToString()));
}
}
}
// if there are errors, package this data into XmlExceptions and throw this
// if we are in VS, the ASP .NET stack will place this information in the error pane
// if we are in the ASP .NET runtime, it will use this information to build the error page
if (errors != null && errors.Count > 0)
{
XmlException inner = null;
XmlException outer = null;
foreach (EdmSchemaError error in errors)
{
outer = new XmlException(error.Message, inner, error.Line, error.Column);
inner = outer;
}
throw outer;
}
BuildProviderUtils.AddArtifactReference(assemblyBuilder, this, base.VirtualPath);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.Hosting;
using System.Web.Compilation;
using System.Xml;
using System.Data.Entity.Design;
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 EntityModelBuildProvider : System.Web.Compilation.BuildProvider
{
///
/// Default constructor
///
public EntityModelBuildProvider()
{
}
///
/// We want ASP .NET to always reset the app domain when we have to rebuild
///
///
///
public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
{
return BuildProviderResultFlags.ShutdownAppDomainOnChange;
}
///
///
///
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
public override void GenerateCode(AssemblyBuilder assemblyBuilder)
{
// look at the assembly builder to see which language we should use in the App_Code directory
EntityCodeGenerator generator = null;
if (assemblyBuilder.CodeDomProvider.FileExtension.ToLowerInvariant() == "cs")
{
generator = new EntityCodeGenerator(LanguageOption.GenerateCSharpCode);
}
else
{
generator = new EntityCodeGenerator(LanguageOption.GenerateVBCode);
}
// generate the code for our CSDL file
IList errors = null;
using (XmlReader input = XmlReader.Create(VirtualPathProvider.OpenFile(base.VirtualPath)))
{
using (StringWriter output = new StringWriter(CultureInfo.InvariantCulture))
{
// Read from input and generate into output, put errors in a class member
errors = generator.GenerateCode(input, output);
if (errors.Count == 0)
{
output.Flush();
assemblyBuilder.AddCodeCompileUnit(this, new CodeSnippetCompileUnit(output.ToString()));
}
}
}
// if there are errors, package this data into XmlExceptions and throw this
// if we are in VS, the ASP .NET stack will place this information in the error pane
// if we are in the ASP .NET runtime, it will use this information to build the error page
if (errors != null && errors.Count > 0)
{
XmlException inner = null;
XmlException outer = null;
foreach (EdmSchemaError error in errors)
{
outer = new XmlException(error.Message, inner, error.Line, error.Column);
inner = outer;
}
throw outer;
}
BuildProviderUtils.AddArtifactReference(assemblyBuilder, this, base.VirtualPath);
}
}
}
// 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
- SortedList.cs
- ResourcePool.cs
- DbgUtil.cs
- DataPagerField.cs
- TextShapeableCharacters.cs
- PaperSource.cs
- Equal.cs
- CollectionMarkupSerializer.cs
- GroupQuery.cs
- MutexSecurity.cs
- KeyProperty.cs
- DataGridViewIntLinkedList.cs
- Tile.cs
- mansign.cs
- SHA512.cs
- DoubleLinkListEnumerator.cs
- ImageBrush.cs
- Parser.cs
- PointValueSerializer.cs
- ConnectionOrientedTransportManager.cs
- DoubleAnimationUsingPath.cs
- ElementAction.cs
- SessionPageStatePersister.cs
- cache.cs
- DependencySource.cs
- BulletedListEventArgs.cs
- InputBinding.cs
- BitmapEffectGeneralTransform.cs
- QueryConverter.cs
- localization.cs
- ClientApiGenerator.cs
- BindingSource.cs
- Pointer.cs
- PropertyTabAttribute.cs
- SchemaContext.cs
- DesignerHelpers.cs
- TabItemAutomationPeer.cs
- Visual3D.cs
- SafeHandles.cs
- IgnorePropertiesAttribute.cs
- CatalogPartChrome.cs
- ICspAsymmetricAlgorithm.cs
- InvalidProgramException.cs
- ProxyManager.cs
- StatusBarItem.cs
- XmlSchemaIdentityConstraint.cs
- RoleManagerSection.cs
- SqlTopReducer.cs
- PersonalizableAttribute.cs
- MSAAEventDispatcher.cs
- Root.cs
- SymbolTable.cs
- ProcessThread.cs
- GridViewSelectEventArgs.cs
- updateconfighost.cs
- PropertyChangingEventArgs.cs
- TextEditorThreadLocalStore.cs
- TextEndOfSegment.cs
- SqlDataSource.cs
- DataGridToolTip.cs
- EventHandlersStore.cs
- TextBox.cs
- SplitterEvent.cs
- DES.cs
- ViewPort3D.cs
- CommandConverter.cs
- Set.cs
- WebColorConverter.cs
- CodeGeneratorOptions.cs
- RegisteredHiddenField.cs
- SchemaType.cs
- ObjectCloneHelper.cs
- MasterPageCodeDomTreeGenerator.cs
- EntitySetBaseCollection.cs
- XmlSignificantWhitespace.cs
- QilCloneVisitor.cs
- DashStyles.cs
- WarningException.cs
- CryptoProvider.cs
- SystemIPv6InterfaceProperties.cs
- TreeViewBindingsEditor.cs
- SQLInt32Storage.cs
- XmlUtil.cs
- DoubleIndependentAnimationStorage.cs
- MemoryFailPoint.cs
- LocalTransaction.cs
- UpdateEventArgs.cs
- XmlEntity.cs
- ReadOnlyDataSourceView.cs
- ThicknessConverter.cs
- ControlType.cs
- ErrorsHelper.cs
- RegexReplacement.cs
- EventDescriptor.cs
- EntryPointNotFoundException.cs
- Win32PrintDialog.cs
- FilterException.cs
- RepeaterItemEventArgs.cs
- ProxyManager.cs
- MenuAutomationPeer.cs