Skip to content

Commit

Permalink
minor fix for CPUInfo and MemInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Nov 30, 2023
1 parent 1143676 commit 41cda3b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
6 changes: 1 addition & 5 deletions ProjBobcat/ProjBobcat/Class/Model/CPUInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
namespace ProjBobcat.Class.Model;

public readonly struct CPUInfo
{
public required double Usage { get; init; }
public required string Name { get; init; }
}
public record CPUInfo(double Usage, string Name);
12 changes: 5 additions & 7 deletions ProjBobcat/ProjBobcat/Class/Model/MemoryInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace ProjBobcat.Class.Model;

public readonly struct MemoryInfo
{
public required double Total { get; init; }
public required double Used { get; init; }
public required double Free { get; init; }
public required double Percentage { get; init; }
}
public record MemoryInfo(
double Total,
double Used,
double Free,
double Percentage);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GraphAuthResultModel

[JsonPropertyName("refresh_token")] public required string RefreshToken { get; init; }

[JsonPropertyName("id_token")] public string? IdToken { get; set; }
[JsonPropertyName("id_token")] public string? IdToken { get; init; }
}

[JsonSerializable(typeof(GraphAuthResultModel))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,7 @@ public static MemoryInfo GetWindowsMemoryStatus()
var used = total - free;
var percentage = MemUsagePercentageCounter.NextValue();

var result = new MemoryInfo
{
Free = free,
Percentage = percentage,
Total = total,
Used = used
};

return result;
return new MemoryInfo(total, used, free, percentage);
}

/// <summary>
Expand All @@ -234,12 +226,11 @@ public static MemoryInfo GetWindowsMemoryStatus()
public static CPUInfo GetWindowsCpuUsage()
{
var percentage = CpuCounter.NextValue();
var val = percentage > 100 ? 100 : percentage;

return new CPUInfo
{
Name = "Total %",
Usage = percentage > 100 ? 100 : percentage
};
const string name = "Total %";

return new CPUInfo(val, name);
}

public static IEnumerable<string> GetLogicalDrives()
Expand Down

0 comments on commit 41cda3b

Please sign in to comment.