RestorePage.xaml.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. using Agent.Models;
  2. using Agent.Services;
  3. using log4net;
  4. using System;
  5. using System.IO;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using WinForms = System.Windows.Forms;
  12. namespace Agent.Views
  13. {
  14. /// <summary>
  15. /// Interaction logic for RestorePage.xaml
  16. /// </summary>
  17. public partial class RestorePage : Page
  18. {
  19. private static readonly ILog log = LogManager.GetLogger(typeof(PolicyPage));
  20. private readonly PolicyService _policyService = new PolicyService();
  21. private readonly UserService _userService = new UserService();
  22. private readonly HashService _hashService = new HashService();
  23. private readonly CollectionViewSource _searchViewSource = new CollectionViewSource();
  24. private readonly ObservableCollection<PolicyHistory> _resultList = new ObservableCollection<PolicyHistory>();
  25. public RestorePage()
  26. {
  27. InitializeComponent();
  28. Tag1Header.Header = (string)Application.Current.Properties["user_tag1"];
  29. Tag2Header.Header = (string)Application.Current.Properties["user_tag2"];
  30. Tag3Header.Header = (string)Application.Current.Properties["user_tag3"];
  31. Tag4Header.Header = (string)Application.Current.Properties["user_tag4"];
  32. Tag5Header.Header = (string)Application.Current.Properties["user_tag5"];
  33. Tag6Header.Header = (string)Application.Current.Properties["user_tag6"];
  34. Tag7Header.Header = (string)Application.Current.Properties["user_tag7"];
  35. Tag8Header.Header = (string)Application.Current.Properties["user_tag8"];
  36. Tag9Header.Header = (string)Application.Current.Properties["user_tag9"];
  37. Tag10Header.Header = (string)Application.Current.Properties["user_tag10"];
  38. Tag1Content.Content = (string)Application.Current.Properties["user_tag1"];
  39. Tag2Content.Content = (string)Application.Current.Properties["user_tag2"];
  40. Tag3Content.Content = (string)Application.Current.Properties["user_tag3"];
  41. Tag4Content.Content = (string)Application.Current.Properties["user_tag4"];
  42. Tag5Content.Content = (string)Application.Current.Properties["user_tag5"];
  43. Tag6Content.Content = (string)Application.Current.Properties["user_tag6"];
  44. Tag7Content.Content = (string)Application.Current.Properties["user_tag7"];
  45. Tag8Content.Content = (string)Application.Current.Properties["user_tag8"];
  46. Tag9Content.Content = (string)Application.Current.Properties["user_tag9"];
  47. Tag10Content.Content = (string)Application.Current.Properties["user_tag10"];
  48. _searchViewSource.Source = _policyService.GetPolicyIndexesExtendTag();
  49. SearchList.ItemsSource = _searchViewSource.View;
  50. ResultList.ItemsSource = _resultList;
  51. }
  52. private void HashChk_btn_Click(object sender, RoutedEventArgs e)
  53. {
  54. try
  55. {
  56. if (0 == _resultList.Count)
  57. {
  58. MessageBox.Show("파일 히스토리가 존재하지 않습니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  59. return;
  60. }
  61. if (ResultList.SelectedIndex < 0)
  62. {
  63. MessageBox.Show("점검할 파일 히스토리를 선랙하지 않습니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  64. return;
  65. }
  66. var dialog = new WinForms.OpenFileDialog();
  67. if (dialog.ShowDialog() == WinForms.DialogResult.Cancel)
  68. {
  69. return;
  70. }
  71. //HashChkWindow hashCheckWindow = new HashChkWindow(dialog.FileName, create_date, findHistory);
  72. var hash = _hashService.FileToMD5(dialog.FileName);
  73. var findHistory = _resultList[ResultList.SelectedIndex].Hash.Equals(hash);
  74. HashChkWindow hashCheckWindow = new HashChkWindow(dialog.FileName, hash, findHistory);
  75. if (findHistory == false)
  76. {
  77. hashCheckWindow.ShowDialog();
  78. return;
  79. }
  80. var info = new FileInfo(dialog.FileName);
  81. var create_date = info.LastWriteTime;
  82. findHistory = _resultList[ResultList.SelectedIndex].Create_Date.ToString().Equals(create_date.ToString());
  83. if (findHistory == false)
  84. {
  85. MessageBox.Show(" 원본 파일 : " + _resultList[ResultList.SelectedIndex].Create_Date.ToString() + "\r\n" + " 대상 파일 : " + create_date.ToString(), "작성일자 불일치", MessageBoxButton.OK, MessageBoxImage.Warning);
  86. return;
  87. }
  88. findHistory = ((Agent.Models.PolicyIndex)SearchList.SelectedItem).Name.ToString().Equals(dialog.SafeFileName.ToString());
  89. //findHistory = SearchList.SelectedItem.ToString().Equals(create_date.ToString());
  90. if (findHistory == false)
  91. {
  92. MessageBox.Show(" 원본 파일명 : " + ((Agent.Models.PolicyIndex)SearchList.SelectedItem).Name.ToString() + "\r\n" + " 대상 파일명 : " + dialog.SafeFileName.ToString(), "파일명 불일치", MessageBoxButton.OK, MessageBoxImage.Warning);
  93. return;
  94. }
  95. hashCheckWindow.ShowDialog();
  96. }
  97. catch (Exception ex)
  98. {
  99. log.Error(ex);
  100. }
  101. //---- 2023.01.03 Bclee Hash Code 일치 확인 로직 변경함 --------------
  102. //var findHistory = _resultList.FirstOrDefault(item => item.Hash.Equals(hash));
  103. //HashChkWindow hashCheckWindow = new HashChkWindow(dialog.FileName, hash, null != findHistory);
  104. }
  105. private void Restore_btn_Click(object sender, RoutedEventArgs e)
  106. {
  107. try
  108. {
  109. if (!(ResultList.SelectedItem is PolicyHistory item))
  110. {
  111. MessageBox.Show("복원 파일 히스토리를 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  112. return;
  113. }
  114. var frm1 = new LoginWindow();
  115. if (frm1.ShowDialog() == true)
  116. {
  117. var result = MessageBox.Show($"해시값({item.Hash})\r\n복원하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
  118. if (result == MessageBoxResult.No)
  119. {
  120. return;
  121. }
  122. if (!(SearchList.SelectedItem is PolicyIndexDto policyIndex))
  123. {
  124. MessageBox.Show("복원에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  125. return;
  126. }
  127. if (!_policyService.Restore(item.Policy_Tid, policyIndex.Path, item.Hash, item.Create_Date, item.Backup_File_Id, "RE", policyIndex.Path + " [파일복원]"))
  128. {
  129. MessageBox.Show("복원에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  130. return;
  131. }
  132. MessageBox.Show($"해시값({item.Hash})\r\n복원되었습니다.", "확인", MessageBoxButton.OK, MessageBoxImage.Information);
  133. }
  134. else
  135. {
  136. }
  137. }
  138. catch (Exception ex)
  139. {
  140. log.Error(ex);
  141. }
  142. }
  143. private void DownLoad_btn_Click(object sender, RoutedEventArgs e)
  144. {
  145. try
  146. {
  147. if (!(ResultList.SelectedItem is PolicyHistory item))
  148. {
  149. MessageBox.Show("다운로드할 파일 히스토리를 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  150. return;
  151. }
  152. var frm1 = new LoginWindow();
  153. if (frm1.ShowDialog() == true)
  154. {
  155. var result = MessageBox.Show($"해시값({item.Hash})\r\n다운로드 하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
  156. if (result == MessageBoxResult.No)
  157. {
  158. return;
  159. }
  160. if (!(SearchList.SelectedItem is PolicyIndexDto policyIndex))
  161. {
  162. MessageBox.Show("다운로드에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  163. return;
  164. }
  165. //bool result = false;
  166. var dialog = new WinForms.SaveFileDialog
  167. {
  168. Filter = "All files(*.*)|*.*"
  169. };
  170. if (dialog.ShowDialog() == WinForms.DialogResult.OK)
  171. {
  172. if (!_policyService.Restore(item.Policy_Tid, dialog.FileName, item.Hash, item.Create_Date, item.Backup_File_Id, "DN", dialog.FileName + " [File Download]"))
  173. {
  174. MessageBox.Show("다운로드에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  175. return;
  176. }
  177. }
  178. MessageBox.Show($"해시값({item.Hash})\r\n다운로드 되었습니다.", "확인", MessageBoxButton.OK, MessageBoxImage.Information);
  179. }
  180. else
  181. {
  182. }
  183. }
  184. catch (Exception ex)
  185. {
  186. MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  187. }
  188. }
  189. private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  190. {
  191. try
  192. {
  193. var idx = RP_serarch_cb.SelectedIndex;
  194. var view = CollectionViewSource.GetDefaultView(_searchViewSource.View);
  195. if (0 == idx)
  196. {
  197. view.Filter = _NameFiltered;
  198. return;
  199. }
  200. if (1 == idx)
  201. {
  202. view.Filter = _Tag1Filtered;
  203. return;
  204. }
  205. if (2 == idx)
  206. {
  207. view.Filter = _Tag2Filtered;
  208. return;
  209. }
  210. if (3 == idx)
  211. {
  212. view.Filter = _Tag3Filtered;
  213. return;
  214. }
  215. if (4 == idx)
  216. {
  217. view.Filter = _Tag4Filtered;
  218. return;
  219. }
  220. if (5 == idx)
  221. {
  222. view.Filter = _Tag5Filtered;
  223. return;
  224. }
  225. if (6 == idx)
  226. {
  227. view.Filter = _Tag6Filtered;
  228. return;
  229. }
  230. if (7 == idx)
  231. {
  232. view.Filter = _Tag7Filtered;
  233. return;
  234. }
  235. if (8 == idx)
  236. {
  237. view.Filter = _Tag8Filtered;
  238. return;
  239. }
  240. if (9 == idx)
  241. {
  242. view.Filter = _Tag9Filtered;
  243. return;
  244. }
  245. if (10 == idx)
  246. {
  247. view.Filter = _Tag10Filtered;
  248. return;
  249. }
  250. }
  251. catch (Exception ex)
  252. {
  253. MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
  254. }
  255. }
  256. private bool _NameFiltered(object item)
  257. {
  258. return (item as PolicyIndexDto).Name.Contains(RP_search_tb.Text.Trim());
  259. }
  260. private bool _Tag1Filtered(object item)
  261. {
  262. return (item as PolicyIndexDto).Custom_tag1.Contains(RP_search_tb.Text.Trim());
  263. }
  264. private bool _Tag2Filtered(object item)
  265. {
  266. return (item as PolicyIndexDto).Custom_tag2.Contains(RP_search_tb.Text.Trim());
  267. }
  268. private bool _Tag3Filtered(object item)
  269. {
  270. return (item as PolicyIndexDto).Custom_tag3.Contains(RP_search_tb.Text.Trim());
  271. }
  272. private bool _Tag4Filtered(object item)
  273. {
  274. return (item as PolicyIndexDto).Custom_tag4.Contains(RP_search_tb.Text.Trim());
  275. }
  276. private bool _Tag5Filtered(object item)
  277. {
  278. return (item as PolicyIndexDto).Custom_tag5.Contains(RP_search_tb.Text.Trim());
  279. }
  280. private bool _Tag6Filtered(object item)
  281. {
  282. return (item as PolicyIndexDto).Custom_tag6.Contains(RP_search_tb.Text.Trim());
  283. }
  284. private bool _Tag7Filtered(object item)
  285. {
  286. return (item as PolicyIndexDto).Custom_tag7.Contains(RP_search_tb.Text.Trim());
  287. }
  288. private bool _Tag8Filtered(object item)
  289. {
  290. return (item as PolicyIndexDto).Custom_tag8.Contains(RP_search_tb.Text.Trim());
  291. }
  292. private bool _Tag9Filtered(object item)
  293. {
  294. return (item as PolicyIndexDto).Custom_tag9.Contains(RP_search_tb.Text.Trim());
  295. }
  296. private bool _Tag10Filtered(object item)
  297. {
  298. return (item as PolicyIndexDto).Custom_tag10.Contains(RP_search_tb.Text.Trim());
  299. }
  300. private void SearchList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  301. {
  302. _resultList.Clear();
  303. if (!((sender as ListView).SelectedItem is PolicyIndexDto item))
  304. {
  305. RP_title_tb.Text = string.Empty;
  306. return;
  307. }
  308. _policyService
  309. .GetPolicyHistories(item.Policy_Tid, item.Tid)
  310. .ForEach(policyHistory => _resultList.Add(policyHistory));
  311. RP_title_tb.Text = $"{_resultList.Count} 개의 히스토리가 있습니다.";
  312. }
  313. private void ResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  314. {
  315. }
  316. }
  317. }