using System.Linq;
using log4net;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Agent.Services;
using Agent.Models;
using System.Configuration;
using System;
namespace Agent.Views
{
///
/// Interaction logic for PolicyPage.xaml
///
public partial class PolicyPage : Page
{
private static readonly ILog log = LogManager.GetLogger(typeof(PolicyPage));
private readonly PolicyService _policyService = new PolicyService();
private readonly UserService _userService = new UserService();
private readonly ObservableCollection _policyList = new ObservableCollection();
private readonly List _checkList = new List();
public PolicyPage()
{
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"];
PolicyList.ItemsSource = _policyList;
FetchList();
}
private void CheckBox_PendingListAll_Checked(object sender, RoutedEventArgs e)
{
foreach (var item in _policyList)
{
item.Selected = true;
}
}
private void CheckBox_PendingListAll_Unchecked(object sender, RoutedEventArgs e)
{
foreach (var item in _policyList)
{
item.Selected = false;
}
}
public void FetchList()
{
_policyList.Clear();
foreach (var policy in _policyService.GetPoliciesRowNum())
{
_policyList.Add(new PolicyListItem
{
Selected = false,
Tid = policy.Tid,
RowNum = policy.RowNum,
UserTid = policy.User_Tid,
PolicyType = policy.Type,
Path = policy.Path,
PathNm = policy.Path,
IsDelete = policy.Is_Delete,
CreateDate = policy.Create_Date,
Tag1 = policy.Custom_Tag1,
Tag2 = policy.Custom_Tag2,
Tag3 = policy.Custom_Tag3,
Tag4 = policy.Custom_Tag4,
Tag5 = policy.Custom_Tag5,
Tag6 = policy.Custom_Tag6,
Tag7 = policy.Custom_Tag7,
Tag8 = policy.Custom_Tag8,
Tag9 = policy.Custom_Tag9,
Tag10 = policy.Custom_Tag10
});
}
PP_title_tb.Text = "DI 에이전트가 감시할 " + _policyList.Count + " 개의 정책이 수립되었습니다.";
}
private void PP_upload_btn_Click(object sender, RoutedEventArgs e)
{
try
{
var policyMonitorTid = _policyService.AddMonitor();
var result = _policyService.Backup();
_policyService.ModifyMonitor(policyMonitorTid, result.Success, result.Fail);
MessageBox.Show("즉시 Upload 되었습니다.", "Direct Upload", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void PP_add_btn_Click(object sender, RoutedEventArgs e)
{
try
{
var policySelectWindow = new PolicySelectWindow(this);
policySelectWindow.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void PP_set_btn_Click(object sender, RoutedEventArgs e)
{
try
{
var selectedItem = _policyList.FirstOrDefault(item => true == item.Selected);
if (null == selectedItem)
{
MessageBox.Show("TAG를 설정할 정책을 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (1 != _policyList.Count(item => true == item.Selected))
{
MessageBox.Show("한 개의 정책만 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
//if ("DIRECTORY".Equals(selectedItem.PolicyType))
//{
// MessageBox.Show("파일 정책만 TAG 설정이 가능합니다.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
// return;
//}
var policyTagWindow = new PolicyTagWindow(this, selectedItem);
policyTagWindow.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void PP_del_btn_Click(object sender, RoutedEventArgs e)
{
try
{
if (null == _policyList.FirstOrDefault(item => true == item.Selected))
{
MessageBox.Show("삭제할 정책을 선택해 주세요.", "오류", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var result = MessageBox.Show("삭제하시겠습니까?", "확인", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.No)
{
return;
}
var frm1 = new LoginWindow();
if (frm1.ShowDialog() == true)
{
_policyList
.Where(item => true == item.Selected)
.ToList()
.ForEach(item => _policyService.DeletePolicy(item.Tid));
for (int i = 0; i < _policyList.Count; i++)
{
if (_policyList[i].Selected == true)
{
_userService.Insert_deleteAT("삭제", frm1.ReturnValue1, _policyList[i].Path, _policyList[i].Tid, _policyList[i].UserTid);
}
}
}
else
{
}
FetchList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "오류", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}