JJServiceManager/Windows/ServiceRow.cs

74 lines
2.8 KiB
C#

using System.ServiceProcess;
using System.Windows;
using System.Windows.Media;
namespace JJServiceManager
{
/// <summary>초기화면 서비스 목록의 한 줄</summary>
public sealed class ServiceRow : ObservableObject
{
private bool _isChecked;
private ServiceControllerStatus? _status;
private bool _statusKnown;
private bool _isBusy;
public ServiceEntry Entry { get; }
public ServiceRow(ServiceEntry entry) => Entry = entry;
public string DisplayName => string.IsNullOrEmpty(Entry.DisplayName) ? Entry.ServiceName : Entry.DisplayName;
public string ServiceName => Entry.ServiceName;
public string ServiceNameText => string.Equals(Entry.DisplayName, Entry.ServiceName, System.StringComparison.OrdinalIgnoreCase) ? "" : $"({Entry.ServiceName})";
public string Tooltip => $"서비스명: {Entry.ServiceName}\n우클릭: 로그 경로 지정";
public bool IsChecked { get => _isChecked; set => Set(ref _isChecked, value); }
/// <summary>Start/Stop 진행 중이면 false</summary>
public bool IsIdle => !_isBusy;
public bool IsBusy
{
get => _isBusy;
set { if (Set(ref _isBusy, value)) OnPropertyChanged(nameof(IsIdle)); }
}
public ServiceControllerStatus? Status
{
get => _status;
set
{
if (_statusKnown && _status == value) return;
_status = value;
_statusKnown = true;
OnPropertyChanged();
OnPropertyChanged(nameof(StatusText));
OnPropertyChanged(nameof(StatusBrush));
}
}
public bool StatusKnown => _statusKnown;
public string StatusText => _statusKnown ? ServiceOps.StatusText(_status) : "확인 중…";
public Brush StatusBrush => !_statusKnown ? Brushes2.Unknown : _status switch
{
ServiceControllerStatus.Running => Brushes2.Running,
ServiceControllerStatus.Stopped => Brushes2.Stopped,
null => Brushes2.Unknown,
ServiceControllerStatus.Paused => Brushes2.Unknown,
_ => Brushes2.Pending
};
public string LogTooltip => string.IsNullOrWhiteSpace(Entry.LogPath)
? "로그 경로가 없습니다. 누르면 지정합니다. (우클릭: 변경)"
: (Entry.LogIsFolder ? "폴더(최신 파일): " : "파일: ") + Entry.LogPath + "\n우클릭: 변경";
public FontWeight LogFontWeight => string.IsNullOrWhiteSpace(Entry.LogPath) ? FontWeights.Normal : FontWeights.Bold;
public void LogPathChanged()
{
OnPropertyChanged(nameof(LogTooltip));
OnPropertyChanged(nameof(LogFontWeight));
}
}
}