using System; using System.ServiceProcess; namespace PCMonitor { /// /// Windows Service Wrapper /// Mengubah AgentService menjadi Windows Service /// public class ServiceWrapper : ServiceBase { private readonly AgentService agentService; private readonly ILog logger = new FileLogger(); public ServiceWrapper(AgentService service) { agentService = service; ServiceName = "PCMonitorAgent"; // DisplayName is set via ServiceInstaller, not here in .NET CanStop = true; CanPauseAndContinue = false; AutoLog = false; } protected override void OnStart(string[] args) { try { logger.Info("Windows Service starting..."); agentService.Start(); logger.Info("Windows Service started successfully"); } catch (Exception ex) { logger.Error($"Error starting Windows Service: {ex.Message}"); throw; } } protected override void OnStop() { try { logger.Info("Windows Service stopping..."); agentService.Stop(); logger.Info("Windows Service stopped successfully"); } catch (Exception ex) { logger.Error($"Error stopping Windows Service: {ex.Message}"); } } } }