Files
VNCServerList/Services/VNCService.cs
2025-07-07 17:05:06 +09:00

69 lines
2.0 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using VNCServerList.Models;
namespace VNCServerList.Services
{
public class VNCService
{
private readonly string _vncViewerPath;
private readonly DatabaseService _databaseService;
public VNCService(DatabaseService databaseService)
{
_vncViewerPath = @"C:\Program Files\TightVNC\tvnviewer.exe";
_databaseService = databaseService;
}
public bool ConnectToServer(VNCServer server)
{
try
{
if (!File.Exists(_vncViewerPath))
{
throw new FileNotFoundException($"VNC Viewer를 찾을 수 없습니다: {_vncViewerPath}");
}
// VNC Viewer 실행
var startInfo = new ProcessStartInfo
{
FileName = _vncViewerPath,
Arguments = $"-host={server.IP} {server.Argument}",
UseShellExecute = true
};
Process.Start(startInfo);
// 연결 성공 (마지막 연결 시간 업데이트는 현재 테이블 구조에 없으므로 제거)
return true;
}
catch (Exception ex)
{
throw new Exception($"VNC 연결 중 오류가 발생했습니다: {ex.Message}", ex);
}
}
public bool ConnectToServer(string user, string ip)
{
var server = _databaseService.GetServerByUserAndIP(user, ip);
if (server == null)
{
throw new ArgumentException($"서버 {user}@{ip}를 찾을 수 없습니다.");
}
return ConnectToServer(server);
}
public bool IsVNCViewerInstalled()
{
return File.Exists(_vncViewerPath);
}
public string GetVNCViewerPath()
{
return _vncViewerPath;
}
}
}