Skip to content

Commit

Permalink
Merge pull request #2181 from microsoft/staging
Browse files Browse the repository at this point in the history
Release - 1/25/24
  • Loading branch information
EricJohnson327 authored Jan 25, 2024
2 parents 8f49970 + 1587b5b commit d1c3a49
Show file tree
Hide file tree
Showing 156 changed files with 1,391 additions and 858 deletions.
3 changes: 0 additions & 3 deletions .github/policies/scheduledSearch.closeNoRecentActivity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ configuration:
* Issue is Open
* Issue has the label Needs-Author-Feedback
* Issue has the label Status-No recent activity
* Issue does not have the label Issue-Feature
* Has not had activity in the last 5 days
Then -
* Close the Issue
Expand All @@ -27,8 +26,6 @@ configuration:
label: Needs-Author-Feedback
- hasLabel:
label: Status-No recent activity
- isNotLabeledWith:
label: Issue-Feature
- noActivitySince:
days: 5
actions:
Expand Down
3 changes: 0 additions & 3 deletions .github/policies/scheduledSearch.markNoRecentActivity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ configuration:
* Issue is Open
* Issue has the label Needs-Author-Feedback
* Issue does not have the label Status-No recent activity
* Issue does not have the label Issue-Feature
* Has not had activity in the last 5 days
Then -
* Mark the issue as Status-No recent activity
Expand All @@ -29,8 +28,6 @@ configuration:
days: 5
- isNotLabeledWith:
label: Status-No recent activity
- isNotLabeledWith:
label: Issue-Feature
actions:
- addLabel:
label: Status-No recent activity
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/DevHome-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
configuration: [Release, Debug]
platform: [x64, x86, arm64]
os: [windows-latest]
dotnet-version: ['6.0.x']
dotnet-version: ['8.0.x']
exclude:
- configuration: Debug
platform: x64
Expand Down Expand Up @@ -77,11 +77,11 @@ jobs:
- name: DevHome UnitTests
if: ${{ matrix.platform != 'arm64' }}
run: cmd /c "$env:VSDevTestCmd" /Platform:${{ matrix.platform }} test\\bin\\${{ matrix.platform }}\\${{ matrix.configuration }}\\net6.0-windows10.0.22000.0\\DevHome.Test.dll
run: cmd /c "$env:VSDevTestCmd" /Platform:${{ matrix.platform }} test\\bin\\${{ matrix.platform }}\\${{ matrix.configuration }}\\net8.0-windows10.0.22000.0\\DevHome.Test.dll

- name: Tools UnitTests
if: ${{ matrix.platform != 'arm64' }}
run: |
foreach ($UnitTestPath in (Get-ChildItem "tools\\*\\*UnitTest\\bin\\${{ matrix.platform }}\\${{ matrix.configuration }}\\net6.0-windows10.0.22000.0\\*.UnitTest.dll")) {
foreach ($UnitTestPath in (Get-ChildItem "tools\\*\\*UnitTest\\bin\\${{ matrix.platform }}\\${{ matrix.configuration }}\\net8.0-windows10.0.22000.0\\*.UnitTest.dll")) {
cmd /c "$env:VSDevTestCmd" /Platform:${{ matrix.platform }} $UnitTestPath.FullName
}
6 changes: 3 additions & 3 deletions CoreWidgetProvider/CoreWidgetProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.206-beta">
<PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="7.0.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
11 changes: 8 additions & 3 deletions CoreWidgetProvider/Helpers/CPUStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace CoreWidgetProvider.Helpers;

internal class CPUStats : IDisposable
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 ();

internal class ProcessStats
internal sealed class ProcessStats
{
public Process? Process { get; set; }

Expand All @@ -31,7 +31,12 @@ internal class ProcessStats
public CPUStats()
{
CpuUsage = 0;
ProcessCPUStats = new ProcessStats[3] { new ProcessStats(), new ProcessStats(), new ProcessStats() };
ProcessCPUStats =
[
new ProcessStats(),
new ProcessStats(),
new ProcessStats()
];

InitCPUPerfCounters();
}
Expand Down
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/ChartHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CoreWidgetProvider.Helpers;

internal class ChartHelper
internal sealed class ChartHelper
{
public enum ChartType
{
Expand Down
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace CoreWidgetProvider.Helpers;

internal class DataManager : IDisposable
internal sealed class DataManager : IDisposable
{
private readonly SystemData systemData;
private readonly DataType dataType;
Expand Down
11 changes: 6 additions & 5 deletions CoreWidgetProvider/Helpers/GPUStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

namespace CoreWidgetProvider.Helpers;

internal class GPUStats : IDisposable
internal sealed class GPUStats : IDisposable
{
// GPU counters
private readonly Dictionary<int, List<PerformanceCounter>> gpuCounters = new ();

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

public class Data
public sealed class Data
{
public string? Name { get; set; }

Expand Down Expand Up @@ -79,12 +79,13 @@ public void GetGPUPerfCounters()
continue;
}

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

gpuCounters[phys].Add(counter);
value.Add(counter);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions CoreWidgetProvider/Helpers/IconLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ public class IconLoader
public static string GetIconAsBase64(string filename)
{
Log.Logger()?.ReportDebug(nameof(IconLoader), $"Asking for icon: {filename}");
if (!Base64ImageRegistry.ContainsKey(filename))
if (!Base64ImageRegistry.TryGetValue(filename, out var value))
{
Base64ImageRegistry.Add(filename, ConvertIconToDataString(filename));
value = ConvertIconToDataString(filename);
Base64ImageRegistry.Add(filename, value);
Log.Logger()?.ReportDebug(nameof(IconLoader), $"The icon {filename} was converted and is now stored.");
}

return Base64ImageRegistry[filename];
return value;
}

private static string ConvertIconToDataString(string fileName)
Expand Down
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/MemoryStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace CoreWidgetProvider.Helpers;

internal class MemoryStats : IDisposable
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);
Expand Down
8 changes: 4 additions & 4 deletions CoreWidgetProvider/Helpers/NetworkStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace CoreWidgetProvider.Helpers;

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

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

private Dictionary<string, List<float>> NetChartValues { get; set; } = new Dictionary<string, List<float>>();

public class Data
public sealed class Data
{
public float Usage
{
Expand Down Expand Up @@ -114,12 +114,12 @@ public Data GetNetworkUsage(int networkIndex)
}

var currNetworkName = NetChartValues.ElementAt(networkIndex).Key;
if (!NetworkUsages.ContainsKey(currNetworkName))
if (!NetworkUsages.TryGetValue(currNetworkName, out var value))
{
return new Data();
}

return NetworkUsages[currNetworkName];
return value;
}

public int GetPrevNetworkIndex(int networkIndex)
Expand Down
6 changes: 3 additions & 3 deletions CoreWidgetProvider/Helpers/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static string ReplaceIdentifers(string str, string[] resourceIdentifiers,
// These are all the string identifiers that appear in widgets.
public static string[] GetWidgetResourceIdentifiers()
{
return new string[]
{
return
[
"Widget_Template/Loading",
"Widget_Template_Tooltip/Submit",
"SSH_Widget_Template/Name",
Expand Down Expand Up @@ -89,6 +89,6 @@ public static string[] GetWidgetResourceIdentifiers()
"CPUUsage_Widget_Template/End_Process",
"Widget_Template_Button/Save",
"Widget_Template_Button/Cancel",
};
];
}
}
2 changes: 1 addition & 1 deletion CoreWidgetProvider/Helpers/SystemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CoreWidgetProvider.Helpers;

internal class SystemData : IDisposable
internal sealed class SystemData : IDisposable
{
public static MemoryStats MemStats { get; set; } = new MemoryStats();

Expand Down
4 changes: 2 additions & 2 deletions CoreWidgetProvider/Widgets/CoreWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public virtual string GetData(WidgetPageState page)

protected string GetTemplateForPage(WidgetPageState page)
{
if (Template.ContainsKey(page))
if (Template.TryGetValue(page, out var value))
{
Log.Logger()?.ReportDebug(Name, ShortId, $"Using cached template for {page}");
return Template[page];
return value;
}

try
Expand Down
30 changes: 17 additions & 13 deletions CoreWidgetProvider/Widgets/SSHWalletWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

namespace CoreWidgetProvider.Widgets;

internal class SSHWalletWidget : CoreWidget
internal sealed class SSHWalletWidget : CoreWidget
{
protected static readonly string DefaultConfigFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\.ssh\\config";
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 FileSystemWatcher? FileWatcher { get; set; }

protected static readonly new string Name = nameof(SSHWalletWidget);
private static readonly new string Name = nameof(SSHWalletWidget);

protected string ConfigFile
private string ConfigFile
{
get => State();

Expand All @@ -48,7 +48,7 @@ public override void LoadContentData()
// Widget will remain in configuring state, waiting for config file path input.
if (string.IsNullOrWhiteSpace(ConfigFile))
{
ContentData = new JsonObject { { "configuring", true } }.ToJsonString();
ContentData = EmptyJson;
DataState = WidgetDataState.Okay;
return;
}
Expand Down Expand Up @@ -86,6 +86,11 @@ public override void LoadContentData()
catch (Exception e)
{
Log.Logger()?.ReportError(Name, ShortId, "Error retrieving data.", e);
var content = new JsonObject
{
{ "errorMessage", e.Message },
};
ContentData = content.ToJsonString();
DataState = WidgetDataState.Failed;
return;
}
Expand Down Expand Up @@ -246,7 +251,7 @@ private void OnConfigFileRenamed(object sender, FileSystemEventArgs e)
UpdateWidget();
}

private JsonObject FillConfigurationData(bool hasConfiguration, string configFile, int numOfEntries = 0, bool configuring = true, string errorMessage = "")
private JsonObject FillConfigurationData(bool hasConfiguration, string configFile, int numOfEntries = 0, string errorMessage = "")
{
var configurationData = new JsonObject();

Expand All @@ -265,7 +270,6 @@ private JsonObject FillConfigurationData(bool hasConfiguration, string configFil
{ "numOfEntries", numOfEntries.ToString(CultureInfo.InvariantCulture) },
};

configurationData.Add("configuring", configuring);
configurationData.Add("hasConfiguration", hasConfiguration);
configurationData.Add("configuration", sshConfigData);
configurationData.Add("savedConfigFile", _savedConfigFile);
Expand Down Expand Up @@ -298,18 +302,18 @@ public override string GetConfiguration(string data)

var numberOfEntries = GetNumberOfHostEntries();

configurationData = FillConfigurationData(true, ConfigFile, numberOfEntries, false);
configurationData = FillConfigurationData(true, ConfigFile, numberOfEntries);
}
else
{
configurationData = FillConfigurationData(false, data, 0, true, Resources.GetResource(@"SSH_Widget_Template/ConfigFileNotFound", Logger()));
configurationData = FillConfigurationData(false, data, 0, Resources.GetResource(@"SSH_Widget_Template/ConfigFileNotFound", Logger()));
}
}
catch (Exception ex)
{
Log.Logger()?.ReportError(Name, ShortId, $"Failed getting configuration information for input config file path: {data}", ex);

configurationData = FillConfigurationData(false, data, 0, true, Resources.GetResource(@"SSH_Widget_Template/ErrorProcessingConfigFile", Logger()));
configurationData = FillConfigurationData(false, data, 0, Resources.GetResource(@"SSH_Widget_Template/ErrorProcessingConfigFile", Logger()));

return configurationData.ToString();
}
Expand Down Expand Up @@ -365,7 +369,7 @@ public override string GetData(WidgetPageState page)
{
WidgetPageState.Configure => GetConfiguration(ConfigFile),
WidgetPageState.Content => ContentData,
WidgetPageState.Loading => new JsonObject { { "configuring", true } }.ToJsonString(),
WidgetPageState.Loading => EmptyJson,

// In case of unknown state default to empty data
_ => EmptyJson,
Expand Down Expand Up @@ -401,7 +405,7 @@ private void SetConfigure()
}
}

internal class DataPayload
internal sealed class DataPayload
{
public string? ConfigFile
{
Expand All @@ -411,6 +415,6 @@ public string? ConfigFile

[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(DataPayload))]
internal partial class SourceGenerationContext : JsonSerializerContext
internal sealed partial class SourceGenerationContext : JsonSerializerContext
{
}
9 changes: 7 additions & 2 deletions CoreWidgetProvider/Widgets/SystemCPUUsageWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
using Microsoft.Windows.Widgets.Providers;

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

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

private readonly DataManager dataManager;

Expand Down Expand Up @@ -58,6 +58,11 @@ public override void LoadContentData()
catch (Exception e)
{
Log.Logger()?.ReportError(Name, ShortId, "Error retrieving stats.", e);
var content = new JsonObject
{
{ "errorMessage", e.Message },
};
ContentData = content.ToJsonString();
DataState = WidgetDataState.Failed;
return;
}
Expand Down
Loading

0 comments on commit d1c3a49

Please sign in to comment.