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,85 @@
//------------------------------------------------------------------------------
// <copyright file="AppSettingsExpressionBuilder.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.Security.Permissions;
using System.CodeDom;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Web.UI;
[ExpressionPrefix("AppSettings")]
[ExpressionEditor("System.Web.UI.Design.AppSettingsExpressionEditor, " + AssemblyRef.SystemDesign)]
public class AppSettingsExpressionBuilder : ExpressionBuilder {
public override bool SupportsEvaluate {
get {
return true;
}
}
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context) {
if (entry.DeclaringType == null || entry.PropertyInfo == null) {
return new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(this.GetType()),
"GetAppSetting",
new CodePrimitiveExpression(entry.Expression.Trim()));
}
else {
return new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(this.GetType()),
"GetAppSetting",
new CodePrimitiveExpression(entry.Expression.Trim()),
new CodeTypeOfExpression(entry.DeclaringType),
new CodePrimitiveExpression(entry.PropertyInfo.Name));
}
}
public override object EvaluateExpression(object target, BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context) {
return GetAppSetting(entry.Expression, target.GetType(), entry.PropertyInfo.Name);
}
public static object GetAppSetting(string key) {
string value = ConfigurationManager.AppSettings[key];
if (value == null) {
throw new InvalidOperationException(SR.GetString(SR.AppSetting_not_found, key));
}
return value;
}
public static object GetAppSetting(string key, Type targetType, string propertyName) {
string value = ConfigurationManager.AppSettings[key];
if (targetType != null) {
PropertyDescriptor propDesc = TypeDescriptor.GetProperties(targetType)[propertyName];
if (propDesc != null) {
if (propDesc.PropertyType != typeof(string)) {
TypeConverter converter = propDesc.Converter;
if (converter.CanConvertFrom(typeof(string))) {
return converter.ConvertFrom(value);
}
else {
throw new InvalidOperationException(SR.GetString(SR.AppSetting_not_convertible, value, propDesc.PropertyType.Name, propDesc.Name));
}
}
}
}
if (value == null) {
throw new InvalidOperationException(SR.GetString(SR.AppSetting_not_found, key));
}
return value;
}
}
}

View File

@@ -0,0 +1,87 @@
//------------------------------------------------------------------------------
// <copyright file="ApplicationBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.IO;
using System.Collections;
using System.CodeDom.Compiler;
using System.Web.Hosting;
using System.Web.Util;
using System.Web.UI;
internal class ApplicationBuildProvider: BaseTemplateBuildProvider {
internal static BuildResultCompiledGlobalAsaxType GetGlobalAsaxBuildResult(bool isPrecompiledApp) {
string cacheKey = BuildManager.GlobalAsaxAssemblyName;
// Try the cache first, and if it's not there, compile it
BuildResultCompiledGlobalAsaxType result = BuildManager.GetBuildResultFromCache(cacheKey) as
BuildResultCompiledGlobalAsaxType;
if (result != null)
return result;
// If this is a precompiled app don't attempt to compile it
if (isPrecompiledApp)
return null;
VirtualPath virtualPath = BuildManager.GlobalAsaxVirtualPath;
// If global.asax doesn't exist, just ignore it
if (!virtualPath.FileExists())
return null;
// Compile global.asax
ApplicationBuildProvider buildProvider = new ApplicationBuildProvider();
buildProvider.SetVirtualPath(virtualPath);
DateTime utcStart = DateTime.UtcNow;
BuildProvidersCompiler bpc = new BuildProvidersCompiler(virtualPath /*configPath*/,
BuildManager.GenerateRandomAssemblyName(BuildManager.GlobalAsaxAssemblyName));
// Set the BuildProvider using a single item collection
bpc.SetBuildProviders(new SingleObjectCollection(buildProvider));
CompilerResults results = bpc.PerformBuild();
result = (BuildResultCompiledGlobalAsaxType) buildProvider.GetBuildResult(results);
// Top level assembliy should not be cached to memory.
result.CacheToMemory = false;
// Cache it for next time
BuildManager.CacheBuildResult(cacheKey, result, utcStart);
// Return the compiled type
return result;
}
protected override TemplateParser CreateParser() {
return new ApplicationFileParser();
}
internal override BaseCodeDomTreeGenerator CreateCodeDomTreeGenerator(TemplateParser parser) {
return new ApplicationFileCodeDomTreeGenerator((ApplicationFileParser)parser);
}
internal override BuildResultCompiledType CreateBuildResult(Type t) {
BuildResultCompiledGlobalAsaxType result = new BuildResultCompiledGlobalAsaxType(t);
// If global.asax contains <object> tags, set a flag to avoid doing useless work
// later on in HttpApplicationFactory (VSWhidbey 453101)
if (Parser.ApplicationObjects != null || Parser.SessionObjects != null)
result.HasAppOrSessionObjects = true;
return result;
}
}
}

View File

@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <copyright file="ApplicationFileCodeDomTreeGenerator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.Web.UI;
internal class ApplicationFileCodeDomTreeGenerator : BaseCodeDomTreeGenerator {
protected ApplicationFileParser _appParser;
internal ApplicationFileCodeDomTreeGenerator(ApplicationFileParser appParser) : base(appParser) {
_appParser = appParser;
}
protected override bool IsGlobalAsaxGenerator { get { return true; } }
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,202 @@
//------------------------------------------------------------------------------
// <copyright file="BaseResourcesBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.Resources;
using System.Resources.Tools;
using System.Reflection;
using System.Globalization;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Web.Configuration;
using System.Web.Hosting;
using System.Web.Compilation;
using System.Web.UI;
using System.Web.Util;
using Util=System.Web.UI.Util;
/// Base class for BuildProviders that generate resources
[BuildProviderAppliesTo(BuildProviderAppliesTo.Resources)]
internal abstract class BaseResourcesBuildProvider : BuildProvider {
internal const string DefaultResourcesNamespace = "Resources";
// The generated namespace and type name
private string _ns;
private string _typeName;
private string _cultureName;
private bool _dontGenerateStronglyTypedClass;
internal void DontGenerateStronglyTypedClass() {
_dontGenerateStronglyTypedClass = true;
}
public override void GenerateCode(AssemblyBuilder assemblyBuilder) {
_cultureName = GetCultureName();
if (!_dontGenerateStronglyTypedClass) {
// Get the namespace and type name that we will use
_ns = Util.GetNamespaceAndTypeNameFromVirtualPath(VirtualPathObject,
(_cultureName == null) ? 1 : 2 /*chunksToIgnore*/, out _typeName);
// Always prepend the namespace with Resources.
if (_ns.Length == 0)
_ns = DefaultResourcesNamespace;
else
_ns = DefaultResourcesNamespace + "." + _ns;
}
// Get an input stream for our virtual path, and get a resource reader from it
using (Stream inputStream = OpenStream()) {
IResourceReader reader = GetResourceReader(inputStream);
try {
GenerateResourceFile(assemblyBuilder, reader);
}
catch (ArgumentException e) {
// If the inner exception is Xml, throw that instead, as it contains more
// useful info
if (e.InnerException != null &&
(e.InnerException is XmlException || e.InnerException is XmlSchemaException)) {
throw e.InnerException;
}
// Otherwise, so just rethrow
throw;
}
// Skip the code part for satellite assemblies, or if dontGenerate is set
if (_cultureName == null && !_dontGenerateStronglyTypedClass)
GenerateStronglyTypedClass(assemblyBuilder, reader);
}
}
protected abstract IResourceReader GetResourceReader(Stream inputStream);
private void GenerateResourceFile(AssemblyBuilder assemblyBuilder, IResourceReader reader) {
// Get the name of the generated .resource file
string resourceFileName;
if (_ns == null) {
// In the case where we don't generate code, just name the resource file
// after the virtual file
resourceFileName = UrlPath.GetFileNameWithoutExtension(VirtualPath) + ".resources";
}
else if (_cultureName == null) {
// Name the resource file after the generated class, since that's what the
// generated class expects
resourceFileName = _ns + "." + _typeName + ".resources";
}
else {
// If it's a non-default resource, include the culture in the name
resourceFileName = _ns + "." + _typeName + "." + _cultureName + ".resources";
}
// Make it lower case, since GetManifestResourceStream (which we use later on) is
// case sensitive
resourceFileName = resourceFileName.ToLower(CultureInfo.InvariantCulture);
Stream outputStream = null;
try {
try {
try {
}
finally {
// Put the assignment in a finally block to avoid a ThreadAbortException from
// causing the created stream to not get assigned and become leaked (Dev10 bug 844463)
outputStream = assemblyBuilder.CreateEmbeddedResource(this, resourceFileName);
}
}
catch (ArgumentException) {
// This throws an ArgumentException if the resource file name was already added.
// Catch the situation, and give a better error message (VSWhidbey 87110)
throw new HttpException(SR.GetString(SR.Duplicate_Resource_File, VirtualPath));
}
// Create an output stream from the .resource file
using (outputStream) {
using (ResourceWriter writer = new ResourceWriter(outputStream)) {
// Enable resource writer to be target-aware
writer.TypeNameConverter = System.Web.UI.TargetFrameworkUtil.TypeNameConverter;
// Copy the resources
foreach (DictionaryEntry de in reader) {
writer.AddResource((string)de.Key, de.Value);
}
}
}
}
finally {
// Always close the stream to avoid a ThreadAbortException from causing the stream
// to be leaked (Dev10 bug 844463)
if (outputStream != null) {
outputStream.Close();
}
}
}
private void GenerateStronglyTypedClass(AssemblyBuilder assemblyBuilder, IResourceReader reader) {
// Copy the resources into an IDictionary
IDictionary resourceList;
using (reader) {
resourceList = GetResourceList(reader);
}
// Generate a strongly typed class from the resources
CodeDomProvider provider = assemblyBuilder.CodeDomProvider;
string[] unmatchable;
CodeCompileUnit ccu = StronglyTypedResourceBuilder.Create(
resourceList, _typeName, _ns,
provider, false /*internalClass*/, out unmatchable);
// Ignore the unmatchable items. We just won't generate code for them,
// but they'll still be usable via the ResourceManager (VSWhidbey 248226)
// We decided to cut support for My.Resources (VSWhidbey 358088)
#if OLD
// generate a My.Resources.* override (VSWhidbey 251554)
CodeNamespace ns = new CodeNamespace();
ns.Name = "My." + _ns;
CodeTypeDeclaration type = new CodeTypeDeclaration();
type.Name = _typeName;
CodeTypeReference baseType = new CodeTypeReference(_ns + "." + _typeName);
// Need to use a global reference to avoid a conflict, since the classes have the same name
baseType.Options = CodeTypeReferenceOptions.GlobalReference;
type.BaseTypes.Add(baseType);
ns.Types.Add(type);
ccu.Namespaces.Add(ns);
#endif
// Add the code compile unit to the compilation
assemblyBuilder.AddCodeCompileUnit(this, ccu);
}
private IDictionary GetResourceList(IResourceReader reader) {
// Read the resources into a dictionary.
IDictionary resourceList = new Hashtable(StringComparer.OrdinalIgnoreCase);
foreach(DictionaryEntry de in reader)
resourceList.Add(de.Key, de.Value);
return resourceList;
}
}
}

View File

@@ -0,0 +1,215 @@
//------------------------------------------------------------------------------
// <copyright file="BaseTemplateBuildProvider.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Web.Util;
using System.Web.UI;
internal abstract class BaseTemplateBuildProvider: InternalBuildProvider {
private TemplateParser _parser;
internal TemplateParser Parser { get { return _parser; } }
internal override IAssemblyDependencyParser AssemblyDependencyParser {
get { return _parser; }
}
private string _instantiatableFullTypeName;
private string _intermediateFullTypeName;
protected abstract TemplateParser CreateParser();
internal abstract BaseCodeDomTreeGenerator CreateCodeDomTreeGenerator(TemplateParser parser);
protected internal override CodeCompileUnit GetCodeCompileUnit(out IDictionary linePragmasTable) {
Debug.Assert(_parser != null);
// Return the provider type and compiler params
Type codeDomProviderType = _parser.CompilerType.CodeDomProviderType;
// Create a code generator for the language
CodeDomProvider codeDomProvider = CompilationUtil.CreateCodeDomProviderNonPublic(
codeDomProviderType);
// Create a designer mode codedom tree for the page
BaseCodeDomTreeGenerator treeGenerator = CreateCodeDomTreeGenerator(_parser);
treeGenerator.SetDesignerMode();
CodeCompileUnit ccu = treeGenerator.GetCodeDomTree(codeDomProvider,
new StringResourceBuilder(), VirtualPathObject);
linePragmasTable = treeGenerator.LinePragmasTable;
// This code is used to see the full generated code in the debugger. Just uncomment and look at
// generatedCode in the debugger. Don't check in with this code uncommented!
#if TESTCODE
Stream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Unicode);
codeDomProvider.GenerateCodeFromCompileUnit(ccu, writer, null /*CodeGeneratorOptions*/);
writer.Flush();
stream.Seek(0, SeekOrigin.Begin);
TextReader reader = new StreamReader(stream);
string generatedCode = reader.ReadToEnd();
#endif
return ccu;
}
public override CompilerType CodeCompilerType {
get {
Debug.Assert(_parser == null);
_parser = CreateParser();
if (IgnoreParseErrors)
_parser.IgnoreParseErrors = true;
if (IgnoreControlProperties)
_parser.IgnoreControlProperties = true;
if (!ThrowOnFirstParseError)
_parser.ThrowOnFirstParseError = false;
_parser.Parse(ReferencedAssemblies, VirtualPathObject);
// If the page is non-compiled, don't ask for a language
if (!Parser.RequiresCompilation)
return null;
return _parser.CompilerType;
}
}
internal override ICollection GetCompileWithDependencies() {
// If there is a code besides file, return it
if (_parser.CodeFileVirtualPath == null)
return null;
// no-compile pages should not have any compile with dependencies
Debug.Assert(Parser.RequiresCompilation);
return new SingleObjectCollection(_parser.CodeFileVirtualPath);
}
public override void GenerateCode(AssemblyBuilder assemblyBuilder) {
// Don't generate any code for no-compile pages
if (!Parser.RequiresCompilation)
return;
BaseCodeDomTreeGenerator treeGenerator = CreateCodeDomTreeGenerator(_parser);
CodeCompileUnit ccu = treeGenerator.GetCodeDomTree(assemblyBuilder.CodeDomProvider,
assemblyBuilder.StringResourceBuilder, VirtualPathObject);
if (ccu != null) {
// Add all the assemblies
if (_parser.AssemblyDependencies != null) {
foreach (Assembly assembly in _parser.AssemblyDependencies) {
assemblyBuilder.AddAssemblyReference(assembly, ccu);
}
}
assemblyBuilder.AddCodeCompileUnit(this, ccu);
}
// Get the name of the generated type that can be instantiated. It may be null
// in updatable compilation scenarios.
_instantiatableFullTypeName = treeGenerator.GetInstantiatableFullTypeName();
// tell the assembly builder to generate a fast factory for this type
if (_instantiatableFullTypeName != null)
assemblyBuilder.GenerateTypeFactory(_instantiatableFullTypeName);
_intermediateFullTypeName = treeGenerator.GetIntermediateFullTypeName();
}
public override Type GetGeneratedType(CompilerResults results) {
return GetGeneratedType(results, useDelayLoadTypeIfEnabled: false);
}
internal Type GetGeneratedType(CompilerResults results, bool useDelayLoadTypeIfEnabled) {
// No Type is generated for no-compile pages
if (!Parser.RequiresCompilation)
return null;
// Figure out the Type that needs to be persisted
string typeName;
if (_instantiatableFullTypeName == null) {
if (Parser.CodeFileVirtualPath != null) {
// Updatable precomp of a code separation page: use the intermediate type
typeName = _intermediateFullTypeName;
}
else {
// Updatable precomp of a single page: use the base type, since nothing got compiled
return Parser.BaseType;
}
}
else {
typeName = _instantiatableFullTypeName;
}
Debug.Assert(typeName != null);
Type generatedType;
if (useDelayLoadTypeIfEnabled && DelayLoadType.Enabled) {
string assemblyFilename = Path.GetFileName(results.PathToAssembly);
string assemblyName = Util.GetAssemblyNameFromFileName(assemblyFilename);
generatedType = new DelayLoadType(assemblyName, typeName);
}
else {
generatedType = results.CompiledAssembly.GetType(typeName);
}
// It should always extend the required base type
// Note: removing this assert as advanced ControlBuilder scenarios allow changing the base type
//Debug.Assert(Parser.BaseType.IsAssignableFrom(generatedType));
return generatedType;
}
internal override BuildResultCompiledType CreateBuildResult(Type t) {
return new BuildResultCompiledTemplateType(t);
}
public override ICollection VirtualPathDependencies {
get {
return _parser.SourceDependencies;
}
}
internal override ICollection GetGeneratedTypeNames() {
if (_parser.GeneratedClassName == null && _parser.BaseTypeName == null) {
return null;
}
ArrayList collection = new ArrayList();
if (_parser.GeneratedClassName != null) {
collection.Add(_parser.GeneratedClassName);
}
if (_parser.BaseTypeName != null) {
collection.Add(Util.MakeFullTypeName(_parser.BaseTypeNamespace, _parser.BaseTypeName));
}
return collection;
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <copyright file="BuildDependencySet.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/************************************************************************************************************/
namespace System.Web.Compilation {
using System.Collections;
using System.Security.Permissions;
/// <devdoc>
/// <para>
/// Dependency set returned by BuildManager.GetCachedBuildDependencySet
/// </para>
/// </devdoc>
public sealed class BuildDependencySet {
private BuildResult _result;
internal BuildDependencySet(BuildResult result) {
_result = result;
}
public string HashCode { get { return _result.VirtualPathDependenciesHash; } }
public IEnumerable VirtualPaths { get { return _result.VirtualPathDependencies; } }
}
}

View File

@@ -0,0 +1 @@
9f26b6ed449d60e2c96baeff70f3bf474eaf9ecf

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
//------------------------------------------------------------------------------
// <copyright file="BuildProviderAppliesTo.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
[Flags]
public enum BuildProviderAppliesTo {
Web = 0x1,
Code = 0x2,
Resources = 0x4,
All = 0x7,
}
}

View File

@@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// <copyright file="BuildProviderAppliesToAttribute.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Compilation {
using System.Security.Permissions;
using System.Web.Configuration;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class BuildProviderAppliesToAttribute : Attribute {
private BuildProviderAppliesTo _appliesTo;
public BuildProviderAppliesToAttribute(BuildProviderAppliesTo appliesTo) {
_appliesTo = appliesTo;
}
public BuildProviderAppliesTo AppliesTo {
get {
return _appliesTo;
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More