Skip to content

Commit

Permalink
Update StyleCop (#2162)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti authored Feb 6, 2024
1 parent 213913e commit e3250fa
Show file tree
Hide file tree
Showing 205 changed files with 786 additions and 732 deletions.
8 changes: 4 additions & 4 deletions CoreWidgetProvider/Helpers/CPUStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace CoreWidgetProvider.Helpers;
internal sealed class CPUStats : IDisposable
{
// CPU counters
private readonly PerformanceCounter procPerf = new ("Processor Information", "% Processor Utility", "_Total");
private readonly PerformanceCounter procPerformance = new ("Processor Information", "% Processor Performance", "_Total");
private readonly PerformanceCounter procFrequency = new ("Processor Information", "Processor Frequency", "_Total");
private readonly Dictionary<Process, PerformanceCounter> cpuCounters = new ();
private readonly PerformanceCounter procPerf = new("Processor Information", "% Processor Utility", "_Total");
private readonly PerformanceCounter procPerformance = new("Processor Information", "% Processor Performance", "_Total");
private readonly PerformanceCounter procFrequency = new("Processor Information", "Processor Frequency", "_Total");
private readonly Dictionary<Process, PerformanceCounter> cpuCounters = new();

internal sealed class ProcessStats
{
Expand Down
8 changes: 4 additions & 4 deletions CoreWidgetProvider/Helpers/GPUStats.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics;
Expand All @@ -10,9 +10,9 @@ namespace CoreWidgetProvider.Helpers;
internal sealed class GPUStats : IDisposable
{
// GPU counters
private readonly Dictionary<int, List<PerformanceCounter>> gpuCounters = new ();
private readonly Dictionary<int, List<PerformanceCounter>> gpuCounters = new();

private readonly List<Data> stats = new ();
private readonly List<Data> stats = new();

public sealed class Data
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public void GetGPUPerfCounters()

if (!gpuCounters.TryGetValue(phys, out var value))
{
value = new ();
value = new();
gpuCounters.Add(phys, value);
}

Expand Down
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/IconLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CoreWidgetProvider.Helpers;

public class IconLoader
{
private static readonly Dictionary<string, string> Base64ImageRegistry = new ();
private static readonly Dictionary<string, string> Base64ImageRegistry = new();

public static string GetIconAsBase64(string filename)
{
Expand Down
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CoreWidgetProvider.Helpers;

public class Log
{
private static readonly ComponentLogger _logger = new ("CoreWidgetProvider");
private static readonly ComponentLogger _logger = new("CoreWidgetProvider");

public static Logger? Logger() => _logger.Logger;
}
Expand Down
12 changes: 6 additions & 6 deletions CoreWidgetProvider/Helpers/MemoryStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace CoreWidgetProvider.Helpers;

internal sealed class MemoryStats : IDisposable
{
private readonly PerformanceCounter memCommitted = new ("Memory", "Committed Bytes", string.Empty);
private readonly PerformanceCounter memCached = new ("Memory", "Cache Bytes", string.Empty);
private readonly PerformanceCounter memCommittedLimit = new ("Memory", "Commit Limit", string.Empty);
private readonly PerformanceCounter memPoolPaged = new ("Memory", "Pool Paged Bytes", string.Empty);
private readonly PerformanceCounter memPoolNonPaged = new ("Memory", "Pool Nonpaged Bytes", string.Empty);
private readonly PerformanceCounter memCommitted = new("Memory", "Committed Bytes", string.Empty);
private readonly PerformanceCounter memCached = new("Memory", "Cache Bytes", string.Empty);
private readonly PerformanceCounter memCommittedLimit = new("Memory", "Commit Limit", string.Empty);
private readonly PerformanceCounter memPoolPaged = new("Memory", "Pool Paged Bytes", string.Empty);
private readonly PerformanceCounter memPoolNonPaged = new("Memory", "Pool Nonpaged Bytes", string.Empty);

public float MemUsage
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public ulong MemNonPagedPool

public void GetData()
{
Windows.Win32.System.SystemInformation.MEMORYSTATUSEX memStatus = new ();
Windows.Win32.System.SystemInformation.MEMORYSTATUSEX memStatus = default;
memStatus.dwLength = (uint)Marshal.SizeOf(typeof(Windows.Win32.System.SystemInformation.MEMORYSTATUSEX));
if (PInvoke.GlobalMemoryStatusEx(out memStatus))
{
Expand Down
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/NetworkStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CoreWidgetProvider.Helpers;

internal sealed class NetworkStats : IDisposable
{
private readonly Dictionary<string, List<PerformanceCounter>> networkCounters = new ();
private readonly Dictionary<string, List<PerformanceCounter>> networkCounters = new();

private Dictionary<string, Data> NetworkUsages { get; set; } = new Dictionary<string, Data>();

Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Helpers/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Windows.ApplicationModel.Resources;

namespace CoreWidgetProvider.Helpers;

public static class Resources
{
private static ResourceLoader? _resourceLoader;
Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Windows.ApplicationModel.Activation;

namespace CoreWidgetProvider;

public sealed class Program
{
[MTAThread]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@

namespace COM;

internal static class Guids
{
public const string IClassFactory = "00000001-0000-0000-C000-000000000046";
public const string IUnknown = "00000000-0000-0000-C000-000000000046";
}

// IClassFactory declaration
[ComImport]
[ComVisible(false)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid(COM.Guids.IClassFactory)]
internal interface IClassFactory
{
[PreserveSig]
int CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject);

[PreserveSig]
int LockServer(bool fLock);
}

[ComVisible(true)]
public class WidgetProviderFactory<T> : IClassFactory
where T : IWidgetProvider
Expand Down Expand Up @@ -70,3 +50,23 @@ int IClassFactory.LockServer(bool fLock)
private const int CLASSENOAGGREGATION = unchecked((int)0x80040110);
private const int ENOINTERFACE = unchecked((int)0x80004002);
}

internal static class Guids
{
public const string IClassFactory = "00000001-0000-0000-C000-000000000046";
public const string IUnknown = "00000000-0000-0000-C000-000000000046";
}

// IClassFactory declaration
[ComImport]
[ComVisible(false)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid(COM.Guids.IClassFactory)]
internal interface IClassFactory
{
[PreserveSig]
int CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject);

[PreserveSig]
int LockServer(bool fLock);
}
4 changes: 2 additions & 2 deletions CoreWidgetProvider/Widgets/CoreWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected bool Enabled
get; set;
}

protected Dictionary<WidgetPageState, string> Template { get; set; } = new ();
protected Dictionary<WidgetPageState, string> Template { get; set; } = new();

public CoreWidget()
{
Expand Down Expand Up @@ -102,7 +102,7 @@ public virtual void UpdateWidget()
{
LoadContentData();

WidgetUpdateRequestOptions updateOptions = new (Id)
WidgetUpdateRequestOptions updateOptions = new(Id)
{
Data = GetData(Page),
Template = GetTemplateForPage(Page),
Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Widgets/Enums/WidgetActivityState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

namespace CoreWidgetProvider.Widgets.Enums;

public enum WidgetActivityState
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Widgets/Enums/WidgetDataState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

namespace CoreWidgetProvider.Widgets.Enums;

public enum WidgetDataState
{
Unknown,
Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Widgets/Enums/WidgetPageState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

namespace CoreWidgetProvider.Widgets.Enums;

public enum WidgetPageState
{
Unknown,
Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Widgets/IWidgetImplFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Windows.Widgets.Providers;

namespace CoreWidgetProvider.Widgets;

internal interface IWidgetImplFactory
{
public WidgetImpl Create(WidgetContext widgetContext, string state);
Expand Down
6 changes: 3 additions & 3 deletions CoreWidgetProvider/Widgets/SSHWalletWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class SSHWalletWidget : CoreWidget
{
private static readonly string DefaultConfigFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\.ssh\\config";

private static readonly Regex HostRegex = new (@"^Host\s+(\S*)\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);
private static readonly Regex HostRegex = new(@"^Host\s+(\S*)\s*$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline);

private FileSystemWatcher? FileWatcher { get; set; }

Expand Down Expand Up @@ -212,7 +212,7 @@ private void SetupFileWatcher()
var configFileDir = Path.GetDirectoryName(ConfigFile);
var configFileName = Path.GetFileName(ConfigFile);

if (configFileDir != null && configFileName != null )
if (configFileDir != null && configFileName != null)
{
FileWatcher = new FileSystemWatcher(configFileDir, configFileName);

Expand Down Expand Up @@ -341,7 +341,7 @@ public override void UpdateActivityState()

public override void UpdateWidget()
{
WidgetUpdateRequestOptions updateOptions = new (Id)
WidgetUpdateRequestOptions updateOptions = new(Id)
{
Data = GetData(Page),
Template = GetTemplateForPage(Page),
Expand Down
5 changes: 3 additions & 2 deletions CoreWidgetProvider/Widgets/SystemCPUUsageWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
using Microsoft.Windows.Widgets.Providers;

namespace CoreWidgetProvider.Widgets;

internal sealed class SystemCPUUsageWidget : CoreWidget, IDisposable
{
private static Dictionary<string, string> Templates { get; set; } = new ();
private static Dictionary<string, string> Templates { get; set; } = new();

private static readonly new string Name = nameof(SystemCPUUsageWidget);

Expand All @@ -19,7 +20,7 @@ internal sealed class SystemCPUUsageWidget : CoreWidget, IDisposable
public SystemCPUUsageWidget()
: base()
{
dataManager = new (DataType.CPU, UpdateWidget);
dataManager = new(DataType.CPU, UpdateWidget);
}

private string SpeedToString(float cpuSpeed)
Expand Down
6 changes: 3 additions & 3 deletions CoreWidgetProvider/Widgets/SystemGPUUsageWidget.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics;
using System.Globalization;
using System.Text.Json.Nodes;
using CoreWidgetProvider.Helpers;
using CoreWidgetProvider.Widgets.Enums;
using Microsoft.Windows.Widgets.Providers;

namespace CoreWidgetProvider.Widgets;

internal sealed class SystemGPUUsageWidget : CoreWidget, IDisposable
{
private static Dictionary<string, string> Templates { get; set; } = new ();
private static Dictionary<string, string> Templates { get; set; } = new();

private static readonly new string Name = nameof(SystemGPUUsageWidget);

Expand All @@ -24,7 +24,7 @@ internal sealed class SystemGPUUsageWidget : CoreWidget, IDisposable
public SystemGPUUsageWidget()
: base()
{
dataManager = new (DataType.GPU, UpdateWidget);
dataManager = new(DataType.GPU, UpdateWidget);
}

private string SpeedToString(float cpuSpeed)
Expand Down
4 changes: 2 additions & 2 deletions CoreWidgetProvider/Widgets/SystemMemoryWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace CoreWidgetProvider.Widgets;

internal sealed class SystemMemoryWidget : CoreWidget, IDisposable
{
private static Dictionary<string, string> Templates { get; set; } = new ();
private static Dictionary<string, string> Templates { get; set; } = new();

private static readonly new string Name = nameof(SystemMemoryWidget);

Expand All @@ -19,7 +19,7 @@ internal sealed class SystemMemoryWidget : CoreWidget, IDisposable
public SystemMemoryWidget()
: base()
{
dataManager = new (DataType.Memory, UpdateWidget);
dataManager = new(DataType.Memory, UpdateWidget);
}

private string FloatToPercentString(float value)
Expand Down
5 changes: 3 additions & 2 deletions CoreWidgetProvider/Widgets/SystemNetworkUsageWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
using Microsoft.Windows.Widgets.Providers;

namespace CoreWidgetProvider.Widgets;

internal sealed class SystemNetworkUsageWidget : CoreWidget, IDisposable
{
private static Dictionary<string, string> Templates { get; set; } = new ();
private static Dictionary<string, string> Templates { get; set; } = new();

private int networkIndex;

Expand All @@ -21,7 +22,7 @@ internal sealed class SystemNetworkUsageWidget : CoreWidget, IDisposable
public SystemNetworkUsageWidget()
: base()
{
dataManager = new (DataType.Network, UpdateWidget);
dataManager = new(DataType.Network, UpdateWidget);
}

private string SpeedToString(float cpuSpeed)
Expand Down
1 change: 1 addition & 0 deletions CoreWidgetProvider/Widgets/WidgetImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Windows.Widgets.Providers;

namespace CoreWidgetProvider.Widgets;

public abstract class WidgetImpl
{
#pragma warning disable SA1310 // Field names should not contain underscore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Windows.Widgets.Providers;

namespace CoreWidgetProvider.Widgets;

internal sealed class WidgetImplFactory<T> : IWidgetImplFactory
where T : WidgetImpl, new()
{
Expand Down
4 changes: 2 additions & 2 deletions CoreWidgetProvider/Widgets/WidgetProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace CoreWidgetProvider.Widgets;
[Guid("F8B2DBB9-3687-4C6E-99B2-B92C82905937")]
internal sealed class WidgetProvider : IWidgetProvider, IWidgetProvider2
{
private readonly Dictionary<string, IWidgetImplFactory> widgetDefinitionRegistry = new ();
private readonly Dictionary<string, WidgetImpl> runningWidgets = new ();
private readonly Dictionary<string, IWidgetImplFactory> widgetDefinitionRegistry = new();
private readonly Dictionary<string, WidgetImpl> runningWidgets = new();

public WidgetProvider()
{
Expand Down
3 changes: 2 additions & 1 deletion CoreWidgetProvider/Widgets/WidgetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
using Windows.Win32.System.Com;

namespace CoreWidgetProvider.Widgets;

public sealed class WidgetServer : IDisposable
{
private readonly HashSet<uint> registrationCookies = new ();
private readonly HashSet<uint> registrationCookies = new();

[UnconditionalSuppressMessage(
"ReflectionAnalysis",
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit e3250fa

Please sign in to comment.