adding in stylecop goodness (#5301)

Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
Clint Rutkas
2020-07-30 12:17:08 -07:00
committed by GitHub
parent ff93b38d23
commit d032956124
8 changed files with 73 additions and 29 deletions

View File

@@ -35,5 +35,21 @@
<ItemGroup>
<ProjectReference Include="..\ManagedTelemetry\Telemetry\Telemetry.csproj" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
</ItemGroup>
</Project>

View File

@@ -1,4 +1,8 @@
using System;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation 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;
namespace ManagedCommon

View File

@@ -1,11 +1,13 @@
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation 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;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace ManagedCommon
{

View File

@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.Tracing;
using System.Text;
namespace Microsoft.PowerToys.Telemetry.Events
{
@@ -9,6 +10,7 @@ namespace Microsoft.PowerToys.Telemetry.Events
public class DebugEvent : EventBase, IEvent
{
public string Message { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
}
}

View File

@@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.Tracing;
using System.Reflection;
using System.Text;
namespace Microsoft.PowerToys.Telemetry.Events
{
/// <summary>
/// A base class to implement properties that are common to all telemetry events.
/// A base class to implement properties that are common to all telemetry events.
/// </summary>
[EventData]
public class EventBase
@@ -15,6 +17,7 @@ namespace Microsoft.PowerToys.Telemetry.Events
public bool UTCReplace_AppSessionGuid => true;
private string _version;
public string Version
{
get
@@ -23,13 +26,14 @@ namespace Microsoft.PowerToys.Telemetry.Events
{
_version = GetVersionFromAssembly();
}
return _version;
}
}
private string GetVersionFromAssembly()
{
// For consistency this should be formatted the same way as
// For consistency this should be formatted the same way as
// https://github.com/microsoft/PowerToys/blob/710f92d99965109fd788d85ebf8b6b9e0ba1524a/src/common/common.cpp#L635
var version = Assembly.GetExecutingAssembly()?.GetName()?.Version ?? new Version();
return $"v{version.Major}.{version.Minor}.{version.Build}";

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.PowerToys.Telemetry.Events
{

View File

@@ -2,9 +2,8 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Telemetry.Events;
using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry.Events;
namespace Microsoft.PowerToys.Telemetry
{
@@ -13,7 +12,6 @@ namespace Microsoft.PowerToys.Telemetry
/// </summary>
public class PowerToysTelemetry : TelemetryBase
{
/// <summary>
/// Name for ETW event.
/// </summary>
@@ -30,20 +28,22 @@ namespace Microsoft.PowerToys.Telemetry
/// <summary>
/// Gets an instance of the <see cref="PowerLauncherTelemetry"/> class.
/// </summary>
public static PowerToysTelemetry Log = new PowerToysTelemetry();
public static PowerToysTelemetry Log { get; } = new PowerToysTelemetry();
/// <summary>
/// Publishes ETW event when an action is triggered on
/// Publishes ETW event when an action is triggered on
/// </summary>
public void WriteEvent<T>(T telemetryEvent)
where T : EventBase, IEvent
{
this.Write<T>(null, new EventSourceOptions()
{
Keywords = ProjectKeywordMeasure,
Tags = ProjectTelemetryTagProductAndServicePerformance,
},
telemetryEvent);
this.Write<T>(
null,
new EventSourceOptions()
{
Keywords = ProjectKeywordMeasure,
Tags = ProjectTelemetryTagProductAndServicePerformance,
},
telemetryEvent);
}
}
}

View File

@@ -19,5 +19,21 @@
<ItemGroup>
<Compile Include="..\..\Telemetry\TelemetryBase.cs" Link="TelemetryBase.cs" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
</ItemGroup>
</Project>