MainWindow.xaml.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. using System.Windows.Media.Imaging;
  5. using System.Windows.Threading;
  6. using Agent.Views;
  7. using log4net;
  8. using Quartz;
  9. namespace Agent
  10. {
  11. /// <summary>
  12. /// MainWindow.xaml에 대한 상호 작용 논리
  13. /// </summary>
  14. public partial class MainWindow : Window, IJobListener
  15. {
  16. private static readonly ILog log = LogManager.GetLogger(typeof(MainWindow));
  17. private readonly SolidColorBrush _activeButtonColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00B0F0"));
  18. string IJobListener.Name => "MainWindowJobListener";
  19. public MainWindow()
  20. {
  21. InitializeComponent();
  22. MainFrame.NavigationService.Navigated += NavigationService_Navigated;
  23. MainFrame.Source = new Uri("DashboardPage.xaml", UriKind.Relative);
  24. UpdateName();
  25. UpdateStatus();
  26. }
  27. private void NavigationService_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
  28. {
  29. MainFrame.NavigationService.RemoveBackEntry();
  30. }
  31. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  32. {
  33. Hide();
  34. InactiveButtons();
  35. DashboardButton.Background = _activeButtonColor;
  36. MainFrame.Source = new Uri("DashboardPage.xaml", UriKind.Relative);
  37. e.Cancel = true;
  38. }
  39. private void DashboardButton_Click(object sender, RoutedEventArgs e)
  40. {
  41. InactiveButtons();
  42. DashboardButton.Background = _activeButtonColor;
  43. MainFrame.Source = new Uri("DashboardPage.xaml", UriKind.Relative);
  44. }
  45. private void PolicyButton_Click(object sender, RoutedEventArgs e)
  46. {
  47. ActivePolicyMenu();
  48. }
  49. private void RestoreButton_Click(object sender, RoutedEventArgs e)
  50. {
  51. InactiveButtons();
  52. RestoreButton.Background = _activeButtonColor;
  53. MainFrame.Source = new Uri("RestorePage.xaml", UriKind.Relative);
  54. }
  55. private void ReportButton_Click(object sender, RoutedEventArgs e)
  56. {
  57. ActiveReportMenu();
  58. }
  59. private void SettingButton_Click(object sender, RoutedEventArgs e)
  60. {
  61. InactiveButtons();
  62. SettingButton.Background = _activeButtonColor;
  63. MainFrame.Source = new Uri("SettingPage.xaml", UriKind.Relative);
  64. }
  65. public void UpdateStatus()
  66. {
  67. if (!"OK".Equals(Application.Current.Properties["db_status"]))
  68. {
  69. SetTitleInactive();
  70. return;
  71. }
  72. SetTitleActive();
  73. }
  74. public void UpdateName()
  75. {
  76. var userName = Application.Current.Properties["user_name"];
  77. if (!NameLabel.Content.Equals(userName))
  78. {
  79. NameLabel.Content = userName;
  80. }
  81. }
  82. public void SetTitleActive()
  83. {
  84. var image = new BitmapImage();
  85. image.BeginInit();
  86. image.UriSource = new Uri("/Resources/check.png", UriKind.Relative);
  87. image.EndInit();
  88. StatusImage.Source = image;
  89. StatusLabel.Content = "DI 에이전트가 정상 동작 중입니다.";
  90. }
  91. public void SetTitleInactive()
  92. {
  93. var image = new BitmapImage();
  94. image.BeginInit();
  95. image.UriSource = new Uri("/Resources/close.png", UriKind.Relative);
  96. image.EndInit();
  97. StatusImage.Source = image;
  98. StatusLabel.Content = "DI 에이전트가 서버와의 연결을 실패하였습니다.";
  99. }
  100. private void InactiveButtons()
  101. {
  102. DashboardButton.Background = null;
  103. PolicyButton.Background = null;
  104. RestoreButton.Background = null;
  105. ReportButton.Background = null;
  106. SettingButton.Background = null;
  107. }
  108. public void ActivePolicyMenu()
  109. {
  110. InactiveButtons();
  111. PolicyButton.Background = _activeButtonColor;
  112. MainFrame.Source = new Uri("PolicyPage.xaml", UriKind.Relative);
  113. }
  114. public void ActiveReportMenu()
  115. {
  116. InactiveButtons();
  117. ReportButton.Background = _activeButtonColor;
  118. MainFrame.Source = new Uri("ReportPage.xaml", UriKind.Relative);
  119. }
  120. void IJobListener.JobToBeExecuted(IJobExecutionContext context)
  121. {
  122. }
  123. void IJobListener.JobExecutionVetoed(IJobExecutionContext context)
  124. {
  125. }
  126. void IJobListener.JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
  127. {
  128. Dispatcher.BeginInvoke(DispatcherPriority.Normal
  129. , new Action(delegate
  130. {
  131. UpdateStatus();
  132. if ((MainFrame.Content is DashboardPage dashboardPage))
  133. {
  134. dashboardPage.LoadStatus();
  135. }
  136. }));
  137. }
  138. }
  139. }