Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,73 @@
//---------------------------------------------------------------------
// <copyright file="BuildProviderUtils.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.Compilation;
using System.Web.Hosting;
namespace System.Data.Entity.Design.AspNet
{
/// <summary>
/// A place to put common methods used by our build providers
/// </summary>
///
internal class BuildProviderUtils
{
/// <summary>
/// Default constructor
/// </summary>
private BuildProviderUtils()
{
}
internal static void AddArtifactReference(AssemblyBuilder assemblyBuilder, BuildProvider prov, string virtualPath)
{
// add the artifact as a resource to the DLL
using (Stream input = VirtualPathProvider.OpenFile(virtualPath))
{
// derive the resource name
string name = BuildProviderUtils.GetResourceNameForVirtualPath(virtualPath);
using (Stream resStream = assemblyBuilder.CreateEmbeddedResource(prov, name))
{
int byteRead = input.ReadByte();
while (byteRead != -1)
{
resStream.WriteByte((byte)byteRead);
byteRead = input.ReadByte();
}
}
}
}
/// <summary>
/// Transforms a virtual path string into a valid resource name.
/// </summary>
/// <param name="virtualPath"></param>
/// <returns></returns>
internal static string GetResourceNameForVirtualPath(string virtualPath)
{
string name = VirtualPathUtility.ToAppRelative(virtualPath);
Debug.Assert(name.StartsWith("~/", StringComparison.OrdinalIgnoreCase), "Expected app-relative path to start with ~/");
if (name.StartsWith("~/", StringComparison.OrdinalIgnoreCase))
{
name = name.Substring(2);
}
name = name.Replace("/", ".");
Debug.Assert(name.StartsWith(".", StringComparison.OrdinalIgnoreCase) == false, "resource name unexpectedly starts with .");
return name;
}
}
}

View File

@@ -0,0 +1,100 @@
//---------------------------------------------------------------------
// <copyright file="EntityDesignerBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @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
{
/// <summary>
/// The ASP .NET Build provider for the CSDL in ADO .NET
/// </summary>
///
[BuildProviderAppliesTo(BuildProviderAppliesTo.Code)]
public class EntityDesignerBuildProvider : System.Web.Compilation.BuildProvider
{
/// <summary>
/// Default constructor
/// </summary>
public EntityDesignerBuildProvider()
{
}
/// <summary>
/// We want ASP .NET to always reset the app domain when we have to rebuild
/// </summary>
/// <param name="results"></param>
/// <returns></returns>
public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
{
return BuildProviderResultFlags.ShutdownAppDomainOnChange;
}
/// <summary>
/// Extract the CSDL, SSDL and MSL nodes from the EDMX file and store them
/// as embedded resources
/// </summary>
/// <param name="assemblyBuilder"></param>
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);
}
}
}
}

View File

@@ -0,0 +1,121 @@
//---------------------------------------------------------------------
// <copyright file="EntityModelBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @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
{
/// <summary>
/// The ASP .NET Build provider for the CSDL in ADO .NET
/// </summary>
///
[BuildProviderAppliesTo(BuildProviderAppliesTo.Code)]
public class EntityModelBuildProvider : System.Web.Compilation.BuildProvider
{
/// <summary>
/// Default constructor
/// </summary>
public EntityModelBuildProvider()
{
}
/// <summary>
/// We want ASP .NET to always reset the app domain when we have to rebuild
/// </summary>
/// <param name="results"></param>
/// <returns></returns>
public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
{
return BuildProviderResultFlags.ShutdownAppDomainOnChange;
}
/// <summary>
///
/// </summary>
/// <param name="assemblyBuilder"></param>
[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<EdmSchemaError> 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
var entityFrameworkVersion = GetEntityFrameworkVersion(BuildManager.TargetFramework.Version);
errors = generator.GenerateCode(input, output, entityFrameworkVersion);
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);
}
private static Version GetEntityFrameworkVersion(Version targetFrameworkVersion)
{
Debug.Assert(targetFrameworkVersion != null, "targetFrameworkVersion should not be null.");
Debug.Assert(targetFrameworkVersion >= new Version(3, 5), "This assembly doesn't exist pre-3.5.");
if (targetFrameworkVersion < new Version(4, 0))
{
return EntityFrameworkVersions.Version1;
}
if (targetFrameworkVersion < new Version(4, 5))
{
return EntityFrameworkVersions.Version2;
}
return EntityFrameworkVersions.Version3;
}
}
}

View File

@@ -0,0 +1,56 @@
//---------------------------------------------------------------------
// <copyright file="MappingModelBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @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.Web;
using System.Web.Hosting;
using System.Web.Compilation;
namespace System.Data.Entity.Design.AspNet
{
/// <summary>
/// The ASP .NET Build provider for the MSL in ADO .NET
/// </summary>
///
[BuildProviderAppliesTo(BuildProviderAppliesTo.Code)]
public class MappingModelBuildProvider : System.Web.Compilation.BuildProvider
{
/// <summary>
/// Default constructor
/// </summary>
public MappingModelBuildProvider()
{
}
/// <summary>
/// We want ASP .NET to always reset the app domain when we have to rebuild
/// </summary>
/// <param name="results"></param>
/// <returns></returns>
public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
{
return BuildProviderResultFlags.ShutdownAppDomainOnChange;
}
/// <summary>
///
/// </summary>
/// <param name="assemblyBuilder"></param>
public override void GenerateCode(AssemblyBuilder assemblyBuilder)
{
BuildProviderUtils.AddArtifactReference(assemblyBuilder, this, base.VirtualPath);
}
}
}

View File

@@ -0,0 +1,56 @@
//---------------------------------------------------------------------
// <copyright file="StorageModelBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @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.Web;
using System.Web.Hosting;
using System.Web.Compilation;
namespace System.Data.Entity.Design.AspNet
{
/// <summary>
/// The ASP .NET Build provider for the SSDL in ADO .NET
/// </summary>
///
[BuildProviderAppliesTo(BuildProviderAppliesTo.Code)]
public class StorageModelBuildProvider : System.Web.Compilation.BuildProvider
{
/// <summary>
/// Default constructor
/// </summary>
public StorageModelBuildProvider()
{
}
/// <summary>
/// We want ASP .NET to always reset the app domain when we have to rebuild
/// </summary>
/// <param name="results"></param>
/// <returns></returns>
public override BuildProviderResultFlags GetResultFlags(CompilerResults results)
{
return BuildProviderResultFlags.ShutdownAppDomainOnChange;
}
/// <summary>
///
/// </summary>
/// <param name="assemblyBuilder"></param>
public override void GenerateCode(AssemblyBuilder assemblyBuilder)
{
BuildProviderUtils.AddArtifactReference(assemblyBuilder, this, base.VirtualPath);
}
}
}