Imported Upstream version 5.0.0.42

Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-04-10 11:41:01 +00:00
parent 1190d13a04
commit 6bdd276d05
19939 changed files with 3099680 additions and 93811 deletions

View File

@@ -0,0 +1,61 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.Tracing.Tests", "tests\System.Diagnostics.Tracing.Tests.csproj", "{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}"
ProjectSection(ProjectDependencies) = postProject
{} = {}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.Tracing", "src\System.Diagnostics.Tracing.csproj", "{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU = ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU = DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU
ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU = ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{7E0E1B11-FF70-461E-99F7-C0AF252C0C60}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.ActiveCfg = net461-Windows_NT-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnet461-Windows_NTnetcoreapp|AnyCPU.Build.0 = net461-Windows_NT-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.DebugNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Debug|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.ActiveCfg = netcoreapp-Release|Any CPU
{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}.ReleaseNETCoreAppnetcoreappnetcoreapp|AnyCPU.Build.0 = netcoreapp-Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<IsNETCoreApp>true</IsNETCoreApp>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netcoreapp;
uap;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,287 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// ------------------------------------------------------------------------------
// Changes to this file must follow the http://aka.ms/api-review process.
// ------------------------------------------------------------------------------
namespace System.Diagnostics.Tracing
{
[System.FlagsAttribute]
public enum EventActivityOptions
{
Detachable = 8,
Disable = 2,
None = 0,
Recursive = 4,
}
[System.AttributeUsageAttribute((System.AttributeTargets)(64))]
public sealed partial class EventAttribute : System.Attribute
{
public EventAttribute(int eventId) { }
public System.Diagnostics.Tracing.EventActivityOptions ActivityOptions { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventChannel Channel { get { throw null; } set { } }
public int EventId { get { throw null; } }
public System.Diagnostics.Tracing.EventKeywords Keywords { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventLevel Level { get { throw null; } set { } }
public string Message { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventOpcode Opcode { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventTags Tags { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventTask Task { get { throw null; } set { } }
public byte Version { get { throw null; } set { } }
}
public enum EventChannel : byte
{
Admin = (byte)16,
Analytic = (byte)18,
Debug = (byte)19,
None = (byte)0,
Operational = (byte)17,
}
public enum EventCommand
{
Disable = -3,
Enable = -2,
SendManifest = -1,
Update = 0,
}
public partial class EventCommandEventArgs : System.EventArgs
{
internal EventCommandEventArgs() { }
public System.Collections.Generic.IDictionary<string, string> Arguments { get { throw null; } }
public System.Diagnostics.Tracing.EventCommand Command { get { throw null; } }
public bool DisableEvent(int eventId) { throw null; }
public bool EnableEvent(int eventId) { throw null; }
}
public class EventCounter {
public EventCounter(string name, EventSource eventSource) { }
public void WriteMetric(float value) { }
}
[System.AttributeUsageAttribute((System.AttributeTargets)(12), Inherited = false)]
public partial class EventDataAttribute : System.Attribute
{
public EventDataAttribute() { }
public string Name { get { throw null; } set { } }
}
[System.AttributeUsageAttribute((System.AttributeTargets)(128))]
public partial class EventFieldAttribute : System.Attribute
{
public EventFieldAttribute() { }
public System.Diagnostics.Tracing.EventFieldFormat Format { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventFieldTags Tags { get { throw null; } set { } }
}
public enum EventFieldFormat
{
Boolean = 3,
Default = 0,
Hexadecimal = 4,
HResult = 15,
Json = 12,
String = 2,
Xml = 11,
}
[System.FlagsAttribute]
public enum EventFieldTags
{
None = 0,
}
[System.AttributeUsageAttribute((System.AttributeTargets)(128))]
public partial class EventIgnoreAttribute : System.Attribute
{
public EventIgnoreAttribute() { }
}
[System.FlagsAttribute]
public enum EventKeywords : long
{
All = (long)-1,
AuditFailure = (long)4503599627370496,
AuditSuccess = (long)9007199254740992,
CorrelationHint = (long)4503599627370496,
EventLogClassic = (long)36028797018963968,
None = (long)0,
Sqm = (long)2251799813685248,
WdiContext = (long)562949953421312,
WdiDiagnostic = (long)1125899906842624,
MicrosoftTelemetry = (long)562949953421312,
}
public enum EventLevel
{
Critical = 1,
Error = 2,
Informational = 4,
LogAlways = 0,
Verbose = 5,
Warning = 3,
}
public abstract partial class EventListener : System.IDisposable
{
protected EventListener() { }
public void DisableEvents(System.Diagnostics.Tracing.EventSource eventSource) { }
public virtual void Dispose() { }
public void EnableEvents(System.Diagnostics.Tracing.EventSource eventSource, System.Diagnostics.Tracing.EventLevel level) { }
public void EnableEvents(System.Diagnostics.Tracing.EventSource eventSource, System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords matchAnyKeyword) { }
public void EnableEvents(System.Diagnostics.Tracing.EventSource eventSource, System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords matchAnyKeyword, System.Collections.Generic.IDictionary<string, string> arguments) { }
protected static int EventSourceIndex(System.Diagnostics.Tracing.EventSource eventSource) { throw null; }
protected internal virtual void OnEventSourceCreated(System.Diagnostics.Tracing.EventSource eventSource) { }
protected internal abstract void OnEventWritten(System.Diagnostics.Tracing.EventWrittenEventArgs eventData);
}
[System.FlagsAttribute]
public enum EventManifestOptions
{
AllCultures = 2,
AllowEventSourceOverride = 8,
None = 0,
OnlyIfNeededForRegistration = 4,
Strict = 1,
}
public enum EventOpcode
{
DataCollectionStart = 3,
DataCollectionStop = 4,
Extension = 5,
Info = 0,
Receive = 240,
Reply = 6,
Resume = 7,
Send = 9,
Start = 1,
Stop = 2,
Suspend = 8,
}
public partial class EventSource : System.IDisposable
{
protected EventSource() { }
protected EventSource(bool throwOnEventWriteErrors) { }
protected EventSource(System.Diagnostics.Tracing.EventSourceSettings settings) { }
protected EventSource(System.Diagnostics.Tracing.EventSourceSettings settings, params string[] traits) { }
public EventSource(string eventSourceName) { }
public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config) { }
public EventSource(string eventSourceName, System.Diagnostics.Tracing.EventSourceSettings config, params string[] traits) { }
public System.Exception ConstructionException { get { throw null; } }
public static System.Guid CurrentThreadActivityId {[System.Security.SecuritySafeCriticalAttribute]get { throw null; } }
public System.Guid Guid { get { throw null; } }
public string Name { get { throw null; } }
public System.Diagnostics.Tracing.EventSourceSettings Settings { get { throw null; } }
public event EventHandler<EventCommandEventArgs> EventCommandExecuted { add {} remove {} }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
~EventSource() { }
public static string GenerateManifest(System.Type eventSourceType, string assemblyPathToIncludeInManifest) { throw null; }
public static string GenerateManifest(System.Type eventSourceType, string assemblyPathToIncludeInManifest, System.Diagnostics.Tracing.EventManifestOptions flags) { throw null; }
public static System.Guid GetGuid(System.Type eventSourceType) { throw null; }
public static string GetName(System.Type eventSourceType) { throw null; }
public static System.Collections.Generic.IEnumerable<System.Diagnostics.Tracing.EventSource> GetSources() { throw null; }
public string GetTrait(string key) { throw null; }
public bool IsEnabled() { throw null; }
public bool IsEnabled(System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords keywords) { throw null; }
public bool IsEnabled(System.Diagnostics.Tracing.EventLevel level, System.Diagnostics.Tracing.EventKeywords keywords, System.Diagnostics.Tracing.EventChannel channel) { throw null; }
protected virtual void OnEventCommand(System.Diagnostics.Tracing.EventCommandEventArgs command) { }
public static void SendCommand(System.Diagnostics.Tracing.EventSource eventSource, System.Diagnostics.Tracing.EventCommand command, System.Collections.Generic.IDictionary<string, string> commandArguments) { }
public static void SetCurrentThreadActivityId(System.Guid activityId) { }
public static void SetCurrentThreadActivityId(System.Guid activityId, out System.Guid oldActivityThatWillContinue) { throw null; }
public override string ToString() { throw null; }
public void Write(string eventName) { }
public void Write(string eventName, System.Diagnostics.Tracing.EventSourceOptions options) { }
public void Write<T>(string eventName, T data) { }
public void Write<T>(string eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data) { }
public void Write<T>(string eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref T data) { }
public void Write<T>(string eventName, ref System.Diagnostics.Tracing.EventSourceOptions options, ref System.Guid activityId, ref System.Guid relatedActivityId, ref T data) { }
protected void WriteEvent(int eventId) { }
protected void WriteEvent(int eventId, byte[] arg1) { }
protected void WriteEvent(int eventId, int arg1) { }
protected void WriteEvent(int eventId, int arg1, int arg2) { }
protected void WriteEvent(int eventId, int arg1, int arg2, int arg3) { }
protected void WriteEvent(int eventId, int arg1, string arg2) { }
protected void WriteEvent(int eventId, long arg1) { }
protected void WriteEvent(int eventId, long arg1, byte[] arg2) { }
protected void WriteEvent(int eventId, long arg1, long arg2) { }
protected void WriteEvent(int eventId, long arg1, long arg2, long arg3) { }
protected void WriteEvent(int eventId, long arg1, string arg2) { }
protected void WriteEvent(int eventId, params object[] args) { }
protected void WriteEvent(int eventId, string arg1) { }
protected void WriteEvent(int eventId, string arg1, int arg2) { }
protected void WriteEvent(int eventId, string arg1, int arg2, int arg3) { }
protected void WriteEvent(int eventId, string arg1, long arg2) { }
protected void WriteEvent(int eventId, string arg1, string arg2) { }
protected void WriteEvent(int eventId, string arg1, string arg2, string arg3) { }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
protected unsafe void WriteEventCore(int eventId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { }
protected void WriteEventWithRelatedActivityId(int eventId, System.Guid relatedActivityId, params object[] args) { }
[System.CLSCompliantAttribute(false)]
[System.Security.SecurityCriticalAttribute]
protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Guid* relatedActivityId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { }
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
protected internal partial struct EventData
{
public System.IntPtr DataPointer { get { throw null; } set { } }
public int Size { get { throw null; } set { } }
}
}
[System.AttributeUsageAttribute((System.AttributeTargets)(4))]
public sealed partial class EventSourceAttribute : System.Attribute
{
public EventSourceAttribute() { }
public string Guid { get { throw null; } set { } }
public string LocalizationResources { get { throw null; } set { } }
public string Name { get { throw null; } set { } }
}
public partial class EventSourceException : System.Exception
{
public EventSourceException() { }
public EventSourceException(string message) { }
public EventSourceException(string message, System.Exception innerException) { }
protected EventSourceException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public partial struct EventSourceOptions
{
public System.Diagnostics.Tracing.EventActivityOptions ActivityOptions { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventKeywords Keywords { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventLevel Level { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventOpcode Opcode { get { throw null; } set { } }
public System.Diagnostics.Tracing.EventTags Tags { get { throw null; } set { } }
}
[System.FlagsAttribute]
public enum EventSourceSettings
{
Default = 0,
EtwManifestEventFormat = 4,
EtwSelfDescribingEventFormat = 8,
ThrowOnEventWriteErrors = 1,
}
[System.FlagsAttribute]
public enum EventTags
{
None = 0,
}
public enum EventTask
{
None = 0,
}
public partial class EventWrittenEventArgs : System.EventArgs
{
internal EventWrittenEventArgs() { }
public System.Guid ActivityId {[System.Security.SecurityCriticalAttribute]get { throw null; } }
public System.Diagnostics.Tracing.EventChannel Channel { get { throw null; } }
public int EventId { get { throw null; } }
public string EventName { get { throw null; } }
public System.Diagnostics.Tracing.EventSource EventSource { get { throw null; } }
public System.Diagnostics.Tracing.EventKeywords Keywords { get { throw null; } }
public System.Diagnostics.Tracing.EventLevel Level { get { throw null; } }
public string Message { get { throw null; } }
public System.Diagnostics.Tracing.EventOpcode Opcode { get { throw null; } }
public System.Collections.ObjectModel.ReadOnlyCollection<object> Payload { get { throw null; } }
public System.Collections.ObjectModel.ReadOnlyCollection<string> PayloadNames { get { throw null; } }
public System.Guid RelatedActivityId {[System.Security.SecurityCriticalAttribute]get { throw null; } }
public System.Diagnostics.Tracing.EventTags Tags { get { throw null; } }
public System.Diagnostics.Tracing.EventTask Task { get { throw null; } }
public byte Version { get { throw null; } }
}
[System.AttributeUsageAttribute((System.AttributeTargets)(64))]
public sealed partial class NonEventAttribute : System.Attribute
{
public NonEventAttribute() { }
}
}

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.Diagnostics.Tracing.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\System.Runtime\ref\System.Runtime.csproj" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,3 @@
TypesMustExist : Type 'System.Diagnostics.Tracing.EventCounter' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Diagnostics.Tracing.EventSource.add_EventCommandExecuted(System.EventHandler<System.Diagnostics.Tracing.EventCommandEventArgs>)' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Diagnostics.Tracing.EventSource.remove_EventCommandExecuted(System.EventHandler<System.Diagnostics.Tracing.EventCommandEventArgs>)' does not exist in the implementation but it does exist in the contract.

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
net461-Windows_NT;
netcoreapp-Windows_NT;
netcoreapp-Unix;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,8 @@
extern alias System_Diagnostics_Tools;
using System.Diagnostics.CodeAnalysis;
using SuppressMessageAttribute = System_Diagnostics_Tools::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute;
[assembly: SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockOnObjectsWithWeakIdentity", Scope = "member", Target = "System.Diagnostics.Tracing.EventCounter.#Enqueue(System.Single)")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockOnObjectsWithWeakIdentity", Scope = "member", Target = "System.Diagnostics.Tracing.EventCounter.#GetEventCounterPayload():System.Diagnostics.Tracing.EventCounterPayload")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockOnObjectsWithWeakIdentity", Scope = "member", Target = "System.Diagnostics.Tracing.EventCounterGroup.#OnTimer(System.Object)")]

View File

@@ -0,0 +1,168 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="UnknownError_Num" xml:space="preserve">
<value>TDB</value>
</data>
<data name="ArgumentOutOfRange_NeedNonNegNum" xml:space="preserve">
<value>Non-negative number required.</value>
</data>
<data name="ArgumentOutOfRange_MaxArgExceeded" xml:space="preserve">
<value>The total number of parameters must not exceed {0}.</value>
</data>
<data name="ArgumentOutOfRange_MaxStringsExceeded" xml:space="preserve">
<value>The number of String parameters must not exceed {0}.</value>
</data>
<data name="ArgumentOutOfRange_NeedValidId" xml:space="preserve">
<value>The ID parameter must be in the range {0} through {1}.</value>
</data>
<data name="ArgumentOutOfRange_NeedPosNum" xml:space="preserve">
<value>Positive number required.</value>
</data>
<data name="EventSource_ListenerNotFound" xml:space="preserve">
<value>Listener not found.</value>
</data>
<data name="EventSource_ToString" xml:space="preserve">
<value>EventSource({0}, {1})</value>
</data>
<data name="EventSource_ImplementGetMetadata" xml:space="preserve">
<value>Please implement the GetMetadata method in your derived class</value>
</data>
<data name="EventSource_NeedGuid" xml:space="preserve">
<value>The Guid of an EventSource must be non zero.</value>
</data>
<data name="EventSource_NeedName" xml:space="preserve">
<value>The name of an EventSource must not be null.</value>
</data>
<data name="EventSource_NeedDescriptors" xml:space="preserve">
<value>The descriptor of an EventSource must be non-null.</value>
</data>
<data name="EventSource_NeedManifest" xml:space="preserve">
<value>The manifest of an EventSource must be non-null.</value>
</data>
<data name="EventSource_EventSourceGuidInUse" xml:space="preserve">
<value>An instance of EventSource with Guid {0} already exists.</value>
</data>
<data name="EventSource_ListenerWriteFailure" xml:space="preserve">
<value>An error occurred when writing to a listener.</value>
</data>
<data name="EventSource_NoManifest" xml:space="preserve">
<value>A manifest could not be generated for this EventSource because it contains one or more ill-formed event methods.</value>
</data>
</root>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="*System.Diagnostics.Tracing*">
<Assembly Name="System.Diagnostics.Tracing">
<Namespace Name="System.Diagnostics.Tracing">
<Type Name="EventSourceAttribute" Dynamic="Required All">
<AttributeImplies Serialize="Required Public"/>
</Type>
<Type Name="EventDataAttribute" Dynamic="Required All">
<AttributeImplies Serialize="Required Public"/>
</Type>
<Type Name="EventAttribute" Dynamic="Required All"/>
<Type Name="EventSource">
<Method Name="Write{T}">
<GenericParameter Name="T" Serialize="Required Public"/>
</Method>
<Subtypes Dynamic="Required Public"/>
</Type>
<Type Name="PropertyValue.ReferenceTypeHelper{System.Object}" Dynamic="Required Public"/>
</Namespace>
</Assembly>
</Library>
</Directives>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<AssemblyName>System.Diagnostics.Tracing</AssemblyName>
<ProjectGuid>{EB880FDC-326D-42B3-A3FD-0CD3BA29A7F4}</ProjectGuid>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<NoWarn>CA2002</NoWarn>
</PropertyGroup>
<!-- Default configurations to help VS understand the options -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net461-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'net461-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<ItemGroup>
<Compile Include="FxCopBaseline.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)'=='netcoreapp'">
<ProjectReference Include="..\..\System.Runtime\src\System.Runtime.csproj" />
<Compile Include="System\Diagnostics\Tracing\EventCounter.cs" />
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)'=='true'">
<TargetingPackReference Include="mscorlib" Condition="'$(TargetGroup)' == 'net461'" />
<TargetingPackReference Include="System.Private.CoreLib" Condition="'$(TargetGroup)' == 'netcoreapp'" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Diagnostics.Tools">
<Aliases>System_Diagnostics_Tools</Aliases>
</Reference>
<ReferenceFromRuntime Include="System.Private.CoreLib" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>

View File

@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// EventActivityOptions flags allow to specify different activity related characteristics.
/// </summary>
[Flags]
public enum EventActivityOptions
{
/// <summary>
/// No special options are added to the event.
/// </summary>
None = 0,
/// <summary>
/// Disable Implicit Activity Tracking
/// </summary>
Disable = 0x2,
/// <summary>
/// Allow activity event to call itself (directly or indirectly)
/// </summary>
Recursive = 0x4,
/// <summary>
/// Allows event activity to live beyond its parent.
/// </summary>
Detachable = 0x8
}
}

View File

@@ -0,0 +1,444 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
#if ES_BUILD_PCL
using System.Threading.Tasks;
#endif
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// Provides the ability to collect statistics through EventSource
/// </summary>
public class EventCounter
{
/// <summary>
/// Initializes a new instance of the <see cref="EventCounter"/> class.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="eventSource">The event source.</param>
public EventCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (eventSource == null)
{
throw new ArgumentNullException(nameof(eventSource));
}
InitializeBuffer();
_name = name;
EventCounterGroup.AddEventCounter(eventSource, this);
}
/// <summary>
/// Writes the metric.
/// </summary>
/// <param name="value">The value.</param>
public void WriteMetric(float value)
{
Enqueue(value);
}
#region private implementation
private readonly string _name;
#region Buffer Management
// Values buffering
private const int BufferedSize = 10;
private const float UnusedBufferSlotValue = float.NegativeInfinity;
private const int UnsetIndex = -1;
private volatile float[] _bufferedValues;
private volatile int _bufferedValuesIndex;
private void InitializeBuffer()
{
_bufferedValues = new float[BufferedSize];
for (int i = 0; i < _bufferedValues.Length; i++)
{
_bufferedValues[i] = UnusedBufferSlotValue;
}
}
private void Enqueue(float value)
{
// It is possible that two threads read the same bufferedValuesIndex, but only one will be able to write the slot, so that is okay.
int i = _bufferedValuesIndex;
while (true)
{
float result = Interlocked.CompareExchange(ref _bufferedValues[i], value, UnusedBufferSlotValue);
i++;
if (_bufferedValues.Length <= i)
{
// It is possible that two threads both think the buffer is full, but only one get to actually flush it, the other
// will eventually enter this code path and potentially calling Flushing on a buffer that is not full, and that's okay too.
lock (_bufferedValues)
{
Flush();
}
i = 0;
}
if (result == UnusedBufferSlotValue)
{
// CompareExchange succeeded
_bufferedValuesIndex = i;
return;
}
}
}
private void Flush()
{
for (int i = 0; i < _bufferedValues.Length; i++)
{
var value = Interlocked.Exchange(ref _bufferedValues[i], UnusedBufferSlotValue);
if (value != UnusedBufferSlotValue)
{
OnMetricWritten(value);
}
}
_bufferedValuesIndex = 0;
}
#endregion // Buffer Management
#region Statistics Calculation
// Statistics
private int _count;
private float _sum;
private float _sumSquared;
private float _min;
private float _max;
private void OnMetricWritten(float value)
{
_sum += value;
_sumSquared += value * value;
if (_count == 0 || value > _max)
{
_max = value;
}
if (_count == 0 || value < _min)
{
_min = value;
}
_count++;
}
internal EventCounterPayload GetEventCounterPayload()
{
lock (_bufferedValues)
{
Flush();
EventCounterPayload result = new EventCounterPayload();
result.Name = _name;
result.Count = _count;
result.Mean = _sum / _count;
result.StandardDeviation = (float)Math.Sqrt(_sumSquared / _count - _sum * _sum / _count / _count);
result.Min = _min;
result.Max = _max;
ResetStatistics();
return result;
}
}
private void ResetStatistics()
{
_count = 0;
_sum = 0;
_sumSquared = 0;
_min = 0;
_max = 0;
}
#endregion // Statistics Calculation
#endregion // private implementation
}
#region internal supporting classes
[EventData]
internal class EventCounterPayload : IEnumerable<KeyValuePair<string, object>>
{
public string Name { get; set; }
public float Mean { get; set; }
public float StandardDeviation { get; set; }
public int Count { get; set; }
public float Min { get; set; }
public float Max { get; set; }
public float IntervalSec { get; internal set; }
#region Implementation of the IEnumerable interface
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
return ForEnumeration.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ForEnumeration.GetEnumerator();
}
private IEnumerable<KeyValuePair<string, object>> ForEnumeration
{
get
{
yield return new KeyValuePair<string, object>("Name", Name);
yield return new KeyValuePair<string, object>("Mean", Mean);
yield return new KeyValuePair<string, object>("StandardDeviation", StandardDeviation);
yield return new KeyValuePair<string, object>("Count", Count);
yield return new KeyValuePair<string, object>("Min", Min);
yield return new KeyValuePair<string, object>("Max", Max);
}
}
#endregion // Implementation of the IEnumerable interface
}
internal class EventCounterGroup : IDisposable
{
private readonly EventSource _eventSource;
private readonly int _eventSourceIndex;
private readonly List<EventCounter> _eventCounters;
internal EventCounterGroup(EventSource eventSource, int eventSourceIndex)
{
_eventSource = eventSource;
_eventSourceIndex = eventSourceIndex;
_eventCounters = new List<EventCounter>();
RegisterCommandCallback();
}
private void Add(EventCounter eventCounter)
{
_eventCounters.Add(eventCounter);
}
#region EventSource Command Processing
private void RegisterCommandCallback()
{
_eventSource.EventCommandExecuted += OnEventSourceCommand;
}
private void OnEventSourceCommand(object sender, EventCommandEventArgs e)
{
if (e.Command == EventCommand.Enable || e.Command == EventCommand.Update)
{
string valueStr;
float value;
if (e.Arguments.TryGetValue("EventCounterIntervalSec", out valueStr) && float.TryParse(valueStr, out value))
{
EnableTimer(value);
}
}
}
#endregion // EventSource Command Processing
#region Global EventCounterGroup Array management
private static EventCounterGroup[] s_eventCounterGroups;
internal static void AddEventCounter(EventSource eventSource, EventCounter eventCounter)
{
int eventSourceIndex = EventListenerHelper.EventSourceIndex(eventSource);
EventCounterGroup.EnsureEventSourceIndexAvailable(eventSourceIndex);
EventCounterGroup eventCounterGroup = GetEventCounterGroup(eventSource);
eventCounterGroup.Add(eventCounter);
}
private static void EnsureEventSourceIndexAvailable(int eventSourceIndex)
{
if (EventCounterGroup.s_eventCounterGroups == null)
{
EventCounterGroup.s_eventCounterGroups = new EventCounterGroup[eventSourceIndex + 1];
}
else if (eventSourceIndex >= EventCounterGroup.s_eventCounterGroups.Length)
{
EventCounterGroup[] newEventCounterGroups = new EventCounterGroup[eventSourceIndex + 1];
Array.Copy(EventCounterGroup.s_eventCounterGroups, 0, newEventCounterGroups, 0, EventCounterGroup.s_eventCounterGroups.Length);
EventCounterGroup.s_eventCounterGroups = newEventCounterGroups;
}
}
private static EventCounterGroup GetEventCounterGroup(EventSource eventSource)
{
int eventSourceIndex = EventListenerHelper.EventSourceIndex(eventSource);
EventCounterGroup result = EventCounterGroup.s_eventCounterGroups[eventSourceIndex];
if (result == null)
{
result = new EventCounterGroup(eventSource, eventSourceIndex);
EventCounterGroup.s_eventCounterGroups[eventSourceIndex] = result;
}
return result;
}
#endregion // Global EventCounterGroup Array management
#region Timer Processing
private DateTime _timeStampSinceCollectionStarted;
private int _pollingIntervalInMilliseconds;
private Timer _pollingTimer;
private void EnableTimer(float pollingIntervalInSeconds)
{
if (pollingIntervalInSeconds == 0)
{
if (_pollingTimer != null)
{
_pollingTimer.Dispose();
_pollingTimer = null;
}
_pollingIntervalInMilliseconds = 0;
}
else if (_pollingIntervalInMilliseconds == 0 || pollingIntervalInSeconds < _pollingIntervalInMilliseconds)
{
_pollingIntervalInMilliseconds = (int)(pollingIntervalInSeconds * 1000);
if (_pollingTimer != null)
{
_pollingTimer.Dispose();
_pollingTimer = null;
}
_timeStampSinceCollectionStarted = DateTime.Now;
_pollingTimer = new Timer(OnTimer, null, _pollingIntervalInMilliseconds, _pollingIntervalInMilliseconds);
}
}
private void OnTimer(object state)
{
if (_eventSource.IsEnabled())
{
DateTime now = DateTime.Now;
TimeSpan elapsed = now - _timeStampSinceCollectionStarted;
lock (_pollingTimer)
{
foreach (var eventCounter in _eventCounters)
{
EventCounterPayload payload = eventCounter.GetEventCounterPayload();
payload.IntervalSec = (float)elapsed.TotalSeconds;
_eventSource.Write("EventCounters", new EventSourceOptions() { Level = EventLevel.LogAlways }, new { Payload = payload });
}
_timeStampSinceCollectionStarted = now;
}
}
else
{
_pollingTimer.Dispose();
_pollingTimer = null;
EventCounterGroup.s_eventCounterGroups[_eventSourceIndex] = null;
}
}
#region PCL timer hack
#if ES_BUILD_PCL
internal delegate void TimerCallback(object state);
internal sealed class Timer : CancellationTokenSource, IDisposable
{
private int _period;
private TimerCallback _callback;
private object _state;
internal Timer(TimerCallback callback, object state, int dueTime, int period)
{
_callback = callback;
_state = state;
_period = period;
Schedule(dueTime);
}
private void Schedule(int dueTime)
{
Task.Delay(dueTime, Token).ContinueWith(OnTimer, null, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.Default);
}
private void OnTimer(Task t, object s)
{
Schedule(_period);
_callback(_state);
}
public new void Dispose() { base.Cancel(); }
}
#endif
#endregion // PCL timer hack
#endregion // Timer Processing
#region Implementation of the IDisposable interface
private bool _disposed = false;
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
return;
}
if (disposing)
{
if (_pollingTimer != null)
{
_pollingTimer.Dispose();
_pollingTimer = null;
}
}
_disposed = true;
}
#endregion // Implementation of the IDisposable interface
}
// This class a work-around because .NET V4.6.2 did not make EventSourceIndex public (it was only protected)
// We make this helper class to get around that protection. We want V4.6.3 to make this public at which
// point this class is no longer needed and can be removed.
internal class EventListenerHelper : EventListener {
public new static int EventSourceIndex(EventSource eventSource) { return EventListener.EventSourceIndex(eventSource); }
protected override void OnEventWritten(EventWrittenEventArgs eventData) { } // override abstact methods to keep compiler happy
}
#endregion // internal supporting classes
}

View File

@@ -0,0 +1,193 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
#if ES_BUILD_STANDALONE
using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
#endif
#if !ES_BUILD_AGAINST_DOTNET_V35
using Contract = System.Diagnostics.Contracts.Contract;
#else
using Contract = Microsoft.Diagnostics.Contracts.Internal.Contract;
#endif
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
internal struct EventDescriptor
{
# region private
[FieldOffset(0)]
private int m_traceloggingId;
[FieldOffset(0)]
private ushort m_id;
[FieldOffset(2)]
private byte m_version;
[FieldOffset(3)]
private byte m_channel;
[FieldOffset(4)]
private byte m_level;
[FieldOffset(5)]
private byte m_opcode;
[FieldOffset(6)]
private ushort m_task;
[FieldOffset(8)]
private long m_keywords;
#endregion
public EventDescriptor(
int traceloggingId,
byte level,
byte opcode,
long keywords
)
{
this.m_id = 0;
this.m_version = 0;
this.m_channel = 0;
this.m_traceloggingId = traceloggingId;
this.m_level = level;
this.m_opcode = opcode;
this.m_task = 0;
this.m_keywords = keywords;
}
public EventDescriptor(
int id,
byte version,
byte channel,
byte level,
byte opcode,
int task,
long keywords
)
{
if (id < 0)
{
throw new ArgumentOutOfRangeException(nameof(id), Resources.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (id > ushort.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(id), Resources.GetResourceString("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
}
m_traceloggingId = 0;
m_id = (ushort)id;
m_version = version;
m_channel = channel;
m_level = level;
m_opcode = opcode;
m_keywords = keywords;
if (task < 0)
{
throw new ArgumentOutOfRangeException(nameof(task), Resources.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if (task > ushort.MaxValue)
{
throw new ArgumentOutOfRangeException(nameof(task), Resources.GetResourceString("ArgumentOutOfRange_NeedValidId", 1, ushort.MaxValue));
}
m_task = (ushort)task;
}
public int EventId
{
get
{
return m_id;
}
}
public byte Version
{
get
{
return m_version;
}
}
public byte Channel
{
get
{
return m_channel;
}
}
public byte Level
{
get
{
return m_level;
}
}
public byte Opcode
{
get
{
return m_opcode;
}
}
public int Task
{
get
{
return m_task;
}
}
public long Keywords
{
get
{
return m_keywords;
}
}
public override bool Equals(object obj)
{
if (!(obj is EventDescriptor))
return false;
return Equals((EventDescriptor) obj);
}
public override int GetHashCode()
{
return m_id ^ m_version ^ m_channel ^ m_level ^ m_opcode ^ m_task ^ (int)m_keywords;
}
public bool Equals(EventDescriptor other)
{
if ((m_id != other.m_id) ||
(m_version != other.m_version) ||
(m_channel != other.m_channel) ||
(m_level != other.m_level) ||
(m_opcode != other.m_opcode) ||
(m_task != other.m_task) ||
(m_keywords != other.m_keywords))
{
return false;
}
return true;
}
public static bool operator ==(EventDescriptor event1, EventDescriptor event2)
{
return event1.Equals(event2);
}
public static bool operator !=(EventDescriptor event1, EventDescriptor event2)
{
return !event1.Equals(event2);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
f5e80591372b54e944387dd55dd6afc5ec89359c

View File

@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.Serialization;
#if ES_BUILD_STANDALONE
using Environment = Microsoft.Diagnostics.Tracing.Internal.Environment;
#endif
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing
#else
namespace System.Diagnostics.Tracing
#endif
{
/// <summary>
/// Exception that is thrown when an error occurs during EventSource operation.
/// </summary>
#if (!ES_BUILD_PCL && !PROJECTN)
#if FEATURE_SERIALIZATION
[Serializable]
#endif
#endif
public class EventSourceException : Exception
{
/// <summary>
/// Initializes a new instance of the EventSourceException class.
/// </summary>
public EventSourceException() :
base(Resources.GetResourceString("EventSource_ListenerWriteFailure")) { }
/// <summary>
/// Initializes a new instance of the EventSourceException class with a specified error message.
/// </summary>
public EventSourceException(string message) : base(message) { }
/// <summary>
/// Initializes a new instance of the EventSourceException class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
public EventSourceException(string message, Exception innerException) : base(message, innerException) { }
#if (!ES_BUILD_PCL && !PROJECTN)
/// <summary>
/// Initializes a new instance of the EventSourceException class with serialized data.
/// </summary>
protected EventSourceException(SerializationInfo info, StreamingContext context) : base(info, context) { }
#endif
internal EventSourceException(Exception innerException) :
base(Resources.GetResourceString("EventSource_ListenerWriteFailure"), innerException) { }
}
}

View File

@@ -0,0 +1,343 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.InteropServices;
using System.Security;
using Microsoft.Reflection;
using Microsoft.Win32;
namespace System.Diagnostics.Tracing
{
public partial class EventSource : IDisposable
{
// ActivityID support (see also WriteEventWithRelatedActivityIdCore)
/// <summary>
/// When a thread starts work that is on behalf of 'something else' (typically another
/// thread or network request) it should mark the thread as working on that other work.
/// This API marks the current thread as working on activity 'activityID'. This API
/// should be used when the caller knows the thread's current activity (the one being
/// overwritten) has completed. Otherwise, callers should prefer the overload that
/// return the oldActivityThatWillContinue (below).
///
/// All events created with the EventSource on this thread are also tagged with the
/// activity ID of the thread.
///
/// It is common, and good practice after setting the thread to an activity to log an event
/// with a 'start' opcode to indicate that precise time/thread where the new activity
/// started.
/// </summary>
/// <param name="activityId">A Guid that represents the new activity with which to mark
/// the current thread</param>
[System.Security.SecuritySafeCritical]
public static void SetCurrentThreadActivityId(Guid activityId)
{
if (TplEtwProvider.Log != null)
TplEtwProvider.Log.SetActivityId(activityId);
#if FEATURE_MANAGED_ETW
#if FEATURE_ACTIVITYSAMPLING
Guid newId = activityId;
#endif // FEATURE_ACTIVITYSAMPLING
// We ignore errors to keep with the convention that EventSources do not throw errors.
// Note we can't access m_throwOnWrites because this is a static method.
if (UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(
UnsafeNativeMethods.ManifestEtw.ActivityControl.EVENT_ACTIVITY_CTRL_GET_SET_ID,
ref activityId) == 0)
{
#if FEATURE_ACTIVITYSAMPLING
var activityDying = s_activityDying;
if (activityDying != null && newId != activityId)
{
if (activityId == Guid.Empty)
{
activityId = FallbackActivityId;
}
// OutputDebugString(string.Format("Activity dying: {0} -> {1}", activityId, newId));
activityDying(activityId); // This is actually the OLD activity ID.
}
#endif // FEATURE_ACTIVITYSAMPLING
}
#endif // FEATURE_MANAGED_ETW
}
/// <summary>
/// When a thread starts work that is on behalf of 'something else' (typically another
/// thread or network request) it should mark the thread as working on that other work.
/// This API marks the current thread as working on activity 'activityID'. It returns
/// whatever activity the thread was previously marked with. There is a convention that
/// callers can assume that callees restore this activity mark before the callee returns.
/// To encourage this this API returns the old activity, so that it can be restored later.
///
/// All events created with the EventSource on this thread are also tagged with the
/// activity ID of the thread.
///
/// It is common, and good practice after setting the thread to an activity to log an event
/// with a 'start' opcode to indicate that precise time/thread where the new activity
/// started.
/// </summary>
/// <param name="activityId">A Guid that represents the new activity with which to mark
/// the current thread</param>
/// <param name="oldActivityThatWillContinue">The Guid that represents the current activity
/// which will continue at some point in the future, on the current thread</param>
[System.Security.SecuritySafeCritical]
public static void SetCurrentThreadActivityId(Guid activityId, out Guid oldActivityThatWillContinue)
{
oldActivityThatWillContinue = activityId;
#if FEATURE_MANAGED_ETW
// We ignore errors to keep with the convention that EventSources do not throw errors.
// Note we can't access m_throwOnWrites because this is a static method.
UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(
UnsafeNativeMethods.ManifestEtw.ActivityControl.EVENT_ACTIVITY_CTRL_GET_SET_ID,
ref oldActivityThatWillContinue);
#endif // FEATURE_MANAGED_ETW
// We don't call the activityDying callback here because the caller has declared that
// it is not dying.
if (TplEtwProvider.Log != null)
TplEtwProvider.Log.SetActivityId(activityId);
}
/// <summary>
/// Retrieves the ETW activity ID associated with the current thread.
/// </summary>
public static Guid CurrentThreadActivityId
{
[System.Security.SecuritySafeCritical]
get
{
// We ignore errors to keep with the convention that EventSources do not throw
// errors. Note we can't access m_throwOnWrites because this is a static method.
Guid retVal = new Guid();
#if FEATURE_MANAGED_ETW
UnsafeNativeMethods.ManifestEtw.EventActivityIdControl(
UnsafeNativeMethods.ManifestEtw.ActivityControl.EVENT_ACTIVITY_CTRL_GET_ID,
ref retVal);
#endif // FEATURE_MANAGED_ETW
return retVal;
}
}
private int GetParameterCount(EventMetadata eventData)
{
int paramCount;
if(eventData.Parameters == null)
{
paramCount = eventData.ParameterTypes.Length;
}
else
{
paramCount = eventData.Parameters.Length;
}
return paramCount;
}
private Type GetDataType(EventMetadata eventData, int parameterId)
{
Type dataType;
if(eventData.Parameters == null)
{
dataType = EventTypeToType(eventData.ParameterTypes[parameterId]);
}
else
{
dataType = eventData.Parameters[parameterId].ParameterType;
}
return dataType;
}
private static readonly bool m_EventSourcePreventRecursion = true;
internal partial struct EventMetadata
{
public EventMetadata(EventDescriptor descriptor,
EventTags tags,
bool enabledForAnyListener,
bool enabledForETW,
string name,
string message,
EventParameterType[] parameterTypes)
{
this.Descriptor = descriptor;
this.Tags = tags;
this.EnabledForAnyListener = enabledForAnyListener;
this.EnabledForETW = enabledForETW;
this.TriggersActivityTracking = 0;
this.Name = name;
this.Message = message;
this.Parameters = null;
this.TraceLoggingEventTypes = null;
this.ActivityOptions = EventActivityOptions.None;
this.ParameterTypes = parameterTypes;
this.HasRelatedActivityID = false;
}
}
public enum EventParameterType
{
Boolean,
Byte,
SByte,
Char,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
IntPtr,
Single,
Double,
Decimal,
Guid,
String
}
private Type EventTypeToType(EventParameterType type)
{
switch (type)
{
case EventParameterType.Boolean:
return typeof(bool);
case EventParameterType.Byte:
return typeof(byte);
case EventParameterType.SByte:
return typeof(sbyte);
case EventParameterType.Char:
return typeof(char);
case EventParameterType.Int16:
return typeof(short);
case EventParameterType.UInt16:
return typeof(ushort);
case EventParameterType.Int32:
return typeof(int);
case EventParameterType.UInt32:
return typeof(uint);
case EventParameterType.Int64:
return typeof(long);
case EventParameterType.UInt64:
return typeof(ulong);
case EventParameterType.IntPtr:
return typeof(IntPtr);
case EventParameterType.Single:
return typeof(float);
case EventParameterType.Double:
return typeof(double);
case EventParameterType.Decimal:
return typeof(decimal);
case EventParameterType.Guid:
return typeof(Guid);
case EventParameterType.String:
return typeof(string);
default:
// TODO: should I throw an exception here?
return null;
}
}
}
internal partial class ManifestBuilder
{
private string GetTypeNameHelper(Type type)
{
switch (type.GetTypeCode())
{
case (Microsoft.Reflection.TypeCode)TypeCode.Boolean:
return "win:Boolean";
case (Microsoft.Reflection.TypeCode)TypeCode.Byte:
return "win:UInt8";
case (Microsoft.Reflection.TypeCode)TypeCode.Char:
case (Microsoft.Reflection.TypeCode)TypeCode.UInt16:
return "win:UInt16";
case (Microsoft.Reflection.TypeCode)TypeCode.UInt32:
return "win:UInt32";
case (Microsoft.Reflection.TypeCode)TypeCode.UInt64:
return "win:UInt64";
case (Microsoft.Reflection.TypeCode)TypeCode.SByte:
return "win:Int8";
case (Microsoft.Reflection.TypeCode)TypeCode.Int16:
return "win:Int16";
case (Microsoft.Reflection.TypeCode)TypeCode.Int32:
return "win:Int32";
case (Microsoft.Reflection.TypeCode)TypeCode.Int64:
return "win:Int64";
case (Microsoft.Reflection.TypeCode)TypeCode.String:
return "win:UnicodeString";
case (Microsoft.Reflection.TypeCode)TypeCode.Single:
return "win:Float";
case (Microsoft.Reflection.TypeCode)TypeCode.Double:
return "win:Double";
case (Microsoft.Reflection.TypeCode)TypeCode.DateTime:
return "win:FILETIME";
default:
if (type == typeof(Guid))
return "win:GUID";
else if (type == typeof(IntPtr))
return "win:Pointer";
else if ((type.IsArray || type.IsPointer) && type.GetElementType() == typeof(byte))
return "win:Binary";
ManifestError(Resources.GetResourceString("EventSource_UnsupportedEventTypeInManifest", type.Name), true);
return string.Empty;
}
}
}
internal partial class EventProvider
{
[System.Security.SecurityCritical]
internal unsafe int SetInformation(
UnsafeNativeMethods.ManifestEtw.EVENT_INFO_CLASS eventInfoClass,
IntPtr data,
uint dataSize)
{
int status = UnsafeNativeMethods.ManifestEtw.ERROR_NOT_SUPPORTED;
if (!m_setInformationMissing)
{
try
{
status = UnsafeNativeMethods.ManifestEtw.EventSetInformation(
m_regHandle,
eventInfoClass,
(void *)data,
(int)dataSize);
}
catch (TypeLoadException)
{
m_setInformationMissing = true;
}
}
return status;
}
}
internal static class Resources
{
internal static string GetResourceString(string key, params object[] args)
{
string fmt = SR.GetResourceString(key, null);
if (fmt != null)
return string.Format(fmt, args);
string sargs = String.Empty;
foreach(var arg in args)
{
if (sargs != String.Empty)
sargs += ", ";
sargs += arg.ToString();
}
return key + " (" + sargs + ")";
}
public static string GetRuntimeResourceString(string key, params object[] args)
{
return GetResourceString(key, args);
}
}
}

View File

@@ -0,0 +1,373 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
#if ES_BUILD_STANDALONE
namespace Microsoft.Diagnostics.Tracing.Internal
#else
namespace System.Diagnostics.Tracing.Internal
#endif
{
#if ES_BUILD_AGAINST_DOTNET_V35
using Microsoft.Internal;
#endif
using Microsoft.Reflection;
using System.Reflection;
internal static class Environment
{
public static readonly string NewLine = System.Environment.NewLine;
public static int TickCount
{ get { return System.Environment.TickCount; } }
public static string GetResourceString(string key, params object[] args)
{
string fmt = rm.GetString(key);
if (fmt != null)
return string.Format(fmt, args);
string sargs = String.Empty;
foreach(var arg in args)
{
if (sargs != String.Empty)
sargs += ", ";
sargs += arg.ToString();
}
return key + " (" + sargs + ")";
}
public static string GetRuntimeResourceString(string key, params object[] args)
{
return GetResourceString(key, args);
}
private static System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Microsoft.Diagnostics.Tracing.Messages", typeof(Environment).Assembly());
}
}
#if ES_BUILD_AGAINST_DOTNET_V35
namespace Microsoft.Diagnostics.Contracts.Internal
{
internal class Contract
{
public static void Assert(bool invariant)
{
Assert(invariant, string.Empty);
}
public static void Assert(bool invariant, string message)
{
if (!invariant)
{
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
throw new Exception("Assertion failed: " + message);
}
}
public static void EndContractBlock()
{ }
}
}
namespace Microsoft.Internal
{
using System.Text;
internal static class Tuple
{
public static Tuple<T1> Create<T1>(T1 item1)
{
return new Tuple<T1>(item1);
}
public static Tuple<T1, T2> Create<T1, T2>(T1 item1, T2 item2)
{
return new Tuple<T1, T2>(item1, item2);
}
}
[Serializable]
internal class Tuple<T1>
{
private readonly T1 m_Item1;
public T1 Item1 { get { return m_Item1; } }
public Tuple(T1 item1)
{
m_Item1 = item1;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("(");
sb.Append(m_Item1);
sb.Append(")");
return sb.ToString();
}
int Size
{
get
{
return 1;
}
}
}
[Serializable]
public class Tuple<T1, T2>
{
private readonly T1 m_Item1;
private readonly T2 m_Item2;
public T1 Item1 { get { return m_Item1; } }
public T2 Item2 { get { return m_Item2; } }
public Tuple(T1 item1, T2 item2)
{
m_Item1 = item1;
m_Item2 = item2;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("(");
sb.Append(m_Item1);
sb.Append(", ");
sb.Append(m_Item2);
sb.Append(")");
return sb.ToString();
}
int Size
{
get
{
return 2;
}
}
}
}
#endif
namespace Microsoft.Reflection
{
using System.Reflection;
#if (ES_BUILD_PCL || PROJECTN)
[Flags]
public enum BindingFlags
{
DeclaredOnly = 0x02, // Only look at the members declared on the Type
Instance = 0x04, // Include Instance members in search
Static = 0x08, // Include Static members in search
Public = 0x10, // Include Public members in search
NonPublic = 0x20, // Include Non-Public members in search
}
public enum TypeCode {
Empty = 0, // Null reference
Object = 1, // Instance that isn't a value
DBNull = 2, // Database null value
Boolean = 3, // Boolean
Char = 4, // Unicode character
SByte = 5, // Signed 8-bit integer
Byte = 6, // Unsigned 8-bit integer
Int16 = 7, // Signed 16-bit integer
UInt16 = 8, // Unsigned 16-bit integer
Int32 = 9, // Signed 32-bit integer
UInt32 = 10, // Unsigned 32-bit integer
Int64 = 11, // Signed 64-bit integer
UInt64 = 12, // Unsigned 64-bit integer
Single = 13, // IEEE 32-bit float
Double = 14, // IEEE 64-bit double
Decimal = 15, // Decimal
DateTime = 16, // DateTime
String = 18, // Unicode character string
}
#endif
static class ReflectionExtensions
{
#if (!ES_BUILD_PCL && !PROJECTN)
//
// Type extension methods
//
public static bool IsEnum(this Type type) { return type.IsEnum; }
public static bool IsAbstract(this Type type) { return type.IsAbstract; }
public static bool IsSealed(this Type type) { return type.IsSealed; }
public static bool IsValueType(this Type type) { return type.IsValueType; }
public static bool IsGenericType(this Type type) { return type.IsGenericType; }
public static Type BaseType(this Type type) { return type.BaseType; }
public static Assembly Assembly(this Type type) { return type.Assembly; }
public static TypeCode GetTypeCode(this Type type) { return Type.GetTypeCode(type); }
public static bool ReflectionOnly(this Assembly assm) { return assm.ReflectionOnly; }
#else // ES_BUILD_PCL
//
// Type extension methods
//
public static bool IsEnum(this Type type) { return type.GetTypeInfo().IsEnum; }
public static bool IsAbstract(this Type type) { return type.GetTypeInfo().IsAbstract; }
public static bool IsSealed(this Type type) { return type.GetTypeInfo().IsSealed; }
public static bool IsValueType(this Type type) { return type.GetTypeInfo().IsValueType; }
public static bool IsGenericType(this Type type) { return type.IsConstructedGenericType; }
public static Type BaseType(this Type type) { return type.GetTypeInfo().BaseType; }
public static Assembly Assembly(this Type type) { return type.GetTypeInfo().Assembly; }
public static IEnumerable<PropertyInfo> GetProperties(this Type type) { return type.GetRuntimeProperties(); }
public static MethodInfo GetGetMethod(this PropertyInfo propInfo) { return propInfo.GetMethod; }
public static Type[] GetGenericArguments(this Type type) { return type.GenericTypeArguments; }
public static MethodInfo[] GetMethods(this Type type, BindingFlags flags)
{
// Minimal implementation to cover only the cases we need
System.Diagnostics.Debug.Assert((flags & BindingFlags.DeclaredOnly) != 0);
System.Diagnostics.Debug.Assert((flags & ~(BindingFlags.DeclaredOnly|BindingFlags.Instance|BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic)) == 0);
Func<MethodInfo, bool> visFilter;
Func<MethodInfo, bool> instFilter;
switch (flags & (BindingFlags.Public | BindingFlags.NonPublic))
{
case 0: visFilter = mi => false; break;
case BindingFlags.Public: visFilter = mi => mi.IsPublic; break;
case BindingFlags.NonPublic: visFilter = mi => !mi.IsPublic; break;
default: visFilter = mi => true; break;
}
switch (flags & (BindingFlags.Instance | BindingFlags.Static))
{
case 0: instFilter = mi => false; break;
case BindingFlags.Instance: instFilter = mi => !mi.IsStatic; break;
case BindingFlags.Static: instFilter = mi => mi.IsStatic; break;
default: instFilter = mi => true; break;
}
List<MethodInfo> methodInfos = new List<MethodInfo>();
foreach (var declaredMethod in type.GetTypeInfo().DeclaredMethods)
{
if (visFilter(declaredMethod) && instFilter(declaredMethod))
methodInfos.Add(declaredMethod);
}
return methodInfos.ToArray();
}
public static FieldInfo[] GetFields(this Type type, BindingFlags flags)
{
// Minimal implementation to cover only the cases we need
System.Diagnostics.Debug.Assert((flags & BindingFlags.DeclaredOnly) != 0);
System.Diagnostics.Debug.Assert((flags & ~(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) == 0);
Func<FieldInfo, bool> visFilter;
Func<FieldInfo, bool> instFilter;
switch (flags & (BindingFlags.Public | BindingFlags.NonPublic))
{
case 0: visFilter = fi => false; break;
case BindingFlags.Public: visFilter = fi => fi.IsPublic; break;
case BindingFlags.NonPublic: visFilter = fi => !fi.IsPublic; break;
default: visFilter = fi => true; break;
}
switch (flags & (BindingFlags.Instance | BindingFlags.Static))
{
case 0: instFilter = fi => false; break;
case BindingFlags.Instance: instFilter = fi => !fi.IsStatic; break;
case BindingFlags.Static: instFilter = fi => fi.IsStatic; break;
default: instFilter = fi => true; break;
}
List<FieldInfo> fieldInfos = new List<FieldInfo>();
foreach (var declaredField in type.GetTypeInfo().DeclaredFields)
{
if (visFilter(declaredField) && instFilter(declaredField))
fieldInfos.Add(declaredField);
}
return fieldInfos.ToArray();
}
public static Type GetNestedType(this Type type, string nestedTypeName)
{
TypeInfo ti = null;
foreach(var nt in type.GetTypeInfo().DeclaredNestedTypes)
{
if (nt.Name == nestedTypeName)
{
ti = nt;
break;
}
}
return ti == null ? null : ti.AsType();
}
public static TypeCode GetTypeCode(this Type type)
{
if (type == typeof(bool)) return TypeCode.Boolean;
else if (type == typeof(byte)) return TypeCode.Byte;
else if (type == typeof(char)) return TypeCode.Char;
else if (type == typeof(ushort)) return TypeCode.UInt16;
else if (type == typeof(uint)) return TypeCode.UInt32;
else if (type == typeof(ulong)) return TypeCode.UInt64;
else if (type == typeof(sbyte)) return TypeCode.SByte;
else if (type == typeof(short)) return TypeCode.Int16;
else if (type == typeof(int)) return TypeCode.Int32;
else if (type == typeof(long)) return TypeCode.Int64;
else if (type == typeof(string)) return TypeCode.String;
else if (type == typeof(float)) return TypeCode.Single;
else if (type == typeof(double)) return TypeCode.Double;
else if (type == typeof(DateTime)) return TypeCode.DateTime;
else if (type == (typeof(Decimal))) return TypeCode.Decimal;
else return TypeCode.Object;
}
//
// FieldInfo extension methods
//
public static object GetRawConstantValue(this FieldInfo fi)
{ return fi.GetValue(null); }
//
// Assembly extension methods
//
public static bool ReflectionOnly(this Assembly assm)
{
// In PCL we can't load in reflection-only context
return false;
}
#endif
}
}
// Defining some no-ops in PCL builds
#if ES_BUILD_PCL || PROJECTN
namespace System.Security
{
class SuppressUnmanagedCodeSecurityAttribute : Attribute { }
enum SecurityAction { Demand }
}
namespace System.Security.Permissions
{
class HostProtectionAttribute : Attribute { public bool MayLeakOnAbort { get; set; } }
class PermissionSetAttribute : Attribute
{
public PermissionSetAttribute(System.Security.SecurityAction action) { }
public bool Unrestricted { get; set; }
}
}
#endif
#if PROJECTN
namespace System
{
public static class AppDomain
{
public static int GetCurrentThreadId()
{
return (int)Interop.Kernel32.GetCurrentThreadId();
}
}
}
#endif

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