PolicyPage.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using System.Linq;
  2. using log4net;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using Agent.Services;
  8. using Agent.Models;
  9. using System.Configuration;
  10. using System;
  11. namespace Agent.Views
  12. {
  13. /// <summary>
  14. /// Interaction logic for PolicyPage.xaml
  15. /// </summary>
  16. public partial class PolicyPage : Page
  17. {
  18. private static readonly ILog log = LogManager.GetLogger(typeof(PolicyPage));
  19. private readonly PolicyService _policyService = new PolicyService();
  20. private readonly UserService _userService = new UserService();
  21. private readonly ObservableCollection<PolicyListItem> _policyList = new ObservableCollection<PolicyListItem>();
  22. private readonly List<PolicyListItem> _checkList = new List<PolicyListItem>();
  23. public PolicyPage()
  24. {
  25. InitializeComponent();
  26. Tag1Header.Header = (string)Application.Current.Properties["user_tag1"];
  27. Tag2Header.Header = (string)Application.Current.Properties["user_tag2"];
  28. Tag3Header.Header = (string)Application.Current.Properties["user_tag3"];
  29. Tag4Header.Header = (string)Application.Current.Properties["user_tag4"];
  30. Tag5Header.Header = (string)Application.Current.Properties["user_tag5"];
  31. Tag6Header.Header = (string)Application.Current.Properties["user_tag6"];
  32. Tag7Header.Header = (string)Application.Current.Properties["user_tag7"];
  33. Tag8Header.Header = (string)Application.Current.Properties["user_tag8"];
  34. Tag9Header.Header = (string)Application.Current.Properties["user_tag9"];
  35. Tag10Header.Header = (string)Application.Current.Properties["user_tag10"];
  36. PolicyList.ItemsSource = _policyList;
  37. FetchList();
  38. }
  39. private void CheckBox_PendingListAll_Checked(object sender, RoutedEventArgs e)
  40. {
  41. foreach (var item in _policyList)
  42. {
  43. item.Selected = true;
  44. }
  45. }
  46. private void CheckBox_PendingListAll_Unchecked(object sender, RoutedEventArgs e)
  47. {
  48. foreach (var item in _policyList)
  49. {
  50. item.Selected = false;
  51. }
  52. }
  53. public void FetchList()
  54. {
  55. _policyList.Clear();
  56. foreach (var policy in _policyService.GetPoliciesRowNum())
  57. {
  58. _policyList.Add(new PolicyListItem
  59. {
  60. Selected = false,
  61. Tid = policy.Tid,
  62. RowNum = policy.RowNum,
  63. UserTid = policy.User_Tid,
  64. PolicyType = policy.Type,
  65. Path = policy.Path,
  66. PathNm = policy.Path,
  67. IsDelete = policy.Is_Delete,
  68. CreateDate = policy.Create_Date,
  69. Tag1 = policy.Custom_Tag1,
  70. Tag2 = policy.Custom_Tag2,
  71. Tag3 = policy.Custom_Tag3,
  72. Tag4 = policy.Custom_Tag4,
  73. Tag5 = policy.Custom_Tag5,
  74. Tag6 = policy.Custom_Tag6,
  75. Tag7 = policy.Custom_Tag7,
  76. Tag8 = policy.Custom_Tag8,
  77. Tag9 = policy.Custom_Tag9,
  78. Tag10 = policy.Custom_Tag10
  79. });
  80. }
  81. PP_title_tb.Text = "DI 에이전트가 감시할 " + _policyList.Count + " 개의 정책이 수립되었습니다.";
  82. }
  83. private void PP_upload_btn_Click(object sender, RoutedEventArgs e)
  84. {
  85. try
  86. {
  87. var policyMonitorTid = _policyService.AddMonitor();
  88. var result = _policyService.Backup();
  89. _policyService.ModifyMonitor(policyMonitorTid, result.Success, result.Fail);
  90. MessageBox.Show("즉시 Upload 되었습니다.", "Direct Upload", MessageBoxButton.OK, MessageBoxImage.Information);
  91. }
  92. catch (Exception ex)
  93. {
  94. MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  95. }
  96. }
  97. private void PP_add_btn_Click(object sender, RoutedEventArgs e)
  98. {
  99. try
  100. {
  101. var policySelectWindow = new PolicySelectWindow(this);
  102. policySelectWindow.ShowDialog();
  103. }
  104. catch (Exception ex)
  105. {
  106. MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  107. }
  108. }
  109. private void PP_set_btn_Click(object sender, RoutedEventArgs e)
  110. {
  111. try
  112. {
  113. var selectedItem = _policyList.FirstOrDefault(item => true == item.Selected);
  114. if (null == selectedItem)
  115. {
  116. MessageBox.Show("TAG를 설정할 정책을 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  117. return;
  118. }
  119. if (1 != _policyList.Count(item => true == item.Selected))
  120. {
  121. MessageBox.Show("한 개의 정책만 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  122. return;
  123. }
  124. //if ("DIRECTORY".Equals(selectedItem.PolicyType))
  125. //{
  126. // MessageBox.Show("파일 정책만 TAG 설정이 가능합니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  127. // return;
  128. //}
  129. var policyTagWindow = new PolicyTagWindow(this, selectedItem);
  130. policyTagWindow.ShowDialog();
  131. }
  132. catch (Exception ex)
  133. {
  134. MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  135. }
  136. }
  137. private void PP_del_btn_Click(object sender, RoutedEventArgs e)
  138. {
  139. try
  140. {
  141. if (null == _policyList.FirstOrDefault(item => true == item.Selected))
  142. {
  143. MessageBox.Show("삭제할 정책을 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  144. return;
  145. }
  146. var result = MessageBox.Show("삭제하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
  147. if (result == MessageBoxResult.No)
  148. {
  149. return;
  150. }
  151. var frm1 = new LoginWindow();
  152. if (frm1.ShowDialog() == true)
  153. {
  154. _policyList
  155. .Where(item => true == item.Selected)
  156. .ToList()
  157. .ForEach(item => _policyService.DeletePolicy(item.Tid));
  158. for (int i = 0; i < _policyList.Count; i++)
  159. {
  160. if (_policyList[i].Selected == true)
  161. {
  162. _userService.Insert_deleteAT("삭제", frm1.ReturnValue1, _policyList[i].Path, _policyList[i].Tid, _policyList[i].UserTid);
  163. }
  164. }
  165. }
  166. else
  167. {
  168. }
  169. FetchList();
  170. }
  171. catch (Exception ex)
  172. {
  173. MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  174. }
  175. }
  176. }
  177. }