Skip to content

Commit eee8d3d

Browse files
MiYannibaronfel
authored andcommitted
In-progress of reviewing the Otel Maybe PR. Doing formatting adjustments and several nullable disable removals. Changed s_source to Source as a static property.
1 parent a8c1f0a commit eee8d3d

24 files changed

+159
-189
lines changed

src/Cli/Microsoft.DotNet.Cli.Utils/Activities.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Microsoft.DotNet.Cli.Utils;
1010
/// </summary>
1111
public static class Activities
1212
{
13-
1413
/// <summary>
1514
/// The main entrypoint for creating <see cref="Activity">Activities</see> in the .NET CLI.
1615
/// All activities created in the CLI should use this <see cref="ActivitySource"/>, to allow

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ internal InstantiateCommand(
5151
Arity = new ArgumentArity(0, 999)
5252
};
5353

54-
internal IReadOnlyList<Option> PassByOptions { get; } = new Option[]
55-
{
54+
internal IReadOnlyList<Option> PassByOptions { get; } =
55+
[
5656
SharedOptions.ForceOption,
5757
SharedOptions.NameOption,
5858
SharedOptions.DryRunOption,
5959
SharedOptions.NoUpdateCheckOption
60-
};
60+
];
6161

6262
internal static Task<NewCommandStatus> ExecuteAsync(
6363
NewCommandArgs newCommandArgs,
@@ -116,7 +116,7 @@ internal static HashSet<TemplateCommand> GetTemplateCommand(
116116
templateGroup,
117117
candidates);
118118
}
119-
return new HashSet<TemplateCommand>();
119+
return [];
120120
}
121121

122122
internal static void HandleNoMatchingTemplateGroup(InstantiateCommandArgs instantiateArgs, IEnumerable<TemplateGroup> templateGroups, IReporter reporter)

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.TemplateEngine.Cli.Commands
1717
internal class TemplateCommand : Command
1818
{
1919
private static readonly TimeSpan ConstraintEvaluationTimeout = TimeSpan.FromMilliseconds(1000);
20-
private static readonly string[] _helpAliases = new[] { "-h", "/h", "--help", "-?", "/?" };
20+
private static readonly string[] _helpAliases = ["-h", "/h", "--help", "-?", "/?"];
2121
private readonly TemplatePackageManager _templatePackageManager;
2222
private readonly IEngineEnvironmentSettings _environmentSettings;
2323
private readonly BaseCommand _instantiateCommand;
@@ -177,7 +177,7 @@ internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, Cance
177177
Task<(string Id, string Version, string Provider)> builtInPackageCheck = packageCoordinator.ValidateBuiltInPackageAvailabilityAsync(args.Template, cancellationToken);
178178
Task<CheckUpdateResult?> checkForUpdateTask = packageCoordinator.CheckUpdateForTemplate(args, cancellationToken);
179179

180-
Task[] tasksToWait = new Task[] { instantiateTask, builtInPackageCheck, checkForUpdateTask };
180+
Task[] tasksToWait = [instantiateTask, builtInPackageCheck, checkForUpdateTask];
181181

182182
await Task.WhenAll(tasksToWait).ConfigureAwait(false);
183183
Reporter.Output.WriteLine();

src/Cli/Microsoft.TemplateEngine.Cli/TemplateListCoordinator.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ internal TemplateListCoordinator(
2424
IEngineEnvironmentSettings engineEnvironmentSettings,
2525
TemplatePackageManager templatePackageManager,
2626
IHostSpecificDataLoader hostSpecificDataLoader)
27-
2827
{
2928
_engineEnvironmentSettings = engineEnvironmentSettings ?? throw new ArgumentNullException(nameof(engineEnvironmentSettings));
3029
_templatePackageManager = templatePackageManager ?? throw new ArgumentNullException(nameof(templatePackageManager));
@@ -49,7 +48,6 @@ internal async Task<NewCommandStatus> DisplayTemplateGroupListAsync(
4948
ListTemplateResolver resolver = new(_constraintManager, _templatePackageManager, _hostSpecificDataLoader);
5049
TemplateResolutionResult resolutionResult = await resolver.ResolveTemplatesAsync(args, _defaultLanguage, cancellationToken).ConfigureAwait(false);
5150

52-
//IReadOnlyDictionary<string, string?>? appliedParameterMatches = resolutionResult.GetAllMatchedParametersList();
5351
if (resolutionResult.TemplateGroupsWithMatchingTemplateInfoAndParameters.Any())
5452
{
5553
Reporter.Output.WriteLine(LocalizableStrings.TemplatesFoundMatchingInputParameters, GetInputParametersString(args));
@@ -67,10 +65,10 @@ internal async Task<NewCommandStatus> DisplayTemplateGroupListAsync(
6765
}
6866
else
6967
{
70-
//if there is no criteria and filters it means that dotnet new list was run but there is no templates installed.
68+
// If there is no criteria and filters, it means that dotnet new list was run but there are no templates installed.
7169
if (args.ListNameCriteria == null && !args.AppliedFilters.Any())
7270
{
73-
//No templates installed.
71+
// No templates installed.
7472
Reporter.Output.WriteLine(LocalizableStrings.NoTemplatesFound);
7573
Reporter.Output.WriteLine();
7674
// To search for the templates on NuGet.org, run:
@@ -84,7 +82,7 @@ internal async Task<NewCommandStatus> DisplayTemplateGroupListAsync(
8482
return NewCommandStatus.Success;
8583
}
8684

87-
// at least one criteria was specified.
85+
// At least one criteria was specified.
8886
// No templates found matching the following input parameter(s): {0}.
8987
Reporter.Error.WriteLine(
9088
string.Format(
@@ -196,33 +194,30 @@ internal async Task<NewCommandStatus> DisplayCommandDescriptionAsync(
196194
return NewCommandStatus.Success;
197195
}
198196

199-
private static string GetInputParametersString(ListCommandArgs args/*, IReadOnlyDictionary<string, string?>? templateParameters = null*/)
197+
private static string GetInputParametersString(ListCommandArgs args)
200198
{
201199
string separator = ", ";
202200
IEnumerable<string> appliedFilters = args.AppliedFilters
203201
.Select(filter => $"{args.GetFilterToken(filter)}='{args.GetFilterValue(filter)}'");
204202

205-
//IEnumerable<string> appliedTemplateParameters = templateParameters?
206-
// .Select(param => string.IsNullOrWhiteSpace(param.Value) ? param.Key : $"{param.Key}='{param.Value}'") ?? Array.Empty<string>();
207-
208203
StringBuilder inputParameters = new();
209204
string? mainCriteria = args.ListNameCriteria;
210205
if (!string.IsNullOrWhiteSpace(mainCriteria))
211206
{
212207
inputParameters.Append($"'{mainCriteria}'");
213-
if (appliedFilters.Any()/* || appliedTemplateParameters.Any()*/)
208+
if (appliedFilters.Any())
214209
{
215210
inputParameters.Append(separator);
216211
}
217212
}
218-
if (appliedFilters/*.Concat(appliedTemplateParameters)*/.Any())
213+
if (appliedFilters.Any())
219214
{
220-
inputParameters.Append(string.Join(separator, appliedFilters/*.Concat(appliedTemplateParameters)*/));
215+
inputParameters.Append(string.Join(separator, appliedFilters));
221216
}
222217
return inputParameters.ToString();
223218
}
224219

225-
private static string GetPartialMatchReason(TemplateResolutionResult templateResolutionResult, ListCommandArgs args/*, IReadOnlyDictionary<string, string?>? templateParameters = null*/)
220+
private static string GetPartialMatchReason(TemplateResolutionResult templateResolutionResult, ListCommandArgs args)
226221
{
227222
string separator = ", ";
228223

@@ -231,15 +226,10 @@ private static string GetPartialMatchReason(TemplateResolutionResult templateRes
231226
.Where(filter => filter.MismatchCriteria(templateResolutionResult))
232227
.Select(filter => $"{args.GetFilterToken(filter)}='{args.GetFilterValue(filter)}'");
233228

234-
//IEnumerable<string> appliedTemplateParameters = templateParameters?
235-
// .Where(parameter =>
236-
// templateResolutionResult.IsParameterMismatchReason(parameter.Key))
237-
// .Select(param => string.IsNullOrWhiteSpace(param.Value) ? param.Key : $"{param.Key}='{param.Value}'") ?? Array.Empty<string>();
238-
239229
StringBuilder inputParameters = new();
240-
if (appliedFilters/*.Concat(appliedTemplateParameters)*/.Any())
230+
if (appliedFilters.Any())
241231
{
242-
inputParameters.Append(string.Join(separator, appliedFilters/*.Concat(appliedTemplateParameters)*/));
232+
inputParameters.Append(string.Join(separator, appliedFilters));
243233
}
244234
return inputParameters.ToString();
245235
}

src/Cli/dotnet/CliSchema.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ internal static class CliSchema
3333
TypeInfoResolver = new DefaultJsonTypeInfoResolver()
3434
};
3535

36-
public record ArgumentDetails(string? description, int order, bool hidden, string? helpName, string valueType, bool hasDefaultValue, object? defaultValue, ArityDetails arity);
37-
public record ArityDetails(int minimum, int? maximum);
36+
public record ArgumentDetails(
37+
string? description,
38+
int order,
39+
bool hidden,
40+
string? helpName,
41+
string valueType,
42+
bool hasDefaultValue,
43+
object? defaultValue,
44+
ArityDetails arity);
45+
46+
public record ArityDetails(
47+
int minimum,
48+
int? maximum);
49+
3850
public record OptionDetails(
3951
string? description,
4052
bool hidden,
@@ -45,15 +57,16 @@ public record OptionDetails(
4557
object? defaultValue,
4658
ArityDetails arity,
4759
bool required,
48-
bool recursive
49-
);
60+
bool recursive);
61+
5062
public record CommandDetails(
5163
string? description,
5264
bool hidden,
5365
string[]? aliases,
5466
Dictionary<string, ArgumentDetails>? arguments,
5567
Dictionary<string, OptionDetails>? options,
5668
Dictionary<string, CommandDetails>? subcommands);
69+
5770
public record RootCommandDetails(
5871
string name,
5972
string version,
@@ -65,7 +78,6 @@ public record RootCommandDetails(
6578
Dictionary<string, CommandDetails>? subcommands
6679
) : CommandDetails(description, hidden, aliases, arguments, options, subcommands);
6780

68-
6981
public static void PrintCliSchema(CommandResult commandResult, TextWriter outputWriter, ITelemetry? telemetryClient)
7082
{
7183
var command = commandResult.Command;

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2555,4 +2555,7 @@ Proceed?</value>
25552555
<value>Tool package download needs confirmation. Run in interactive mode or use the "--yes" command-line option to confirm.</value>
25562556
<comment>{Locked="--yes"}</comment>
25572557
</data>
2558-
</root>
2558+
<data name="ToolInstallPackageIdMissing" xml:space="preserve">
2559+
<value>A package ID was not specified for tool installation.</value>
2560+
</data>
2561+
</root>

src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ public static void ProcessInputAndSendTelemetry(ParseResult result, ITelemetry t
3939

4040
internal class ThreadBlockingTelemetry : ITelemetry
4141
{
42-
private readonly Telemetry.Telemetry telemetry;
42+
private readonly Telemetry.Telemetry _telemetry;
4343

4444
internal ThreadBlockingTelemetry()
4545
{
4646
var sessionId = Environment.GetEnvironmentVariable(TelemetrySessionIdEnvironmentVariableName);
47-
telemetry = new Telemetry.Telemetry(sessionId);
47+
_telemetry = new Telemetry.Telemetry(sessionId);
4848
}
49-
public bool Enabled => telemetry.Enabled;
49+
50+
public bool Enabled => _telemetry.Enabled;
5051

5152
public void TrackEvent(string eventName, IDictionary<string, string?>? properties, IDictionary<string, double>? measurements)
5253
{
53-
telemetry.ThreadBlockingTrackEvent(eventName, properties, measurements);
54+
_telemetry.ThreadBlockingTrackEvent(eventName, properties, measurements);
5455
}
5556
}
5657
}

src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private static MSBuildArgs ConcatTelemetryLogger(MSBuildArgs msbuildArgs)
2828
}
2929
catch (Exception)
3030
{
31-
// Exceptions during telemetry shouldn't cause anything else to fail
31+
// Exceptions during _telemetry shouldn't cause anything else to fail
3232
}
3333
}
3434
return msbuildArgs;

src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Initialize(IEventSource eventSource)
2626
eventSource4.IncludeEvaluationPropertiesAndItems();
2727
}
2828

29-
// Only forward telemetry events
29+
// Only forward _telemetry events
3030
if (eventSource is IEventSource2 eventSource2)
3131
{
3232
eventSource2.TelemetryLogged += (sender, args) => BuildEventRedirector.ForwardEvent(args);

src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs

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

4-
#nullable disable
5-
64
using System.Globalization;
75
using Microsoft.Build.Framework;
86
using Microsoft.DotNet.Cli.Telemetry;
97
using Microsoft.DotNet.Cli.Utils;
10-
using Microsoft.DotNet.Configurer;
118

129
namespace Microsoft.DotNet.Cli.Commands.MSBuild;
1310

1411
public sealed class MSBuildLogger : INodeLogger
1512
{
16-
private readonly ITelemetry _telemetry;
13+
private readonly ITelemetry? _telemetry;
1714

1815
internal const string TargetFrameworkTelemetryEventName = "targetframeworkeval";
1916
internal const string BuildTelemetryEventName = "build";
@@ -52,8 +49,7 @@ public MSBuildLogger()
5249
{
5350
try
5451
{
55-
string sessionId =
56-
Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
52+
string? sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
5753

5854
if (sessionId != null)
5955
{
@@ -62,7 +58,7 @@ public MSBuildLogger()
6258
}
6359
catch (Exception)
6460
{
65-
// Exceptions during telemetry shouldn't cause anything else to fail
61+
// Exceptions during _telemetry shouldn't cause anything else to fail
6662
}
6763
}
6864

@@ -92,18 +88,18 @@ public void Initialize(IEventSource eventSource)
9288
}
9389
catch (Exception)
9490
{
95-
// Exceptions during telemetry shouldn't cause anything else to fail
91+
// Exceptions during _telemetry shouldn't cause anything else to fail
9692
}
9793
}
9894

99-
internal static void FormatAndSend(ITelemetry telemetry, TelemetryEventArgs args)
95+
internal static void FormatAndSend(ITelemetry? telemetry, TelemetryEventArgs args)
10096
{
10197
switch (args.EventName)
10298
{
10399
case TargetFrameworkTelemetryEventName:
104100
{
105101
var newEventName = $"msbuild/{TargetFrameworkTelemetryEventName}";
106-
Dictionary<string, string> maskedProperties = [];
102+
Dictionary<string, string?> maskedProperties = [];
107103

108104
foreach (var key in new[] {
109105
TargetFrameworkVersionTelemetryPropertyKey,
@@ -115,13 +111,13 @@ internal static void FormatAndSend(ITelemetry telemetry, TelemetryEventArgs args
115111
ArtifactsPathLocationTypeTelemetryPropertyKey
116112
})
117113
{
118-
if (args.Properties.TryGetValue(key, out string value))
114+
if (args.Properties.TryGetValue(key, out string? value) && value is not null)
119115
{
120116
maskedProperties.Add(key, Sha256Hasher.HashWithNormalizedCasing(value));
121117
}
122118
}
123119

124-
telemetry.TrackEvent(newEventName, maskedProperties, measurements: null);
120+
telemetry?.TrackEvent(newEventName, maskedProperties, measurements: null);
125121
break;
126122
}
127123
case BuildTelemetryEventName:
@@ -165,38 +161,38 @@ internal static void FormatAndSend(ITelemetry telemetry, TelemetryEventArgs args
165161
}
166162
}
167163

168-
private static void TrackEvent(ITelemetry telemetry, string eventName, IDictionary<string, string> eventProperties, string[] toBeHashed, string[] toBeMeasured)
164+
private static void TrackEvent(ITelemetry? telemetry, string eventName, IDictionary<string, string?> eventProperties, string[] toBeHashed, string[] toBeMeasured)
169165
{
170-
Dictionary<string, string> properties = null;
171-
Dictionary<string, double> measurements = null;
166+
Dictionary<string, string?>? properties = null;
167+
Dictionary<string, double>? measurements = null;
172168

173169
foreach (var propertyToBeHashed in toBeHashed)
174170
{
175-
if (eventProperties.TryGetValue(propertyToBeHashed, out string value))
171+
if (eventProperties.TryGetValue(propertyToBeHashed, out string? value) && value is not null)
176172
{
177-
// Lets lazy allocate in case there is tons of telemetry
178-
properties ??= new Dictionary<string, string>(eventProperties);
173+
// Lets lazy allocate in case there is tons of _telemetry
174+
properties ??= new Dictionary<string, string?>(eventProperties);
179175
properties[propertyToBeHashed] = Sha256Hasher.HashWithNormalizedCasing(value);
180176
}
181177
}
182178

183179
foreach (var propertyToBeMeasured in toBeMeasured)
184180
{
185-
if (eventProperties.TryGetValue(propertyToBeMeasured, out string value))
181+
if (eventProperties.TryGetValue(propertyToBeMeasured, out string? value))
186182
{
187-
// Lets lazy allocate in case there is tons of telemetry
188-
properties ??= new Dictionary<string, string>(eventProperties);
183+
// Lets lazy allocate in case there is tons of _telemetry
184+
properties ??= new Dictionary<string, string?>(eventProperties);
189185
properties.Remove(propertyToBeMeasured);
190186
if (double.TryParse(value, CultureInfo.InvariantCulture, out double realValue))
191187
{
192-
// Lets lazy allocate in case there is tons of telemetry
188+
// Lets lazy allocate in case there is tons of _telemetry
193189
measurements ??= [];
194190
measurements[propertyToBeMeasured] = realValue;
195191
}
196192
}
197193
}
198194

199-
telemetry.TrackEvent(eventName, properties ?? eventProperties, measurements);
195+
telemetry?.TrackEvent(eventName, properties ?? eventProperties, measurements);
200196
}
201197

202198
private void OnTelemetryLogged(object sender, TelemetryEventArgs args)
@@ -210,5 +206,5 @@ public void Shutdown()
210206

211207
public LoggerVerbosity Verbosity { get; set; }
212208

213-
public string Parameters { get; set; }
209+
public string? Parameters { get; set; }
214210
}

0 commit comments

Comments
 (0)