Skip to content

Commit 92b9104

Browse files
committed
More cleanup
1 parent b676215 commit 92b9104

23 files changed

+24
-75
lines changed

src/Microsoft.Diagnostics.Monitoring.Extension.Common/Microsoft.Diagnostics.Monitoring.Extension.Common.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24+
<PackageReference Include="Microsoft.Extensions.Logging" />
25+
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
2426
<PackageReference Include="System.CommandLine" />
2527
</ItemGroup>
2628

src/Microsoft.Diagnostics.Monitoring.Options/Microsoft.Diagnostics.Monitoring.Options.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,4 @@
3939
<Generator>PublicResXFileCodeGenerator</Generator>
4040
</EmbeddedResource>
4141
</ItemGroup>
42-
4342
</Project>

src/Tests/Microsoft.Diagnostics.Monitoring.ConfigurationSchema/Microsoft.Diagnostics.Monitoring.ConfigurationSchema.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
</ItemGroup>
7777

7878
<ItemGroup>
79+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
7980
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
8081
<PackageReference Include="NJsonSchema" />
8182
<PackageReference Include="NJsonSchema.NewtonsoftJson" />

src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTestCommon/TestValidatableType.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
namespace Microsoft.Diagnostics.Monitoring.TestCommon
99
{
10-
// The Validation source generator doesn't run for libraries that don't call AddValidation,
11-
// so we can't generate IValidatableInfo by using [ValidatableType] directly on types defined
12-
// in ProjectReferences. This is a workaround to force the generator running in this project to
13-
// generate IValidatableInfo for the referenced types. The containing class is not used otherwise.
1410
[ValidatableType]
1511
internal sealed class TestValidatableTypes
1612
{

src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/CollectionRuleDescriptionPipelineTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Microsoft.Diagnostics.Monitoring.Tool.UnitTests.CollectionRules.Triggers;
88
using Microsoft.Diagnostics.Monitoring.WebApi;
99
using Microsoft.Diagnostics.Monitoring.WebApi.Models;
10-
using Strings = Microsoft.Diagnostics.Monitoring.WebApi.Strings;
1110
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules;
1211
using Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options;
1312
using Microsoft.Extensions.DependencyInjection;

src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/ExtensionManifestTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public void ExtensionManifest_NameAndAssembly_Valid()
179179
Assert.Equal(ExpectedAssemblyName, manifest.AssemblyFileName);
180180
Assert.Null(manifest.ExecutableFileName);
181181

182-
183182
var validationOptions = _fixture.Services.GetRequiredService<IOptions<ValidationOptions>>().Value;
184183
manifest.Validate(_fixture.Services, validationOptions);
185184
}

src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTestsSample/Microsoft.Diagnostics.Monitoring.Tool.UnitTestsSample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net10.0</TargetFramework>
4+
<TargetFrameworks>$(ToolTargetFrameworks)</TargetFrameworks>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

src/Tools/dotnet-monitor/Auth/ApiKey/MonitorApiKeyPostConfigure.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ public void PostConfigure(string? name, MonitorApiKeyConfiguration options)
5656
// Some options are configured (but may not be valid)
5757
options.Configured = true;
5858

59-
ValidationHelper.TryValidateObject(sourceOptions, typeof(MonitorApiKeyOptions), _validationOptions, _serviceProvider, errors);
59+
ValidationHelper.TryValidateObject(
60+
sourceOptions,
61+
typeof(MonitorApiKeyOptions),
62+
_validationOptions,
63+
_serviceProvider,
64+
errors);
6065

6166
string? jwkJson = null;
6267
try

src/Tools/dotnet-monitor/CollectionRules/Actions/CollectExceptionsAction.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
using Microsoft.Extensions.Options;
1111
using Microsoft.Extensions.Configuration;
1212
using System;
13-
using System.Collections.Generic;
14-
using System.ComponentModel.DataAnnotations;
1513
using Utils = Microsoft.Diagnostics.Monitoring.WebApi.Utilities;
1614

1715
namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Actions
@@ -34,12 +32,7 @@ public ICollectionRuleAction Create(IProcessInfo processInfo, CollectExceptionsO
3432
throw new ArgumentNullException(nameof(options));
3533
}
3634

37-
List<ValidationResult> result = new();
38-
if (!ValidationHelper.TryValidateObject(options, typeof(CollectExceptionsOptions), _validationOptions, _serviceProvider, result))
39-
{
40-
throw new ValidationException(
41-
string.Join(Environment.NewLine, result.ConvertAll(r => r.ErrorMessage)));
42-
}
35+
ValidationHelper.ValidateObject(options, typeof(CollectExceptionsOptions), _validationOptions, _serviceProvider);
4336

4437
return new CollectExceptionsAction(processInfo, options);
4538
}

src/Tools/dotnet-monitor/CollectionRules/Configuration/CollectionRuleBindingHelper.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,6 @@ namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Configuration
1010
{
1111
internal static class CollectionRuleBindingHelper
1212
{
13-
// public static object CreateActionSettings(
14-
// string actionType,
15-
// Func<CollectDumpOptions> collectDump,
16-
// Func<CollectExceptionsOptions> collectExceptions
17-
// ) => actionType switch {
18-
// KnownCollectionRuleActions.CollectDump => collectDump(),
19-
// KnownCollectionRuleActions.CollectExceptions => collectExceptions(),
20-
// _ => throw new ArgumentException($"Unknown action type: {actionType}", nameof(actionType))
21-
// };
22-
23-
// public static object NewActionSettings(string actionType) =>
24-
// actionType switch {
25-
// KnownCollectionRuleActions.CollectDump => new CollectDumpOptions(),
26-
// KnownCollectionRuleActions.CollectExceptions => new CollectExceptionsOptions(),
27-
// _ => null
28-
// };
29-
30-
// public static Action SelectAction(
31-
// string actionType,
32-
// Action<CollectDumpOptions> collectDump,
33-
// Action<CollectExceptionsOptions> collectExceptions
34-
// ) => actionType switch {
35-
// KnownCollectionRuleActions.CollectDump => collectDump,
36-
// KnownCollectionRuleActions.CollectExceptions => collectExceptions,
37-
// };
38-
39-
4013
public static void BindActionSettings(IConfigurationSection actionSection, CollectionRuleActionOptions actionOptions, ICollectionRuleActionOperations actionOperations)
4114
{
4215
if (null != actionOptions &&

src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectExceptionsOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace Microsoft.Diagnostics.Tools.Monitor.CollectionRules.Options.Actions
1616
#if SCHEMAGEN
1717
[NJsonSchema.Annotations.JsonSchemaFlatten]
1818
#endif
19-
2019
internal sealed partial record class CollectExceptionsOptions : BaseRecordOptions, IEgressProviderProperties
2120
{
2221
[Display(

src/Tools/dotnet-monitor/CollectionRules/Options/Actions/CollectTraceOptions.Validate.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext vali
9191
ValidationContext providerContext = new(provider, nameof(Providers), validationContext, validationContext.Items);
9292
providerContext.MemberName = nameof(Providers) + "[" + index.ToString(CultureInfo.InvariantCulture) + "]";
9393

94-
// Note: generated validation logic doesn't recurse into members of T for List<T>, when List<T> is not required.
95-
// Need to do the recursion ourselves.
9694
var validationOptions = validationContext.GetRequiredService<IOptions<ValidationOptions>>().Value;
9795
ValidationHelper.TryValidateObject(provider, typeof(EventPipeProvider), validationOptions, providerContext, results);
9896

src/Tools/dotnet-monitor/CollectionRules/Options/CollectionRuleOptions.Validate.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,6 @@ IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext vali
2424
return results;
2525
}
2626

27-
// ValidationContext filtersContext = new(Filters, validationContext, validationContext.Items);
28-
// filtersContext.MemberName = nameof(Filters);
29-
// ValidationHelper.TryValidateItems(Filters, filtersContext, results);
30-
31-
// if (null != Trigger)
32-
// {
33-
// ValidationContext triggerContext = new(Trigger, validationContext, validationContext.Items);
34-
// triggerContext.MemberName = nameof(Trigger);
35-
// Validator.TryValidateObject(Trigger, triggerContext, results);
36-
// }
37-
38-
// ValidationContext actionsContext = new(Actions, validationContext, validationContext.Items);
39-
// actionsContext.MemberName = nameof(Actions);
40-
// ValidationHelper.TryValidateItems(Actions, actionsContext, results);
41-
4227
var actionNames = new HashSet<string>(StringComparer.Ordinal);
4328
foreach (CollectionRuleActionOptions option in Actions)
4429
{
@@ -53,4 +38,4 @@ IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext vali
5338
return results;
5439
}
5540
}
56-
}
41+
}

src/Tools/dotnet-monitor/CollectionRules/Options/ValidationHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ public static bool TryValidateObject(object options, Type type, ValidationOption
9898

9999
public static void ValidateObject(object options, Type type, ValidationOptions validationOptions, IServiceProvider serviceProvider)
100100
{
101-
if (!TryValidateObject(options, type, validationOptions, serviceProvider, new List<ValidationResult>()))
101+
List<ValidationResult> results = new();
102+
if (!TryValidateObject(options, type, validationOptions, serviceProvider, results))
102103
{
103-
throw new ValidationException("Validation failed for " + type.FullName);
104+
throw new ValidationException(string.Join(Environment.NewLine, results.ConvertAll(r => r.ErrorMessage)));
104105
}
105106
}
106107
}

src/Tools/dotnet-monitor/CommonOptionsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#nullable enable
@@ -153,4 +153,4 @@ private static string ToHexString(byte[] data)
153153
return builder.ToString();
154154
}
155155
}
156-
}
156+
}

src/Tools/dotnet-monitor/ConfigurationTokenParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public ConfigurationTokenParser(ILogger logger)
6464
{
6565
object? settings = originalSettings;
6666

67-
6867
foreach (PropertyInfo propertyInfo in GetPropertiesFromSettings(settings))
6968
{
7069
string? originalPropertyValue = (string?)propertyInfo.GetValue(settings);

src/Tools/dotnet-monitor/DataAnnotationValidateOptions.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ public DataAnnotationValidateOptions(IServiceProvider serviceProvider)
3535
public ValidateOptionsResult Validate(string? name, TOptions options)
3636
{
3737
var results = new List<ValidationResult>();
38-
var typeName = typeof(TOptions).Name;
39-
var validationContext = new ValidationContext(options, typeName, _serviceProvider, items: null) {
40-
MemberName = typeName
41-
};
42-
if (!ValidationHelper.TryValidateObject(options, typeof(TOptions), _validationOptions, validationContext, results))
38+
if (!ValidationHelper.TryValidateObject(options, typeof(TOptions), _validationOptions, _serviceProvider, results))
4339
{
4440
IList<string> failures = new List<string>();
4541
foreach (ValidationResult result in results)

src/Tools/dotnet-monitor/DynamicNamedOptionsCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Diagnostics.Tools.Monitor
2020
/// </remarks>
2121
internal sealed class DynamicNamedOptionsCache<TOptions> :
2222
OptionsCache<TOptions>
23-
where TOptions : class, new()
23+
where TOptions : class
2424
{
2525
public override TOptions GetOrAdd(string name, Func<TOptions> createOptions)
2626
{

src/Tools/dotnet-monitor/Egress/Extension/ExtensionEgressPayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
#nullable disable

src/Tools/dotnet-monitor/EndpointInfo/ServerEndpointInfoSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ private async Task ListenAsync(ReversedDiagnosticsServer server, CancellationTok
184184
try
185185
{
186186
IpcEndpointInfo info = await server.AcceptAsync(token).ConfigureAwait(false);
187+
187188
_ = Task.Run(async () =>
188189
{
189190
try

src/Tools/dotnet-monitor/OpenApi/OpenApiOptionsExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public static void ConfigureMonitorOpenApiGen(this OpenApiOptions options)
119119
{
120120
includeSchema.Type |= JsonSchemaType.Null;
121121
}
122+
122123
if (schema.Properties["exclude"] is OpenApiSchema excludeSchema)
123124
{
124125
excludeSchema.Type |= JsonSchemaType.Null;

src/Tools/dotnet-monitor/OpenApi/Transformers/RemoveFailureContentTypesOperationTransformer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform
2828
}
2929
}
3030
}
31+
3132
return Task.CompletedTask;
3233
}
3334
}

src/Tools/dotnet-monitor/RootOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ internal sealed partial class RootOptions
3838
public TemplateOptions? Templates { get; set; }
3939

4040
public DotnetMonitorDebugOptions? DotnetMonitorDebug { get; set; }
41+
4142
}
4243
}

0 commit comments

Comments
 (0)