e3530e5342
Introduces new models, services, and view models for process monitoring, power plan association, application settings, and enhanced logging. Updates main application files and views to support new features. Adds developer and architecture documentation.
128 lines
4.0 KiB
C#
128 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using ThreadPilot.Models.Core;
|
|
|
|
namespace ThreadPilot.Models
|
|
{
|
|
/// <summary>
|
|
/// Represents an association between an executable and a power plan
|
|
/// </summary>
|
|
public partial class ProcessPowerPlanAssociation : ObservableObject, IModel
|
|
{
|
|
[ObservableProperty]
|
|
private string id = Guid.NewGuid().ToString();
|
|
|
|
[ObservableProperty]
|
|
private string executableName = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string executablePath = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string powerPlanGuid = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private string powerPlanName = string.Empty;
|
|
|
|
[ObservableProperty]
|
|
private bool isEnabled = true;
|
|
|
|
[ObservableProperty]
|
|
private DateTime createdAt = DateTime.UtcNow;
|
|
|
|
[ObservableProperty]
|
|
private DateTime updatedAt = DateTime.UtcNow;
|
|
|
|
// IModel implementation - properties are auto-generated by ObservableProperty
|
|
|
|
[ObservableProperty]
|
|
private string description = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Whether to match by exact executable name or path
|
|
/// </summary>
|
|
[ObservableProperty]
|
|
private bool matchByPath = false;
|
|
|
|
/// <summary>
|
|
/// Priority for this association (higher number = higher priority)
|
|
/// Used when multiple associations could match the same process
|
|
/// </summary>
|
|
[ObservableProperty]
|
|
private int priority = 0;
|
|
|
|
public ProcessPowerPlanAssociation()
|
|
{
|
|
}
|
|
|
|
public ProcessPowerPlanAssociation(string executableName, string powerPlanGuid, string powerPlanName)
|
|
{
|
|
ExecutableName = executableName;
|
|
PowerPlanGuid = powerPlanGuid;
|
|
PowerPlanName = powerPlanName;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if this association matches the given process
|
|
/// </summary>
|
|
public bool MatchesProcess(ProcessModel process)
|
|
{
|
|
if (!IsEnabled) return false;
|
|
|
|
if (MatchByPath && !string.IsNullOrEmpty(ExecutablePath))
|
|
{
|
|
return string.Equals(process.ExecutablePath, ExecutablePath, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
else
|
|
{
|
|
return string.Equals(process.Name, ExecutableName, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if this association matches the given executable name
|
|
/// </summary>
|
|
public bool MatchesExecutable(string executableName)
|
|
{
|
|
if (!IsEnabled) return false;
|
|
return string.Equals(ExecutableName, executableName, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
|
|
|
|
public ValidationResult Validate()
|
|
{
|
|
var errors = new List<string>();
|
|
|
|
if (string.IsNullOrWhiteSpace(ExecutableName))
|
|
errors.Add("Executable name is required");
|
|
|
|
if (string.IsNullOrWhiteSpace(PowerPlanGuid))
|
|
errors.Add("Power plan GUID is required");
|
|
|
|
if (string.IsNullOrWhiteSpace(PowerPlanName))
|
|
errors.Add("Power plan name is required");
|
|
|
|
return errors.Count == 0 ? ValidationResult.Success() : ValidationResult.Failure(errors.ToArray());
|
|
}
|
|
|
|
public IModel Clone()
|
|
{
|
|
return new ProcessPowerPlanAssociation
|
|
{
|
|
id = Guid.NewGuid().ToString(), // New ID for clone
|
|
ExecutableName = this.ExecutableName,
|
|
ExecutablePath = this.ExecutablePath,
|
|
PowerPlanGuid = this.PowerPlanGuid,
|
|
PowerPlanName = this.PowerPlanName,
|
|
IsEnabled = this.IsEnabled,
|
|
Description = this.Description,
|
|
MatchByPath = this.MatchByPath,
|
|
createdAt = DateTime.UtcNow,
|
|
updatedAt = DateTime.UtcNow
|
|
};
|
|
}
|
|
}
|
|
}
|