renaming telemetry to diagnostic #26

This commit is contained in:
John Luo 2015-10-18 15:52:02 -07:00
Родитель 1b8f6699b6
Коммит 4ee3cbe19b
28 изменённых файлов: 119 добавлений и 123 удалений

Просмотреть файл

@ -1,4 +1,3 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14 # Visual Studio 14
VisualStudioVersion = 14.0.23107.0 VisualStudioVersion = 14.0.23107.0
@ -7,9 +6,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8B66E199-1AF
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D75011A4-DEEE-48DE-BB83-CE042F2AC05B}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D75011A4-DEEE-48DE-BB83-CE042F2AC05B}"
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.TelemetryAdapter", "src\Microsoft.Extensions.TelemetryAdapter\Microsoft.Extensions.TelemetryAdapter.xproj", "{87808F3C-362E-4261-AA4A-EE40BA39D64E}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DiagnosticAdapter", "src\Microsoft.Extensions.DiagnosticAdapter\Microsoft.Extensions.DiagnosticAdapter.xproj", "{87808F3C-362E-4261-AA4A-EE40BA39D64E}"
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.TelemetryAdapter.Test", "test\Microsoft.Extensions.TelemetryAdapter.Test\Microsoft.Extensions.TelemetryAdapter.Test.xproj", "{FB993EEE-FF13-4454-BF49-F60DD0A531F7}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DiagnosticAdapter.Test", "test\Microsoft.Extensions.DiagnosticAdapter.Test\Microsoft.Extensions.DiagnosticAdapter.Test.xproj", "{02754747-C385-4662-AD58-49CE54C3D7AF}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,16 +20,16 @@ Global
{87808F3C-362E-4261-AA4A-EE40BA39D64E}.Debug|Any CPU.Build.0 = Debug|Any CPU {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.ActiveCfg = Release|Any CPU {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.Build.0 = Release|Any CPU {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.Build.0 = Release|Any CPU
{FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {02754747-C385-4662-AD58-49CE54C3D7AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Debug|Any CPU.Build.0 = Debug|Any CPU {02754747-C385-4662-AD58-49CE54C3D7AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Release|Any CPU.ActiveCfg = Release|Any CPU {02754747-C385-4662-AD58-49CE54C3D7AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Release|Any CPU.Build.0 = Release|Any CPU {02754747-C385-4662-AD58-49CE54C3D7AF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{87808F3C-362E-4261-AA4A-EE40BA39D64E} = {8B66E199-1AFE-4B68-AC71-4521C46EC4CD} {87808F3C-362E-4261-AA4A-EE40BA39D64E} = {8B66E199-1AFE-4B68-AC71-4521C46EC4CD}
{FB993EEE-FF13-4454-BF49-F60DD0A531F7} = {D75011A4-DEEE-48DE-BB83-CE042F2AC05B} {02754747-C385-4662-AD58-49CE54C3D7AF} = {D75011A4-DEEE-48DE-BB83-CE042F2AC05B}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

Просмотреть файл

@ -9,7 +9,7 @@
"StrictSemanticVersionValidationRule" "StrictSemanticVersionValidationRule"
], ],
"packages": { "packages": {
"Microsoft.Extensions.TelemetryAdapter": { } "Microsoft.Extensions.DiagnosticAdapter": { }
} }
}, },
"Default": { // Rules to run for packages not listed in any other set. "Default": { // Rules to run for packages not listed in any other set.
@ -22,4 +22,4 @@
"StrictSemanticVersionValidationRule" "StrictSemanticVersionValidationRule"
] ]
} }
} }

Просмотреть файл

@ -4,7 +4,7 @@ EventNotification
Notice Notice
------- -------
The infrastructure for publishing notifications has moved to the .Net framework. See the new `TelemetrySource` and `TelemetryListerner` APIs in the `System.Diagnostics.Tracing.Telemetry` package. The infrastructure provided here is for subscribing to events using runtime-generated proxies. The infrastructure for publishing notifications has moved to the .Net framework. See the new `DiagnosticSource` and `DiagnosticListerner` APIs in the `System.Diagnostics.DiagnosticSource` package. The infrastructure provided here is for subscribing to events using runtime-generated proxies.
AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/t1bk7hrnqqvlx0fa/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/EventNotification/branch/dev) AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/t1bk7hrnqqvlx0fa/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/EventNotification/branch/dev)

Просмотреть файл

@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.DiagnosticAdapter;
namespace System.Diagnostics
{
public static class DiagnosticListenerExtensions
{
public static IDisposable SubscribeWithAdapter(this DiagnosticListener diagnostic, object target)
{
var adapter = new DiagnosticSourceAdapter(target);
return diagnostic.Subscribe(adapter, adapter.IsEnabled);
}
public static IDisposable SubscribeWithAdapter(
this DiagnosticListener diagnostic,
object target,
Func<string, bool> isEnabled)
{
var adapter = new DiagnosticSourceAdapter(target, isEnabled);
return diagnostic.Subscribe(adapter, adapter.IsEnabled);
}
}
}

Просмотреть файл

@ -3,11 +3,11 @@
using System; using System;
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
public class TelemetryNameAttribute : Attribute public class DiagnosticNameAttribute : Attribute
{ {
public TelemetryNameAttribute(string name) public DiagnosticNameAttribute(string name)
{ {
Name = name; Name = name;
} }

Просмотреть файл

@ -7,27 +7,27 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
public class TelemetrySourceAdapter : IObserver<KeyValuePair<string, object>> public class DiagnosticSourceAdapter : IObserver<KeyValuePair<string, object>>
{ {
private readonly Listener _listener; private readonly Listener _listener;
private readonly ITelemetrySourceMethodAdapter _methodAdapter; private readonly IDiagnosticSourceMethodAdapter _methodAdapter;
public TelemetrySourceAdapter(object target) public DiagnosticSourceAdapter(object target)
: this(target, null, new ProxyTelemetrySourceMethodAdapter()) : this(target, null, new ProxyDiagnosticSourceMethodAdapter())
{ {
} }
public TelemetrySourceAdapter(object target, Func<string, bool> isEnabled) public DiagnosticSourceAdapter(object target, Func<string, bool> isEnabled)
: this(target, isEnabled, methodAdapter: new ProxyTelemetrySourceMethodAdapter()) : this(target, isEnabled, methodAdapter: new ProxyDiagnosticSourceMethodAdapter())
{ {
} }
public TelemetrySourceAdapter( public DiagnosticSourceAdapter(
object target, object target,
Func<string, bool> isEnabled, Func<string, bool> isEnabled,
ITelemetrySourceMethodAdapter methodAdapter) IDiagnosticSourceMethodAdapter methodAdapter)
{ {
_methodAdapter = methodAdapter; _methodAdapter = methodAdapter;
@ -42,18 +42,18 @@ namespace Microsoft.Extensions.TelemetryAdapter
var methodInfos = typeInfo.DeclaredMethods; var methodInfos = typeInfo.DeclaredMethods;
foreach (var methodInfo in methodInfos) foreach (var methodInfo in methodInfos)
{ {
var notificationNameAttribute = methodInfo.GetCustomAttribute<TelemetryNameAttribute>(); var diagnosticNameAttribute = methodInfo.GetCustomAttribute<DiagnosticNameAttribute>();
if (notificationNameAttribute != null) if (diagnosticNameAttribute != null)
{ {
var subscription = new Subscription(methodInfo); var subscription = new Subscription(methodInfo);
listener.Subscriptions.Add(notificationNameAttribute.Name, subscription); listener.Subscriptions.Add(diagnosticNameAttribute.Name, subscription);
} }
} }
return listener; return listener;
} }
public bool IsEnabled(string telemetryName) public bool IsEnabled(string diagnosticName)
{ {
if (_listener.Subscriptions.Count == 0) if (_listener.Subscriptions.Count == 0)
{ {
@ -61,11 +61,11 @@ namespace Microsoft.Extensions.TelemetryAdapter
} }
return return
_listener.Subscriptions.ContainsKey(telemetryName) && _listener.Subscriptions.ContainsKey(diagnosticName) &&
(_listener.IsEnabled == null || _listener.IsEnabled(telemetryName)); (_listener.IsEnabled == null || _listener.IsEnabled(diagnosticName));
} }
public void WriteTelemetry(string telemetryName, object parameters) public void Write(string diagnosticName, object parameters)
{ {
if (parameters == null) if (parameters == null)
{ {
@ -73,12 +73,12 @@ namespace Microsoft.Extensions.TelemetryAdapter
} }
Subscription subscription; Subscription subscription;
if (!_listener.Subscriptions.TryGetValue(telemetryName, out subscription)) if (!_listener.Subscriptions.TryGetValue(diagnosticName, out subscription))
{ {
return; return;
} }
if (_listener.IsEnabled != null && !_listener.IsEnabled(telemetryName)) if (_listener.IsEnabled != null && !_listener.IsEnabled(diagnosticName))
{ {
return; return;
} }
@ -105,7 +105,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
void IObserver<KeyValuePair<string, object>>.OnNext(KeyValuePair<string, object> value) void IObserver<KeyValuePair<string, object>>.OnNext(KeyValuePair<string, object> value)
{ {
WriteTelemetry(value.Key, value.Value); Write(value.Key, value.Value);
} }
void IObserver<KeyValuePair<string, object>>.OnError(Exception error) void IObserver<KeyValuePair<string, object>>.OnError(Exception error)

Просмотреть файл

@ -4,9 +4,9 @@
using System; using System;
using System.Reflection; using System.Reflection;
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
public interface ITelemetrySourceMethodAdapter public interface IDiagnosticSourceMethodAdapter
{ {
Func<object, object, bool> Adapt(MethodInfo method, Type inputType); Func<object, object, bool> Adapt(MethodInfo method, Type inputType);
} }

Просмотреть файл

@ -5,7 +5,7 @@ using System;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public static class ProxyAssembly public static class ProxyAssembly
{ {
@ -16,11 +16,11 @@ namespace Microsoft.Extensions.TelemetryAdapter.Internal
static ProxyAssembly() static ProxyAssembly()
{ {
var assemblyName = new AssemblyName("Microsoft.Extensions.TelemetryAdapter.ProxyAssembly"); var assemblyName = new AssemblyName("Microsoft.Extensions.DiagnosticAdapter.ProxyAssembly");
var access = AssemblyBuilderAccess.Run; var access = AssemblyBuilderAccess.Run;
AssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, access); AssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, access);
ModuleBuilder = AssemblyBuilder.DefineDynamicModule("Microsoft.Extensions.TelemetryAdapter.ProxyAssembly.dll"); ModuleBuilder = AssemblyBuilder.DefineDynamicModule("Microsoft.Extensions.DiagnosticAdapter.ProxyAssembly.dll");
} }
public static TypeBuilder DefineType( public static TypeBuilder DefineType(

Просмотреть файл

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public abstract class ProxyBase public abstract class ProxyBase
{ {

Просмотреть файл

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public class ProxyBase<T> : ProxyBase where T : class public class ProxyBase<T> : ProxyBase where T : class
{ {

Просмотреть файл

@ -5,7 +5,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public class ProxyEnumerable<TSourceElement, TTargetElement> : IEnumerable<TTargetElement> public class ProxyEnumerable<TSourceElement, TTargetElement> : IEnumerable<TTargetElement>
{ {

Просмотреть файл

@ -5,7 +5,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public class ProxyList<TSourceElement, TTargetElement> : IReadOnlyList<TTargetElement> public class ProxyList<TSourceElement, TTargetElement> : IReadOnlyList<TTargetElement>
{ {

Просмотреть файл

@ -6,7 +6,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public static class ProxyMethodEmitter public static class ProxyMethodEmitter
{ {

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public class ProxyTypeCache : ConcurrentDictionary<Tuple<Type, Type>, ProxyTypeCacheResult> public class ProxyTypeCache : ConcurrentDictionary<Tuple<Type, Type>, ProxyTypeCacheResult>
{ {

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Reflection; using System.Reflection;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public class ProxyTypeCacheResult public class ProxyTypeCacheResult
{ {

Просмотреть файл

@ -8,7 +8,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public static class ProxyTypeEmitter public static class ProxyTypeEmitter
{ {

Просмотреть файл

@ -7,7 +7,7 @@
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>87808f3c-362e-4261-aa4a-ee40ba39d64e</ProjectGuid> <ProjectGuid>87808f3c-362e-4261-aa4a-ee40ba39d64e</ProjectGuid>
<RootNamespace>Microsoft.Extensions.TelemetryAdapter</RootNamespace> <RootNamespace>Microsoft.Extensions.DiagnosticAdapter</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup> </PropertyGroup>

Просмотреть файл

@ -1,5 +1,5 @@
// <auto-generated /> // <auto-generated />
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
using System.Globalization; using System.Globalization;
using System.Reflection; using System.Reflection;
@ -8,7 +8,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
internal static class Resources internal static class Resources
{ {
private static readonly ResourceManager _resourceManager private static readonly ResourceManager _resourceManager
= new ResourceManager("Microsoft.Extensions.TelemetryAdapter.Resources", typeof(Resources).GetTypeInfo().Assembly); = new ResourceManager("Microsoft.Extensions.DiagnosticAdapter.Resources", typeof(Resources).GetTypeInfo().Assembly);
/// <summary> /// <summary>
/// The property '{0}' on type '{1}' must define a getter to support proxy generation. /// The property '{0}' on type '{1}' must define a getter to support proxy generation.

Просмотреть файл

@ -4,9 +4,9 @@
using System; using System;
using System.Reflection; using System.Reflection;
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
public class ProxyTelemetrySourceMethodAdapter : ITelemetrySourceMethodAdapter public class ProxyDiagnosticSourceMethodAdapter : IDiagnosticSourceMethodAdapter
{ {
public Func<object, object, bool> Adapt(MethodInfo method, Type inputType) public Func<object, object, bool> Adapt(MethodInfo method, Type inputType)
{ {

Просмотреть файл

@ -1,9 +1,9 @@
{ {
"version": "1.0.0-*", "version": "1.0.0-*",
"description": "An TelemetryListener implementation which provides duck-typing through generated proxy types.", "description": "A DiagnosticListener implementation which provides duck-typing through generated proxy types.",
"dependencies": { "dependencies": {
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*", "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*",
"System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*" "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*"
}, },
"compilationOptions": { "compilationOptions": {
"define": [ "define": [

Просмотреть файл

@ -1,25 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.TelemetryAdapter;
namespace System.Diagnostics.Tracing
{
public static class TelemetryListenerExtensions
{
public static IDisposable SubscribeWithAdapter(this TelemetryListener telemetry, object target)
{
var adapter = new TelemetrySourceAdapter(target);
return telemetry.Subscribe(adapter, adapter.IsEnabled);
}
public static IDisposable SubscribeWithAdapter(
this TelemetryListener telemetry,
object target,
Func<string, bool> isEnabled)
{
var adapter = new TelemetrySourceAdapter(target, isEnabled);
return telemetry.Subscribe(adapter, adapter.IsEnabled);
}
}
}

Просмотреть файл

@ -4,15 +4,15 @@
using System; using System;
using Xunit; using Xunit;
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
public class TelemetrySourceAdapterTest public class DiagnosticSourceAdapterTest
{ {
public class OneTarget public class OneTarget
{ {
public int OneCallCount { get; private set; } public int OneCallCount { get; private set; }
[TelemetryName("One")] [DiagnosticName("One")]
public void One() public void One()
{ {
++OneCallCount; ++OneCallCount;
@ -78,7 +78,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
} }
[Fact] [Fact]
public void CallingWriteTelemetryWillInvokeMethod() public void CallingWriteWillInvokeMethod()
{ {
// Arrange // Arrange
var target = new OneTarget(); var target = new OneTarget();
@ -86,12 +86,12 @@ namespace Microsoft.Extensions.TelemetryAdapter
// Act & Assert // Act & Assert
Assert.Equal(0, target.OneCallCount); Assert.Equal(0, target.OneCallCount);
adapter.WriteTelemetry("One", new { }); adapter.Write("One", new { });
Assert.Equal(1, target.OneCallCount); Assert.Equal(1, target.OneCallCount);
} }
[Fact] [Fact]
public void CallingWriteTelemetryForNonEnlistedNameIsHarmless() public void CallingWriteForNonEnlistedNameIsHarmless()
{ {
// Arrange // Arrange
var target = new OneTarget(); var target = new OneTarget();
@ -99,12 +99,12 @@ namespace Microsoft.Extensions.TelemetryAdapter
// Act & Assert // Act & Assert
Assert.Equal(0, target.OneCallCount); Assert.Equal(0, target.OneCallCount);
adapter.WriteTelemetry("Two", new { }); adapter.Write("Two", new { });
Assert.Equal(0, target.OneCallCount); Assert.Equal(0, target.OneCallCount);
} }
[Fact] [Fact]
public void WriteTelemetry_True_CallsIsEnabled() public void Write_True_CallsIsEnabled()
{ {
// Arrange // Arrange
var callCount = 0; var callCount = 0;
@ -119,7 +119,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var adapter = CreateAdapter(target, isEnabled); var adapter = CreateAdapter(target, isEnabled);
// Act // Act
adapter.WriteTelemetry("One", new { }); adapter.Write("One", new { });
// Assert // Assert
Assert.Equal(1, callCount); Assert.Equal(1, callCount);
@ -127,7 +127,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
} }
[Fact] [Fact]
public void WriteTelemetry_False_CallsIsEnabled() public void Write_False_CallsIsEnabled()
{ {
// Arrange // Arrange
var callCount = 0; var callCount = 0;
@ -142,7 +142,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var adapter = CreateAdapter(target, isEnabled); var adapter = CreateAdapter(target, isEnabled);
// Act // Act
adapter.WriteTelemetry("One", new { }); adapter.Write("One", new { });
// Assert // Assert
Assert.Equal(1, callCount); Assert.Equal(1, callCount);
@ -155,7 +155,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public string Beta { get; private set; } public string Beta { get; private set; }
public int Delta { get; private set; } public int Delta { get; private set; }
[TelemetryName("Two")] [DiagnosticName("Two")]
public void Two(string alpha, string beta, int delta) public void Two(string alpha, string beta, int delta)
{ {
Alpha = alpha; Alpha = alpha;
@ -172,7 +172,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var adapter = CreateAdapter(target); var adapter = CreateAdapter(target);
// Act // Act
adapter.WriteTelemetry("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1 }); adapter.Write("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1 });
// Assert // Assert
Assert.Equal("ALPHA", target.Alpha); Assert.Equal("ALPHA", target.Alpha);
@ -188,7 +188,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var adapter = CreateAdapter(target); var adapter = CreateAdapter(target);
// Act // Act
adapter.WriteTelemetry("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1, extra = this }); adapter.Write("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1, extra = this });
// Assert // Assert
Assert.Equal("ALPHA", target.Alpha); Assert.Equal("ALPHA", target.Alpha);
@ -204,7 +204,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var adapter = CreateAdapter(target); var adapter = CreateAdapter(target);
// Act // Act
adapter.WriteTelemetry("Two", new { alpha = "ALPHA", delta = -1 }); adapter.Write("Two", new { alpha = "ALPHA", delta = -1 });
// Assert // Assert
Assert.Equal("ALPHA", target.Alpha); Assert.Equal("ALPHA", target.Alpha);
@ -213,14 +213,14 @@ namespace Microsoft.Extensions.TelemetryAdapter
} }
[Fact] [Fact]
public void WriteTelemetryCanDuckType() public void WriteCanDuckType()
{ {
// Arrange // Arrange
var target = new ThreeTarget(); var target = new ThreeTarget();
var adapter = CreateAdapter(target); var adapter = CreateAdapter(target);
// Act // Act
adapter.WriteTelemetry("Three", new adapter.Write("Three", new
{ {
person = new Person person = new Person
{ {
@ -242,14 +242,14 @@ namespace Microsoft.Extensions.TelemetryAdapter
} }
[Fact] [Fact]
public void WriteTelemetry_NominialType() public void Write_NominialType()
{ {
// Arrange // Arrange
var target = new ThreeTarget(); var target = new ThreeTarget();
var adapter = CreateAdapter(target); var adapter = CreateAdapter(target);
// Act // Act
adapter.WriteTelemetry("Three", new NominalType() adapter.Write("Three", new NominalType()
{ {
Person = new Person Person = new Person
{ {
@ -274,7 +274,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
{ {
public IPerson Person { get; private set; } public IPerson Person { get; private set; }
[TelemetryName("Three")] [DiagnosticName("Three")]
public void Three(IPerson person) public void Three(IPerson person)
{ {
Person = person; Person = person;
@ -329,9 +329,9 @@ namespace Microsoft.Extensions.TelemetryAdapter
public int Value { get; private set; } public int Value { get; private set; }
} }
private static TelemetrySourceAdapter CreateAdapter(object target, Func<string, bool> isEnabled = null) private static DiagnosticSourceAdapter CreateAdapter(object target, Func<string, bool> isEnabled = null)
{ {
return new TelemetrySourceAdapter(target, isEnabled, new ProxyTelemetrySourceMethodAdapter()); return new DiagnosticSourceAdapter(target, isEnabled, new ProxyDiagnosticSourceMethodAdapter());
} }
} }
} }

Просмотреть файл

@ -7,7 +7,7 @@ using System.Linq;
using Microsoft.AspNet.Testing.xunit; using Microsoft.AspNet.Testing.xunit;
using Xunit; using Xunit;
namespace Microsoft.Extensions.TelemetryAdapter.Internal namespace Microsoft.Extensions.DiagnosticAdapter.Internal
{ {
public class ProxyTypeEmitterTest public class ProxyTypeEmitterTest
{ {

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
@ -6,16 +6,14 @@
</PropertyGroup> </PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>fb993eee-ff13-4454-bf49-f60dd0a531f7</ProjectGuid> <ProjectGuid>02754747-c385-4662-ad58-49ce54c3d7af</ProjectGuid>
<RootNamespace>Microsoft.Extensions.TelemetryAdapter.Test</RootNamespace> <RootNamespace>Microsoft.Extensions.DiagnosticAdapter.Test</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project> </Project>

Просмотреть файл

@ -6,15 +6,15 @@ using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using Xunit; using Xunit;
namespace Microsoft.Extensions.TelemetryAdapter namespace Microsoft.Extensions.DiagnosticAdapter
{ {
public class ProxyTelemetrySourceMethodAdapterTest public class ProxyTDiagnosticSourceMethodAdapterTest
{ {
[Fact] [Fact]
public void Adapt_Throws_ForSameNamedPropertiesWithDifferentCasing() public void Adapt_Throws_ForSameNamedPropertiesWithDifferentCasing()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener1(); var listener = new Listener1();
var method = GetMethodInfo<Listener2>(l => l.Listen(5, "joey")); var method = GetMethodInfo<Listener2>(l => l.Listen(5, "joey"));
@ -36,7 +36,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_ReturnsTrueForTypeMatch() public void Adapt_ReturnsTrueForTypeMatch()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener1(); var listener = new Listener1();
var method = GetMethodInfo<Listener1>(l => l.Listen()); var method = GetMethodInfo<Listener1>(l => l.Listen());
@ -52,7 +52,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_ReturnsFalseForTypeNotMatching() public void Adapt_ReturnsFalseForTypeNotMatching()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener1(); var listener = new Listener1();
var method = GetMethodInfo<Listener1>(l => l.Listen()); var method = GetMethodInfo<Listener1>(l => l.Listen());
@ -68,7 +68,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters() public void Adapt_SplatsParameters()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener2(); var listener = new Listener2();
var value = new { id = 17, name = "Bill" }; var value = new { id = 17, name = "Bill" };
@ -87,7 +87,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters_CamelCase() public void Adapt_SplatsParameters_CamelCase()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener4(); var listener = new Listener4();
var value = new { Id = 17, Person = new Person() { Name = "Bill" } }; var value = new { Id = 17, Person = new Person() { Name = "Bill" } };
@ -106,7 +106,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters_CaseInsensitive() public void Adapt_SplatsParameters_CaseInsensitive()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener4(); var listener = new Listener4();
var value = new { ID = 17, PersOn = new Person() { Name = "Bill" }}; var value = new { ID = 17, PersOn = new Person() { Name = "Bill" }};
@ -125,7 +125,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters_ExtraEventDataIgnored() public void Adapt_SplatsParameters_ExtraEventDataIgnored()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener2(); var listener = new Listener2();
var value = new { id = 17, name = "Bill", ignored = "hi" }; var value = new { id = 17, name = "Bill", ignored = "hi" };
@ -144,7 +144,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters_ExtraParametersGetDefaultValues() public void Adapt_SplatsParameters_ExtraParametersGetDefaultValues()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener2(); var listener = new Listener2();
var value = new { }; var value = new { };
@ -163,7 +163,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters_WithProxy() public void Adapt_SplatsParameters_WithProxy()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener3(); var listener = new Listener3();
var value = new { id = 17, person = new Person() { Name = "Bill" } }; var value = new { id = 17, person = new Person() { Name = "Bill" } };
@ -182,7 +182,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
public void Adapt_SplatsParameters_WithNominalType() public void Adapt_SplatsParameters_WithNominalType()
{ {
// Arrange // Arrange
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var listener = new Listener3(); var listener = new Listener3();
var value = new NominalType() { Id = 17, Person = new Person() { Name = "Bill" } }; var value = new NominalType() { Id = 17, Person = new Person() { Name = "Bill" } };
@ -207,7 +207,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var targetMethodInfo = target.GetType().GetMethod(nameof(Listener5.TargetMethod)); var targetMethodInfo = target.GetType().GetMethod(nameof(Listener5.TargetMethod));
// Act // Act
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var callback = adapter.Adapt(targetMethodInfo, source.GetType()); var callback = adapter.Adapt(targetMethodInfo, source.GetType());
var result = callback(target, source); var result = callback(target, source);
@ -228,7 +228,7 @@ namespace Microsoft.Extensions.TelemetryAdapter
var targetMethodInfo = target.GetType().GetMethod(nameof(Listener6.Listen)); var targetMethodInfo = target.GetType().GetMethod(nameof(Listener6.Listen));
// Act // Act
var adapter = new ProxyTelemetrySourceMethodAdapter(); var adapter = new ProxyDiagnosticSourceMethodAdapter();
var callback = adapter.Adapt(targetMethodInfo, source.GetType()); var callback = adapter.Adapt(targetMethodInfo, source.GetType());
var result = callback(target, source); var result = callback(target, source);

Просмотреть файл

@ -1,10 +1,9 @@
{ {
"dependencies": { "dependencies": {
"Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*",
"Microsoft.Extensions.TelemetryAdapter": "1.0.0-*", "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*" "xunit.runner.aspnet": "2.0.0-aspnet-*"
}, },
"compile": "../../src/Microsoft.Extensions.TelemetryAdapter/ReflectionTelemetrySourceMethodAdapter.cs",
"compilationOptions": {"define": ["TEST"]}, "compilationOptions": {"define": ["TEST"]},
"commands": { "commands": {
"run": "xunit.runner.aspnet", "run": "xunit.runner.aspnet",