Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 019781b2f4 | |||
| 5bb26c1c3f |
@@ -17,7 +17,7 @@ internal static class Data
|
|||||||
|
|
||||||
internal static ObservableCollection<SensorEntry> SensorEntries { get; set; } = [];
|
internal static ObservableCollection<SensorEntry> SensorEntries { get; set; } = [];
|
||||||
|
|
||||||
internal static async Task LoadComputer()
|
private static async Task LoadComputer()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -30,8 +30,11 @@ internal static class Data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void RefreshComputer()
|
internal static async Task RefreshComputer()
|
||||||
{
|
{
|
||||||
|
if (_pipeClient is not { State: PipeState.Connected })
|
||||||
|
await LoadComputer();
|
||||||
|
|
||||||
_hardware = _pipeClient.InvokeAsync(service => service.GetHardware()).Result;
|
_hardware = _pipeClient.InvokeAsync(service => service.GetHardware()).Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using System;
|
using HardwareMonitorStatusWindow.Service;
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using HardwareMonitorStatusWindow.Service;
|
|
||||||
|
|
||||||
namespace HardwareMonitorStatusWindow.StatusWindow;
|
namespace HardwareMonitorStatusWindow.StatusWindow;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
|||||||
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
|
_dataErrorDictionary.ErrorsChanged += DataErrorDictionaryErrorsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? Label
|
public string Label
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set
|
set
|
||||||
@@ -28,7 +28,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
|||||||
|
|
||||||
SetField(ref field, value);
|
SetField(ref field, value);
|
||||||
}
|
}
|
||||||
}
|
} = string.Empty;
|
||||||
|
|
||||||
public string? HardwareId
|
public string? HardwareId
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Hardware? Hardware => Data.ComputerHardware?.FirstOrDefault(h => h.Identifier.ToString() == HardwareId);
|
public Hardware? Hardware => Data.ComputerHardware.FirstOrDefault(h => h.Identifier.ToString() == HardwareId);
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Sensor? Sensor => Hardware?.Sensors.FirstOrDefault(s => s.Identifier.ToString() == SensorId);
|
public Sensor? Sensor => Hardware?.Sensors.FirstOrDefault(s => s.Identifier.ToString() == SensorId);
|
||||||
@@ -88,17 +88,16 @@ public class SensorEntry : INotifyDataErrorInfo, INotifyPropertyChanged
|
|||||||
|
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
private void SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||||
{
|
{
|
||||||
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
if (EqualityComparer<T>.Default.Equals(field, value)) return;
|
||||||
field = value;
|
field = value;
|
||||||
OnPropertyChanged(propertyName);
|
OnPropertyChanged(propertyName);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public string SensorValueFormat
|
public string SensorValueFormat
|
||||||
|
|||||||
@@ -67,13 +67,13 @@ public partial class HardwareSettingsPanel
|
|||||||
EditSelectedSensor();
|
EditSelectedSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddSensor()
|
private async void AddSensor()
|
||||||
{
|
{
|
||||||
var sensorEntry = new SensorEntry();
|
var sensorEntry = new SensorEntry();
|
||||||
|
|
||||||
var sensorWindow = new SensorWindow();
|
var sensorWindow = new SensorWindow();
|
||||||
|
|
||||||
var result = sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
var result = await sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
||||||
|
|
||||||
if (!result.HasValue || !result.Value)
|
if (!result.HasValue || !result.Value)
|
||||||
return;
|
return;
|
||||||
@@ -83,7 +83,7 @@ public partial class HardwareSettingsPanel
|
|||||||
SetSensorButtonStates();
|
SetSensorButtonStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EditSelectedSensor()
|
private async void EditSelectedSensor()
|
||||||
{
|
{
|
||||||
if (SensorDataGrid.SelectedItem == null)
|
if (SensorDataGrid.SelectedItem == null)
|
||||||
return;
|
return;
|
||||||
@@ -92,7 +92,7 @@ public partial class HardwareSettingsPanel
|
|||||||
|
|
||||||
var sensorWindow = new SensorWindow();
|
var sensorWindow = new SensorWindow();
|
||||||
|
|
||||||
sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
await sensorWindow.Display(sensorEntry, Window.GetWindow(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DeleteSelectedSensors()
|
private void DeleteSelectedSensors()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using ChrisKaczor.Wpf.Validation;
|
using ChrisKaczor.Wpf.Validation;
|
||||||
using HardwareMonitorStatusWindow.Service;
|
using HardwareMonitorStatusWindow.Service;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
@@ -17,11 +18,11 @@ public partial class SensorWindow
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool? Display(SensorEntry sensorEntry, Window? owner)
|
public async Task<bool?> Display(SensorEntry sensorEntry, Window? owner)
|
||||||
{
|
{
|
||||||
DataContext = sensorEntry;
|
DataContext = sensorEntry;
|
||||||
|
|
||||||
Data.RefreshComputer();
|
await Data.RefreshComputer();
|
||||||
|
|
||||||
HardwareTypeComboBox.ItemsSource = Data.ComputerHardware.Where(h => h.Sensors.Any()).DistinctBy(h => h.Type).Select(s => new HardwareTypeItem(s.Type)).OrderBy(s => s.Name);
|
HardwareTypeComboBox.ItemsSource = Data.ComputerHardware.Where(h => h.Sensors.Any()).DistinctBy(h => h.Type).Select(s => new HardwareTypeItem(s.Type)).OrderBy(s => s.Name);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<PackageReference Include="ChrisKaczor.Wpf.Controls.Link" Version="1.0.4" />
|
<PackageReference Include="ChrisKaczor.Wpf.Controls.Link" Version="1.0.4" />
|
||||||
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.4" />
|
<PackageReference Include="ChrisKaczor.Wpf.Validation" Version="1.0.4" />
|
||||||
<PackageReference Include="ChrisKaczor.Wpf.Windows.CategoryWindow" Version="1.0.2" />
|
<PackageReference Include="ChrisKaczor.Wpf.Windows.CategoryWindow" Version="1.0.2" />
|
||||||
<PackageReference Include="ChrisKaczor.Wpf.Windows.FloatingStatusWindow" Version="2.0.0.8" />
|
<PackageReference Include="ChrisKaczor.Wpf.Windows.FloatingStatusWindow" Version="2.0.0.9" />
|
||||||
<PackageReference Include="gong-wpf-dragdrop" Version="4.0.0" />
|
<PackageReference Include="gong-wpf-dragdrop" Version="4.0.0" />
|
||||||
<PackageReference Include="PipeMethodCalls" Version="4.0.3" />
|
<PackageReference Include="PipeMethodCalls" Version="4.0.3" />
|
||||||
<PackageReference Include="Serilog" Version="4.3.1" />
|
<PackageReference Include="Serilog" Version="4.3.1" />
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -139,7 +140,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Start(bool hasUpdate)
|
private void Start(bool hasUpdate)
|
||||||
{
|
{
|
||||||
Log.Information("Start: hasUpdate={hasUpdate}", hasUpdate);
|
Log.Information("Start: hasUpdate={hasUpdate}", hasUpdate);
|
||||||
|
|
||||||
@@ -148,7 +149,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
|
|
||||||
Log.Information("Load");
|
Log.Information("Load");
|
||||||
|
|
||||||
await Load();
|
Load();
|
||||||
|
|
||||||
Log.Information("Starting timer");
|
Log.Information("Starting timer");
|
||||||
|
|
||||||
@@ -157,10 +158,8 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
_timer.Enabled = true;
|
_timer.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task Load()
|
private static void Load()
|
||||||
{
|
{
|
||||||
await Data.LoadComputer();
|
|
||||||
|
|
||||||
Data.Load();
|
Data.Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,19 +226,26 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
if (existingTask == null)
|
if (existingTask == null)
|
||||||
{
|
{
|
||||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotInstalled));
|
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotInstalled));
|
||||||
|
_timer.Start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingTask.State != TaskState.Running)
|
if (existingTask.State != TaskState.Running)
|
||||||
{
|
{
|
||||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotStarted));
|
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.ServiceNotStarted));
|
||||||
|
|
||||||
|
existingTask.Run();
|
||||||
|
_timer.Start();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var text = new StringBuilder();
|
var text = new StringBuilder();
|
||||||
|
|
||||||
Data.RefreshComputer();
|
Data.RefreshComputer().Wait();
|
||||||
|
|
||||||
|
var labelLength = Data.SensorEntries.Max(x => x.Label.Length);
|
||||||
|
|
||||||
foreach (var sensorEntry in Data.SensorEntries)
|
foreach (var sensorEntry in Data.SensorEntries)
|
||||||
{
|
{
|
||||||
@@ -249,7 +255,7 @@ internal class WindowSource : IWindowSource, IDisposable
|
|||||||
if (text.Length > 0)
|
if (text.Length > 0)
|
||||||
text.AppendLine();
|
text.AppendLine();
|
||||||
|
|
||||||
text.Append($"{sensorEntry.Label}: {string.Format(sensorEntry.SensorValueFormat, sensorEntry.Sensor.Value)}");
|
text.Append($"{sensorEntry.Label.PadLeft(labelLength)}: {string.Format(sensorEntry.SensorValueFormat, sensorEntry.Sensor.Value)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString()));
|
_dispatcher.Invoke(() => _floatingStatusWindow.SetText(text.ToString()));
|
||||||
|
|||||||
Reference in New Issue
Block a user