123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- using Agent.Models;
- using Agent.Services;
- using log4net;
- using System;
- using System.IO;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using WinForms = System.Windows.Forms;
- namespace Agent.Views
- {
- /// <summary>
- /// Interaction logic for RestorePage.xaml
- /// </summary>
- public partial class RestorePage : Page
- {
- private static readonly ILog log = LogManager.GetLogger(typeof(PolicyPage));
- private readonly PolicyService _policyService = new PolicyService();
- private readonly UserService _userService = new UserService();
- private readonly HashService _hashService = new HashService();
- private readonly CollectionViewSource _searchViewSource = new CollectionViewSource();
- private readonly ObservableCollection<PolicyHistory> _resultList = new ObservableCollection<PolicyHistory>();
- public RestorePage()
- {
- InitializeComponent();
- Tag1Header.Header = (string)Application.Current.Properties["user_tag1"];
- Tag2Header.Header = (string)Application.Current.Properties["user_tag2"];
- Tag3Header.Header = (string)Application.Current.Properties["user_tag3"];
- Tag4Header.Header = (string)Application.Current.Properties["user_tag4"];
- Tag5Header.Header = (string)Application.Current.Properties["user_tag5"];
- Tag6Header.Header = (string)Application.Current.Properties["user_tag6"];
- Tag7Header.Header = (string)Application.Current.Properties["user_tag7"];
- Tag8Header.Header = (string)Application.Current.Properties["user_tag8"];
- Tag9Header.Header = (string)Application.Current.Properties["user_tag9"];
- Tag10Header.Header = (string)Application.Current.Properties["user_tag10"];
- Tag1Content.Content = (string)Application.Current.Properties["user_tag1"];
- Tag2Content.Content = (string)Application.Current.Properties["user_tag2"];
- Tag3Content.Content = (string)Application.Current.Properties["user_tag3"];
- Tag4Content.Content = (string)Application.Current.Properties["user_tag4"];
- Tag5Content.Content = (string)Application.Current.Properties["user_tag5"];
- Tag6Content.Content = (string)Application.Current.Properties["user_tag6"];
- Tag7Content.Content = (string)Application.Current.Properties["user_tag7"];
- Tag8Content.Content = (string)Application.Current.Properties["user_tag8"];
- Tag9Content.Content = (string)Application.Current.Properties["user_tag9"];
- Tag10Content.Content = (string)Application.Current.Properties["user_tag10"];
- _searchViewSource.Source = _policyService.GetPolicyIndexesExtendTag();
- SearchList.ItemsSource = _searchViewSource.View;
- ResultList.ItemsSource = _resultList;
- }
- private void HashChk_btn_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (0 == _resultList.Count)
- {
- MessageBox.Show("파일 히스토리가 존재하지 않습니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- if (ResultList.SelectedIndex < 0)
- {
- MessageBox.Show("점검할 파일 히스토리를 선랙하지 않습니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- var dialog = new WinForms.OpenFileDialog();
- if (dialog.ShowDialog() == WinForms.DialogResult.Cancel)
- {
- return;
- }
- //HashChkWindow hashCheckWindow = new HashChkWindow(dialog.FileName, create_date, findHistory);
- var hash = _hashService.FileToMD5(dialog.FileName);
- var findHistory = _resultList[ResultList.SelectedIndex].Hash.Equals(hash);
- HashChkWindow hashCheckWindow = new HashChkWindow(dialog.FileName, hash, findHistory);
- if (findHistory == false)
- {
- hashCheckWindow.ShowDialog();
- return;
- }
- var info = new FileInfo(dialog.FileName);
- var create_date = info.LastWriteTime;
- findHistory = _resultList[ResultList.SelectedIndex].Create_Date.ToString().Equals(create_date.ToString());
- if (findHistory == false)
- {
- MessageBox.Show(" 원본 파일 : " + _resultList[ResultList.SelectedIndex].Create_Date.ToString() + "\r\n" + " 대상 파일 : " + create_date.ToString(), "작성일자 불일치", MessageBoxButton.OK, MessageBoxImage.Warning);
- return;
- }
- findHistory = ((Agent.Models.PolicyIndex)SearchList.SelectedItem).Name.ToString().Equals(dialog.SafeFileName.ToString());
- //findHistory = SearchList.SelectedItem.ToString().Equals(create_date.ToString());
- if (findHistory == false)
- {
- MessageBox.Show(" 원본 파일명 : " + ((Agent.Models.PolicyIndex)SearchList.SelectedItem).Name.ToString() + "\r\n" + " 대상 파일명 : " + dialog.SafeFileName.ToString(), "파일명 불일치", MessageBoxButton.OK, MessageBoxImage.Warning);
- return;
- }
- hashCheckWindow.ShowDialog();
- }
- catch (Exception ex)
- {
- log.Error(ex);
- }
- //---- 2023.01.03 Bclee Hash Code 일치 확인 로직 변경함 --------------
- //var findHistory = _resultList.FirstOrDefault(item => item.Hash.Equals(hash));
- //HashChkWindow hashCheckWindow = new HashChkWindow(dialog.FileName, hash, null != findHistory);
- }
- private void Restore_btn_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (!(ResultList.SelectedItem is PolicyHistory item))
- {
- MessageBox.Show("복원 파일 히스토리를 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- var frm1 = new LoginWindow();
- if (frm1.ShowDialog() == true)
- {
- var result = MessageBox.Show($"해시값({item.Hash})\r\n복원하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
- if (result == MessageBoxResult.No)
- {
- return;
- }
- if (!(SearchList.SelectedItem is PolicyIndexDto policyIndex))
- {
- MessageBox.Show("복원에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- if (!_policyService.Restore(item.Policy_Tid, policyIndex.Path, item.Hash, item.Create_Date, item.Backup_File_Id, "RE", policyIndex.Path + " [파일복원]"))
- {
- MessageBox.Show("복원에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- MessageBox.Show($"해시값({item.Hash})\r\n복원되었습니다.", "확인", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- else
- {
- }
- }
- catch (Exception ex)
- {
- log.Error(ex);
- }
- }
- private void DownLoad_btn_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (!(ResultList.SelectedItem is PolicyHistory item))
- {
- MessageBox.Show("다운로드할 파일 히스토리를 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- var frm1 = new LoginWindow();
- if (frm1.ShowDialog() == true)
- {
- var result = MessageBox.Show($"해시값({item.Hash})\r\n다운로드 하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
- if (result == MessageBoxResult.No)
- {
- return;
- }
-
- if (!(SearchList.SelectedItem is PolicyIndexDto policyIndex))
- {
- MessageBox.Show("다운로드에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
-
- return;
- }
- //bool result = false;
- var dialog = new WinForms.SaveFileDialog
- {
- Filter = "All files(*.*)|*.*"
- };
- if (dialog.ShowDialog() == WinForms.DialogResult.OK)
- {
- if (!_policyService.Restore(item.Policy_Tid, dialog.FileName, item.Hash, item.Create_Date, item.Backup_File_Id, "DN", dialog.FileName + " [File Download]"))
- {
- MessageBox.Show("다운로드에 실패하였습니다.\r\n다시 시도 해주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- }
- MessageBox.Show($"해시값({item.Hash})\r\n다운로드 되었습니다.", "확인", MessageBoxButton.OK, MessageBoxImage.Information);
- }
- else
- {
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- try
- {
- var idx = RP_serarch_cb.SelectedIndex;
- var view = CollectionViewSource.GetDefaultView(_searchViewSource.View);
- if (0 == idx)
- {
- view.Filter = _NameFiltered;
- return;
- }
- if (1 == idx)
- {
- view.Filter = _Tag1Filtered;
- return;
- }
- if (2 == idx)
- {
- view.Filter = _Tag2Filtered;
- return;
- }
- if (3 == idx)
- {
- view.Filter = _Tag3Filtered;
- return;
- }
- if (4 == idx)
- {
- view.Filter = _Tag4Filtered;
- return;
- }
- if (5 == idx)
- {
- view.Filter = _Tag5Filtered;
- return;
- }
- if (6 == idx)
- {
- view.Filter = _Tag6Filtered;
- return;
- }
- if (7 == idx)
- {
- view.Filter = _Tag7Filtered;
- return;
- }
- if (8 == idx)
- {
- view.Filter = _Tag8Filtered;
- return;
- }
- if (9 == idx)
- {
- view.Filter = _Tag9Filtered;
- return;
- }
- if (10 == idx)
- {
- view.Filter = _Tag10Filtered;
- return;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- }
- private bool _NameFiltered(object item)
- {
- return (item as PolicyIndexDto).Name.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag1Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag1.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag2Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag2.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag3Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag3.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag4Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag4.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag5Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag5.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag6Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag6.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag7Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag7.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag8Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag8.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag9Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag9.Contains(RP_search_tb.Text.Trim());
- }
- private bool _Tag10Filtered(object item)
- {
- return (item as PolicyIndexDto).Custom_tag10.Contains(RP_search_tb.Text.Trim());
- }
- private void SearchList_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- _resultList.Clear();
- if (!((sender as ListView).SelectedItem is PolicyIndexDto item))
- {
- RP_title_tb.Text = string.Empty;
- return;
- }
- _policyService
- .GetPolicyHistories(item.Policy_Tid, item.Tid)
- .ForEach(policyHistory => _resultList.Add(policyHistory));
- RP_title_tb.Text = $"{_resultList.Count} 개의 히스토리가 있습니다.";
- }
- private void ResultList_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- }
- }
- }
|