using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Security.Principal;
using System.ServiceProcess;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using Forms = System.Windows.Forms;
namespace JJServiceManager
{
/// 초기화면
public sealed class MainWindow : Window
{
private static readonly TimeSpan OpTimeout = TimeSpan.FromSeconds(60);
private readonly AppSettings _settings;
private readonly ObservableCollection _rows = new ObservableCollection();
private readonly LogPanel _log;
private readonly LogWindowManager _logWindows;
private readonly DispatcherTimer _statusTimer;
private readonly ItemsControl _list;
private readonly CheckBox _chkAll;
private readonly TextBlock _txtCount, _txtEmpty, _txtLogHidden;
private readonly ContentControl _ccLog;
private readonly FrameworkElement _pnlShutdown;
private Forms.NotifyIcon _tray;
private HotkeyManager _hotkey;
private bool _exiting;
private bool _refreshing;
private bool _trayTipShown;
private bool _modalOpen;
public MainWindow(AppSettings settings)
{
_settings = settings;
Title = "JJServiceManager - 서비스 관리";
FontFamily = new FontFamily("Malgun Gothic");
FontSize = 13;
Background = Brushes2.Make("#F5F7F8");
MinWidth = 760;
MinHeight = 520;
AppIcon.Apply(this);
RestoreWindowBounds(settings);
var root = XamlLoader.LoadElement("MainWindow.xaml");
Content = root;
_list = root.Find("icServices");
_chkAll = root.Find("chkAll");
_txtCount = root.Find("txtCount");
_txtEmpty = root.Find("txtEmpty");
_txtLogHidden = root.Find("txtLogHidden");
_ccLog = root.Find("ccLog");
_pnlShutdown = root.Find("pnlShutdown");
_log = new LogPanel { ShowTimestamp = true };
_ccLog.Content = _log;
_logWindows = new LogWindowManager(() => _settings, SaveSettings);
foreach (var e in settings.Services) _rows.Add(new ServiceRow(e));
_list.ItemsSource = _rows;
_rows.CollectionChanged += (s, e) => UpdateCounts();
// 상단 버튼
root.Find