# ThreadPilot API Reference ## Core Interfaces ### ISystemService Base interface for all system services providing lifecycle management. ```csharp public interface ISystemService { bool IsAvailable { get; } event EventHandler? AvailabilityChanged; Task InitializeAsync(); Task DisposeAsync(); } ``` **Key Methods:** - `InitializeAsync()`: Initialize service resources - `DisposeAsync()`: Clean up service resources - `IsAvailable`: Indicates if service is operational ### IRepository Generic repository interface for data access operations. ```csharp public interface IRepository : IRepository where T : class { Task GetByIdAsync(string id); Task> GetAllAsync(); Task> FindAsync(Expression> predicate); Task AddAsync(T entity); Task UpdateAsync(T entity); Task DeleteAsync(string id); Task ExistsAsync(string id); Task CountAsync(); } ``` ## Core Services ### IProcessService Manages process enumeration and manipulation. ```csharp public interface IProcessService { Task> GetRunningProcessesAsync(); Task SetProcessPriorityAsync(int processId, ProcessPriorityClass priority); Task SetProcessAffinityAsync(int processId, long affinityMask); Task GetProcessByIdAsync(int processId); bool IsProcessRunning(string processName); } ``` **Key Features:** - Async process enumeration - Priority and affinity management - Process existence checking ### IPowerPlanService Manages Windows power plans. ```csharp public interface IPowerPlanService { Task> GetAvailablePowerPlansAsync(); Task GetActivePowerPlanAsync(); Task SetActivePowerPlanAsync(string powerPlanGuid); Task GetPowerPlanByGuidAsync(string guid); event EventHandler? PowerPlanChanged; } ``` **Key Features:** - Power plan enumeration and activation - Change event notifications - GUID-based plan identification ### ICpuTopologyService Provides CPU topology detection and affinity management. ```csharp public interface ICpuTopologyService { Task DetectTopologyAsync(); Task SetProcessAffinityAsync(int processId, IEnumerable coreIds); Task GetProcessAffinityAsync(int processId); event EventHandler? TopologyDetected; } ``` **Key Features:** - Modern CPU architecture detection - Core affinity management - Support for hybrid architectures ## Business Logic Services ### IProcessMonitorManagerService Orchestrates process monitoring and power plan switching. ```csharp public interface IProcessMonitorManagerService { bool IsMonitoringActive { get; } Task StartMonitoringAsync(); Task StopMonitoringAsync(); event EventHandler? ProcessStarted; event EventHandler? ProcessStopped; event EventHandler? MonitoringStarted; event EventHandler? MonitoringStopped; } ``` **Key Features:** - WMI-based process monitoring - Automatic power plan switching - Fallback polling mechanism ### IGameBoostService Manages game detection and performance optimization. ```csharp public interface IGameBoostService { bool IsGameBoostActive { get; } string? CurrentGameName { get; } Task ActivateGameBoostAsync(ProcessModel gameProcess); Task DeactivateGameBoostAsync(); Task AddKnownGameAsync(string executableName); Task RemoveKnownGameAsync(string executableName); event EventHandler? GameBoostActivated; event EventHandler? GameBoostDeactivated; } ``` **Key Features:** - Automatic game detection - Performance optimization - Configurable game database ## Application Services ### IApplicationSettingsService Manages application configuration and persistence. ```csharp public interface IApplicationSettingsService { ApplicationSettingsModel Settings { get; } Task LoadSettingsAsync(); Task SaveSettingsAsync(); Task ResetToDefaultsAsync(); Task ExportSettingsAsync(string filePath); Task ImportSettingsAsync(string filePath); event EventHandler? SettingsChanged; } ``` **Key Features:** - Automatic settings persistence - Import/export functionality - Change notifications ### INotificationService Handles user notifications and system tray integration. ```csharp public interface INotificationService { Task ShowNotificationAsync(string title, string message, NotificationType type); Task ShowBalloonNotificationAsync(string title, string message, int duration); Task ShowToastNotificationAsync(string title, string message); Task ClearAllNotificationsAsync(); } ``` **Key Features:** - Multiple notification types - System tray balloon tips - Windows toast notifications ### IEnhancedLoggingService Provides structured logging with file persistence. ```csharp public interface IEnhancedLoggingService { Task LogPowerPlanChangeAsync(string fromPlan, string toPlan, string reason); Task LogProcessEventAsync(string processName, string eventType, string details); Task LogGameBoostEventAsync(string gameName, string action, string details); Task LogUserActionAsync(string action, string details, string? context = null); Task LogErrorAsync(string source, string error, string? stackTrace = null); Task> GetLogEntriesAsync(DateTime? fromDate = null, DateTime? toDate = null); } ``` **Key Features:** - Structured event logging - File rotation and management - Query capabilities ## Data Models ### ProcessModel Represents a system process with extended information. ```csharp public partial class ProcessModel : ObservableObject { public int ProcessId { get; set; } public string Name { get; set; } public string ExecutablePath { get; set; } public ProcessPriorityClass Priority { get; set; } public long ProcessorAffinity { get; set; } public double CpuUsage { get; set; } public long WorkingSet { get; set; } } ``` ### PowerPlanModel Represents a Windows power plan. ```csharp public partial class PowerPlanModel : ObservableObject { public string Guid { get; set; } public string Name { get; set; } public string Description { get; set; } public bool IsActive { get; set; } } ``` ### CpuTopologyModel Represents CPU topology information. ```csharp public partial class CpuTopologyModel : ObservableObject { public int TotalCores { get; set; } public int PhysicalCores { get; set; } public int LogicalCores { get; set; } public bool HasHybridArchitecture { get; set; } public ObservableCollection Cores { get; set; } } ``` ## Event Arguments ### ProcessEventArgs Provides data for process-related events. ```csharp public class ProcessEventArgs : EventArgs { public ProcessModel Process { get; } public DateTime Timestamp { get; } public string EventType { get; } } ``` ### PowerPlanChangedEventArgs Provides data for power plan change events. ```csharp public class PowerPlanChangedEventArgs : EventArgs { public PowerPlanModel? PreviousPlan { get; } public PowerPlanModel CurrentPlan { get; } public string Reason { get; } public DateTime Timestamp { get; } } ``` ### GameBoostEventArgs Provides data for game boost events. ```csharp public class GameBoostEventArgs : EventArgs { public ProcessModel? GameProcess { get; } public bool IsActivated { get; } public DateTime Timestamp { get; } } ``` ## Configuration Enums ### NotificationType Defines notification types for the notification service. ```csharp public enum NotificationType { Information, Warning, Error, Success } ``` ### ProcessPriorityClass Standard .NET process priority enumeration. ```csharp public enum ProcessPriorityClass { Idle, BelowNormal, Normal, AboveNormal, High, RealTime } ``` This API reference provides comprehensive documentation for all public interfaces and key classes in ThreadPilot.