Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Reflection;
namespace System.Web.WebPages.Instrumentation
{
internal partial class HttpContextAdapter
{
private static readonly bool _isInstrumentationAvailable = typeof(HttpContext).GetProperty("PageInstrumentation", BindingFlags.Instance | BindingFlags.Public) != null;
internal static bool IsInstrumentationAvailable
{
get { return _isInstrumentationAvailable; }
}
}
}

View File

@@ -0,0 +1,24 @@
using System.CodeDom.Compiler;
namespace System.Web.WebPages.Instrumentation
{
[GeneratedCode("Microsoft.Web.CodeGen.DynamicCallerGenerator", "1.0.0.0")]
internal partial class HttpContextAdapter
{
internal PageInstrumentationServiceAdapter PageInstrumentation
{
get { return new PageInstrumentationServiceAdapter((object)Adaptee.PageInstrumentation); }
}
// BEGIN Adaptor Infrastructure Code
private static readonly Type _TargetType = typeof(HttpContext);
internal dynamic Adaptee { get; private set; }
internal HttpContextAdapter(object existing)
{
Adaptee = existing;
}
// END Adaptor Infrastructure Code
}
}

View File

@@ -0,0 +1,21 @@
<#@ template debug="false" hostspecific="true" language="C#" inherits="Microsoft.Web.CodeGen.DynamicCallerGenerator" #>
<#@ import namespace="System.Reflection" #>
<#@ assembly name="$(SolutionDir)\tools\Microsoft.Web.CodeGen\Microsoft.Web.CodeGen.dll" #>
<#@ output extension=".cs" #>
<#
TargetNamespace = "System.Web.WebPages.Instrumentation";
Include(MemberTypes.Property, "PageInstrumentation");
Map(
"System.Web.Instrumentation.PageInstrumentationService",
"System.Web.WebPages.Instrumentation.PageInstrumentationServiceAdapter",
s => {#><#=s#>.Adaptee<#},
s => {#>new PageInstrumentationServiceAdapter(<#=s#>)<#}
);
WriteAdaptor(
"System.Web.HttpContext",
Host.ResolvePath(@"..\..\..\ReferenceAssemblies\NetFx\Dev11\System.Web.dll")
);
#>

View File

@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.IO;
namespace System.Web.WebPages.Instrumentation
{
public class InstrumentationService
{
private static readonly bool _isAvailable = HttpContextAdapter.IsInstrumentationAvailable;
private bool _localIsAvailable = _isAvailable && PageInstrumentationServiceAdapter.IsEnabled;
public InstrumentationService()
{
ExtractInstrumentationService = GetInstrumentationService;
CreateContext = CreateSystemWebContext;
}
public bool IsAvailable
{
get { return _localIsAvailable; }
internal set { _localIsAvailable = value; }
}
internal Func<HttpContextBase, PageInstrumentationServiceAdapter> ExtractInstrumentationService { get; set; }
internal Func<string, TextWriter, int, int, bool, PageExecutionContextAdapter> CreateContext { get; set; }
public void BeginContext(HttpContextBase context, string virtualPath, TextWriter writer, int startPosition, int length, bool isLiteral)
{
RunOnListeners(context,
listener => listener.BeginContext(CreateContext(
virtualPath,
writer,
startPosition,
length,
isLiteral)));
}
public void EndContext(HttpContextBase context, string virtualPath, TextWriter writer, int startPosition, int length, bool isLiteral)
{
RunOnListeners(context,
listener => listener.EndContext(CreateContext(
virtualPath,
writer,
startPosition,
length,
isLiteral)));
}
private PageExecutionContextAdapter CreateSystemWebContext(string virtualPath, TextWriter writer, int startPosition, int length, bool isLiteral)
{
return new PageExecutionContextAdapter()
{
VirtualPath = virtualPath,
TextWriter = writer,
StartPosition = startPosition,
Length = length,
IsLiteral = isLiteral
};
}
private PageInstrumentationServiceAdapter GetInstrumentationService(HttpContextBase context)
{
HttpContextAdapter ctx = new HttpContextAdapter(context);
return ctx.PageInstrumentation;
}
private void RunOnListeners(HttpContextBase context, Action<PageExecutionListenerAdapter> act)
{
if (IsAvailable)
{
PageInstrumentationServiceAdapter instSvc = ExtractInstrumentationService(context);
if (instSvc != null)
{
foreach (PageExecutionListenerAdapter listener in instSvc.ExecutionListeners)
{
act(listener);
}
}
}
}
}
}

View File

@@ -0,0 +1,68 @@
using System.CodeDom.Compiler;
using System.IO;
using System.Linq.Expressions;
namespace System.Web.WebPages.Instrumentation
{
[GeneratedCode("Microsoft.Web.CodeGen.DynamicCallerGenerator", "1.0.0.0")]
internal partial class PageExecutionContextAdapter
{
internal bool IsLiteral
{
get { return Adaptee.IsLiteral; }
set { Adaptee.IsLiteral = value; }
}
internal int Length
{
get { return Adaptee.Length; }
set { Adaptee.Length = value; }
}
internal int StartPosition
{
get { return Adaptee.StartPosition; }
set { Adaptee.StartPosition = value; }
}
internal TextWriter TextWriter
{
get { return Adaptee.TextWriter; }
set { Adaptee.TextWriter = value; }
}
internal string VirtualPath
{
get { return Adaptee.VirtualPath; }
set { Adaptee.VirtualPath = value; }
}
private static class _CallSite_ctor_1
{
public static Func<object> Site;
static _CallSite_ctor_1()
{
Site = Expression.Lambda<Func<object>>(
Expression.New(_TargetType.GetConstructor(new Type[] { })))
.Compile();
}
}
internal PageExecutionContextAdapter()
{
Adaptee = _CallSite_ctor_1.Site();
}
// BEGIN Adaptor Infrastructure Code
private static readonly Type _TargetType = typeof(HttpContext).Assembly.GetType("System.Web.Instrumentation.PageExecutionContext");
internal dynamic Adaptee { get; private set; }
internal PageExecutionContextAdapter(object existing)
{
Adaptee = existing;
}
// END Adaptor Infrastructure Code
}
}

View File

@@ -0,0 +1,9 @@
<#@ template debug="false" hostspecific="true" language="C#" inherits="Microsoft.Web.CodeGen.DynamicCallerGenerator" #>
<#@ assembly name="$(SolutionDir)\tools\Microsoft.Web.CodeGen\Microsoft.Web.CodeGen.dll" #>
<#@ output extension=".cs" #>
<#
TargetNamespace = "System.Web.WebPages.Instrumentation";
WriteAdaptor(
"System.Web.Instrumentation.PageExecutionContext",
Host.ResolvePath(@"..\..\..\ReferenceAssemblies\NetFx\Dev11\System.Web.dll")
); #>

View File

@@ -0,0 +1,29 @@
using System.CodeDom.Compiler;
namespace System.Web.WebPages.Instrumentation
{
[GeneratedCode("Microsoft.Web.CodeGen.DynamicCallerGenerator", "1.0.0.0")]
internal partial class PageExecutionListenerAdapter
{
internal void BeginContext(PageExecutionContextAdapter context)
{
Adaptee.BeginContext(context.Adaptee);
}
internal void EndContext(PageExecutionContextAdapter context)
{
Adaptee.EndContext(context.Adaptee);
}
// BEGIN Adaptor Infrastructure Code
private static readonly Type _TargetType = typeof(HttpContext).Assembly.GetType("System.Web.Instrumentation.PageExecutionListener");
internal dynamic Adaptee { get; private set; }
internal PageExecutionListenerAdapter(object existing)
{
Adaptee = existing;
}
// END Adaptor Infrastructure Code
}
}

View File

@@ -0,0 +1,14 @@
<#@ template debug="false" hostspecific="true" language="C#" inherits="Microsoft.Web.CodeGen.DynamicCallerGenerator" #>
<#@ assembly name="$(SolutionDir)\tools\Microsoft.Web.CodeGen\Microsoft.Web.CodeGen.dll" #>
<#@ output extension=".cs" #>
<#
TargetNamespace = "System.Web.WebPages.Instrumentation";
Map(
"System.Web.Instrumentation.PageExecutionContext",
"System.Web.WebPages.Instrumentation.PageExecutionContextAdapter",
s => {#><#=s#>.Adaptee<#}
);
WriteAdaptor(
"System.Web.Instrumentation.PageExecutionListener",
Host.ResolvePath(@"..\..\..\ReferenceAssemblies\NetFx\Dev11\System.Web.dll")
); #>

View File

@@ -0,0 +1,97 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace System.Web.WebPages.Instrumentation
{
internal partial class PageInstrumentationServiceAdapter
{
private static readonly Type _targetType = typeof(HttpContext).Assembly.GetType("System.Web.Instrumentation.PageInstrumentationService");
internal PageInstrumentationServiceAdapter()
{
Adaptee = _CallSite_ctor_2.Site();
}
internal PageInstrumentationServiceAdapter(object existing)
{
Adaptee = existing;
}
internal IEnumerable<PageExecutionListenerAdapter> ExecutionListeners
{
get
{
IEnumerable<dynamic> inner = Adaptee.ExecutionListeners;
// Bug 235916: If we pass the type as an object, the callsite is limited to wherever the object is assigned to dynamic which avoids private reflection issues in
// partial trust.
return inner.Select(listener => new PageExecutionListenerAdapter((object)listener));
}
}
internal static bool IsEnabled
{
get { return _CallSite_IsEnabled_1.Getter(); }
set { _CallSite_IsEnabled_1.Setter(value); }
}
internal dynamic Adaptee { get; private set; }
private static class _CallSite_IsEnabled_1
{
public static Func<bool> Getter;
public static Action<bool> Setter;
[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Fields cannot be initialized at declaration")]
static _CallSite_IsEnabled_1()
{
PropertyInfo prop = null;
if (_targetType != null)
{
prop = _targetType.GetProperty("IsEnabled", BindingFlags.Static | BindingFlags.Public, Type.DefaultBinder, typeof(bool), Type.EmptyTypes, new ParameterModifier[0]);
}
if (prop != null)
{
Getter = Expression.Lambda<Func<bool>>(Expression.Property(null, prop)).Compile();
ParameterExpression value = Expression.Parameter(typeof(bool));
Setter = Expression.Lambda<Action<bool>>(
Expression.Assign(Expression.Property(null, prop), value), value).Compile();
}
else
{
Getter = () => false;
Setter = _ =>
{
};
}
}
}
private static class _CallSite_ctor_2
{
public static Func<object> Site;
[SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline", Justification = "Fields cannot be initialized at declaration")]
static _CallSite_ctor_2()
{
if (_targetType != null)
{
Site = Expression.Lambda<Func<object>>(
Expression.New(
_targetType.GetConstructor(new Type[] { })))
.Compile();
}
else
{
Site = () => null;
}
}
}
// END Adaptor Infrastructure Code
}
}

View File

@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Diagnostics;
using Microsoft.Internal.Web.Utils;
namespace System.Web.WebPages.Instrumentation
{
[DebuggerDisplay("({Position})\"{Value}\"")]
public class PositionTagged<T>
{
private PositionTagged()
{
Position = 0;
Value = default(T);
}
public PositionTagged(T value, int offset)
{
Position = offset;
Value = value;
}
public int Position { get; private set; }
public T Value { get; private set; }
public override bool Equals(object obj)
{
PositionTagged<T> other = obj as PositionTagged<T>;
return other != null &&
other.Position == Position &&
Equals(other.Value, Value);
}
public override int GetHashCode()
{
return HashCodeCombiner.Start()
.Add(Position)
.Add(Value)
.CombinedHash;
}
public override string ToString()
{
return Value.ToString();
}
public static implicit operator T(PositionTagged<T> value)
{
return value.Value;
}
public static implicit operator PositionTagged<T>(Tuple<T, int> value)
{
return new PositionTagged<T>(value.Item1, value.Item2);
}
public static bool operator ==(PositionTagged<T> left, PositionTagged<T> right)
{
return Equals(left, right);
}
public static bool operator !=(PositionTagged<T> left, PositionTagged<T> right)
{
return !Equals(left, right);
}
}
}