-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompareViewEx.xaml.cs
156 lines (128 loc) · 5.34 KB
/
CompareViewEx.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using PolReader.DiffingClasses;
using System.ComponentModel;
namespace PolReader
{
/// <summary>
/// Interaction logic for CompareViewEx.xaml
/// </summary>
public partial class CompareViewEx : Window
{
public CompareViewEx()
{
InitializeComponent();
CommandBinding cb = new CommandBinding(ApplicationCommands.Copy, CopyCmdExecuted, CopyCmdCanExecute);
CompareTreeView.CommandBindings.Add(cb);
}
void CopyCmdExecuted(object target, ExecutedRoutedEventArgs e)
{
TreeView tv = e.OriginalSource as TreeView;
string copyContent = String.Empty;
if (tv.SelectedItem is DiffPolicyInfo)
{
DiffPolicyInfo dpInf= (DiffPolicyInfo)tv.SelectedItem;
copyContent = dpInf.Name;
}
else if (tv.SelectedItem is BaseDiffViewItem)
{
BaseDiffViewItem dpI = (BaseDiffViewItem)tv.SelectedItem;
copyContent = dpI.Name;
}
try
{
Clipboard.SetData(DataFormats.Text, copyContent);
}
catch
{
}
}
void CopyCmdCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
TreeView tv = e.OriginalSource as TreeView;
// CanExecute only if there is one or more selected Item.
if (tv.SelectedItem !=null)
e.CanExecute = true;
else
e.CanExecute = false;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.SaveFileDialog fbDialog = new System.Windows.Forms.SaveFileDialog();
fbDialog.Filter = "Compare Policy Files|*.Cpf";
if (fbDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Stream stream = File.Open(fbDialog.FileName, FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, CompareTreeView.ItemsSource);
stream.Close();
}
}
private void OpenButton_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog fbDialog = new System.Windows.Forms.OpenFileDialog();
fbDialog.Filter = "Compare Policy Files|*.Cpf";
if (fbDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Stream stream = File.Open(fbDialog.FileName, FileMode.Open);
BinaryFormatter bformatter = new BinaryFormatter();
CompareTreeView.ItemsSource = (List<DiffPolicyInfo>)bformatter.Deserialize(stream);
stream.Close();
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}
private void FilterText_TextChanged(object sender, TextChangedEventArgs e)
{
FilterData();
}
public void FilterData()
{
if (CompareTreeView != null && CompareTreeView.ItemsSource != null)
{
ICollectionView view = CollectionViewSource.GetDefaultView(CompareTreeView.ItemsSource);
view.Filter = null;
view.Filter = new Predicate<object>(FilterListView);
}
}
public bool FilterListView(Object item)
{
DiffPolicyInfo policy = (DiffPolicyInfo)item;
return ((FilterText.Text.Length < 1 || (policy.Name.ToLower().Contains(FilterText.Text.ToLower())))
&& ((FilterAssign.IsChecked == true && policy.AssignmentsDifferenceInfo.Assignmments.Count>0)
|| (FilterGPT.IsChecked == true && policy.SecEditDifferenceInfo.Sections.Count > 0)
|| (FilterLinks.IsChecked == true && policy.LinkageDifferenceInfo.Linkages.Count > 0)
|| (FilterWMI.IsChecked == true && policy.WMIDifferenceInfo.WMIItems.Count > 0)
|| (FilterPref.IsChecked == true && (policy.PreferenceDifferenceInfo.nodeItems.Count > 0 || policy.MachinePreferenceDifferenceInfo.nodeItems.Count > 0))
|| (FilterReg.IsChecked == true && (policy.MachineRegDifferenceInfo.Items.Count > 0 || policy.UserRegDifferenceInfo.Items.Count > 0))
|| (FilterIEAK.IsChecked == true && (policy.IEAKDifferenceInfo.Sections.Count > 0 || policy.IEAKMachineDifferenceInfo.Sections.Count > 0))
));
}
private void Filter_Click(object sender, RoutedEventArgs e)
{
FilterData();
}
}
}