using System; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; using Agent.Views; using log4net; using Quartz; namespace Agent { /// /// MainWindow.xaml에 대한 상호 작용 논리 /// public partial class MainWindow : Window, IJobListener { private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow)); private readonly SolidColorBrush _activeButtonColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00B0F0")); string IJobListener.Name => "MainWindowJobListener"; public MainWindow() { InitializeComponent(); MainFrame.NavigationService.Navigated += NavigationService_Navigated; MainFrame.Source = new Uri("DashboardPage.xaml", UriKind.Relative); UpdateName(); UpdateStatus(); } private void NavigationService_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { MainFrame.NavigationService.RemoveBackEntry(); } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Hide(); InactiveButtons(); DashboardButton.Background = _activeButtonColor; MainFrame.Source = new Uri("DashboardPage.xaml", UriKind.Relative); e.Cancel = true; } private void DashboardButton_Click(object sender, RoutedEventArgs e) { InactiveButtons(); DashboardButton.Background = _activeButtonColor; MainFrame.Source = new Uri("DashboardPage.xaml", UriKind.Relative); } private void PolicyButton_Click(object sender, RoutedEventArgs e) { ActivePolicyMenu(); } private void RestoreButton_Click(object sender, RoutedEventArgs e) { InactiveButtons(); RestoreButton.Background = _activeButtonColor; MainFrame.Source = new Uri("RestorePage.xaml", UriKind.Relative); } private void ReportButton_Click(object sender, RoutedEventArgs e) { ActiveReportMenu(); } private void SettingButton_Click(object sender, RoutedEventArgs e) { InactiveButtons(); SettingButton.Background = _activeButtonColor; MainFrame.Source = new Uri("SettingPage.xaml", UriKind.Relative); } public void UpdateStatus() { if (!"OK".Equals(Application.Current.Properties["db_status"])) { SetTitleInactive(); return; } SetTitleActive(); } public void UpdateName() { var userName = Application.Current.Properties["user_name"]; if (!NameLabel.Content.Equals(userName)) { NameLabel.Content = userName; } } public void SetTitleActive() { var image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri("/Resources/check.png", UriKind.Relative); image.EndInit(); StatusImage.Source = image; StatusLabel.Content = "DI 에이전트가 정상 동작 중입니다."; } public void SetTitleInactive() { var image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri("/Resources/close.png", UriKind.Relative); image.EndInit(); StatusImage.Source = image; StatusLabel.Content = "DI 에이전트가 서버와의 연결을 실패하였습니다."; } private void InactiveButtons() { DashboardButton.Background = null; PolicyButton.Background = null; RestoreButton.Background = null; ReportButton.Background = null; SettingButton.Background = null; } public void ActivePolicyMenu() { InactiveButtons(); PolicyButton.Background = _activeButtonColor; MainFrame.Source = new Uri("PolicyPage.xaml", UriKind.Relative); } public void ActiveReportMenu() { InactiveButtons(); ReportButton.Background = _activeButtonColor; MainFrame.Source = new Uri("ReportPage.xaml", UriKind.Relative); } void IJobListener.JobToBeExecuted(IJobExecutionContext context) { } void IJobListener.JobExecutionVetoed(IJobExecutionContext context) { } void IJobListener.JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException) { Dispatcher.BeginInvoke(DispatcherPriority.Normal , new Action(delegate { UpdateStatus(); if ((MainFrame.Content is DashboardPage dashboardPage)) { dashboardPage.LoadStatus(); } })); } } }