forked from FIMTooler/csReporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmFilter.cs
More file actions
4540 lines (4455 loc) · 231 KB
/
frmFilter.cs
File metadata and controls
4540 lines (4455 loc) · 231 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
MIT License
Copyright (c) 2017 David Cassady
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace csReporter
{
public partial class frmFilter : Form
{
#region Form Variables
CustomConcurrentBag<csObject> csObjects = new CustomConcurrentBag<csObject>();
ConcurrentBag<csObject> matchingCSobjects = new ConcurrentBag<csObject>();
FilterObject filter;
string inputFileName;
string outputFileName;
ToolTip tTipInfo = new ToolTip();
List<string> csAddlengths = new List<string>();
List<string> xmlLoadlenghts = new List<string>();
List<string> subStringlengths = new List<string>();
bool pendingImportDeltasExist;
bool unappliedExportDeltasExist;
bool escrowedExportDeltasExist;
bool unconfirmedExportDeltasExist;
bool synchronizationHologramExist;
bool pendingImportHologramExist;
bool unappliedExportHologramExist;
bool escrowedExportHologramExist;
bool unconfirmedExportHologramExist;
bool lowMemProcessing;
bool makeReport;
reportType report;
List<string> sysAttribs = new List<string>();
List<string> changingAttribs = new List<string>();
List<string> nonChangingAttribs = new List<string>();
List<string> errorAttribs = new List<string>();
List<string> mvAttribs = new List<string>();
//timer that runs once after form_Shown event
System.Windows.Forms.Timer oneTime = new System.Windows.Forms.Timer();
//delegates for processing form while reading/writing files
private delegate void delCloseForm(frmProgressBar frmProgress);
private delegate void delUpdateBar(frmProgressBar frmProgress, int value);
private delegate void delSetText(frmProgressBar frmProgress, String value);
private delegate void delSetCount(int count);
private delegate void delUpdateLBs(string[] valuess);
private bool ADdata = false;
public static volatile bool stopProcessing = false;
List<string> knownADattribs = new List<string>() { "accountExpires", "objectSid", "groupType", "pwdLastSet", "userAccountControl", "lastLogonTimestamp", "createTimeStamp" };
#endregion
#region Form Contructor/Events
public frmFilter(string fileName)
{
InitializeComponent();
tTipInfo.AutoPopDelay =10000;
tTipInfo.SetToolTip(this.cbADMA, "Auto-formats known Active Directory attributes so they are readable");
inputFileName = fileName;
csObjects.FinishedLoading += new LoadCompletedEventHandler(this.fileLoadComplete);
this.Enabled = false;
}
private void frmFilter_Shown(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
oneTime.Interval = 500;
oneTime.Tick += oneTime_Tick;
oneTime.Start();
}
private void oneTime_Tick(object sender, EventArgs e)
{
oneTime.Stop();
//Cursor = Cursors.WaitCursor;
//call function to parse file and populate UI filters
processFile();
System.GC.Collect();
Cursor = Cursors.Default;
}
private void rbPendingImport_CheckedChanged(object sender, EventArgs e)
{
if (rbPendingImport.Checked)
{
if (!lowMemProcessing && csObjects.Count < 1)
{
MessageBox.Show("You must first select a file");
rbPendingImport.Checked = false;
return;
}
Cursor = Cursors.WaitCursor;
cbNonChanging.Enabled = true;
reCalcMatching(FilterLevel.State);
Cursor = Cursors.Default;
}
}
private void rbUnappliedExport_CheckedChanged(object sender, EventArgs e)
{
if (rbUnappliedExport.Checked)
{
if (!lowMemProcessing && csObjects.Count < 1)
{
MessageBox.Show("You must first select a file");
rbUnappliedExport.Checked = false;
return;
}
Cursor = Cursors.WaitCursor;
cbNonChanging.Enabled = true;
reCalcMatching(FilterLevel.State);
Cursor = Cursors.Default;
}
}
private void rbSynchronized_CheckedChanged(object sender, EventArgs e)
{
if (rbSynchronized.Checked)
{
if (!lowMemProcessing && csObjects.Count < 1)
{
MessageBox.Show("You must first select a file");
rbSynchronized.Checked = false;
return;
}
Cursor = Cursors.WaitCursor;
cbNonChanging.Enabled = false;
reCalcMatching(FilterLevel.State);
Cursor = Cursors.Default;
}
}
private void rbEscrowedExport_CheckedChanged(object sender, EventArgs e)
{
if (rbEscrowedExport.Checked)
{
if (!lowMemProcessing && csObjects.Count < 1)
{
MessageBox.Show("You must first select a file");
rbEscrowedExport.Checked = false;
return;
}
Cursor = Cursors.WaitCursor;
cbNonChanging.Enabled = true;
reCalcMatching(FilterLevel.State);
Cursor = Cursors.Default;
}
}
private void rbUnconfirmedExport_CheckedChanged(object sender, EventArgs e)
{
if (rbUnconfirmedExport.Checked)
{
if (!lowMemProcessing && csObjects.Count < 1)
{
MessageBox.Show("You must first select a file");
rbUnconfirmedExport.Checked = false;
return;
}
Cursor = Cursors.WaitCursor;
cbNonChanging.Enabled = true;
reCalcMatching(FilterLevel.State);
Cursor = Cursors.Default;
}
}
private void lbObjectType_SelectedValueChanged(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
if (lbObjectType.SelectedItems.Count == 0)
{
reCalcMatching(FilterLevel.State);
}
else if (rbSynchronized.Checked)
{
reCalcMatching(FilterLevel.Operation);
}
else
{
reCalcMatching(FilterLevel.ObjectType);
}
Cursor = Cursors.Default;
}
private void lbOperation_SelectedValueChanged(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
if (lbOperation.SelectedItems.Count == 0)
{
reCalcMatching(FilterLevel.ObjectType);
}
else
{
reCalcMatching(FilterLevel.Operation);
}
Cursor = Cursors.Default;
}
private void lbAttribute_SelectedValueChanged(object sender, EventArgs e)
{
if (lbAttribute.SelectedItems.Count == 0)
{
filter.ReportAttributes = lbAttribute.Items.Cast<string>().ToList();
}
else
{
filter.ReportAttributes = lbAttribute.SelectedItems.Cast<string>().ToList();
}
}
private void btnAddFilter_Click(object sender, EventArgs e)
{
if (dgvAdvanced.DataSource == null)
{
//set binding for datagrid
dgvAdvanced.DataSource = filter.AttributeFilters;
}
//starts with Is covers Is present, Is not present, Is changing, Is not changing
if (cbbAttributes.Text.Length > 0 && cbbComparators.Text.Length > 0 && (cbbValue.Text.Length > 0 || cbbComparators.Text.StartsWith("Is")))
{
//verify uniqueness then add to filter
if (!filter.AttributeFilters.Contains(new FilterAttribute(cbbAttributes.Text, cbbComparators.Text, cbbValue.Text)))
{
Cursor = Cursors.WaitCursor;
filter.AttributeFilters.Add(new FilterAttribute(cbbAttributes.Text, cbbComparators.Text, cbbValue.Text));
cbbAttributes.SelectedIndex = -1;
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
reCalcMatching(FilterLevel.AttributeValue);
Cursor = Cursors.Default;
}
else
{
MessageBox.Show("This filter is already added and cannot be added again");
}
}
else
{
MessageBox.Show("Filter is not complete. Ensure an attribute, operation, and value are present");
}
}
private void btnRemoveFilter_Click(object sender, EventArgs e)
{
if (dgvAdvanced.SelectedRows.Count == 1)
{
Cursor = Cursors.WaitCursor;
FilterAttribute tempFilter = new FilterAttribute(dgvAdvanced.SelectedRows[0].Cells[0].Value.ToString(), dgvAdvanced.SelectedRows[0].Cells[1].Value.ToString(), dgvAdvanced.SelectedRows[0].Cells[2].Value.ToString());
filter.AttributeFilters.Remove(tempFilter);
cbbAttributes.SelectedIndex = -1;
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
if (filter.AttributeFilters.Count > 0)
{
reCalcMatching(FilterLevel.AttributeValue);
}
else
{
reCalcMatching(FilterLevel.Operation);
}
Cursor = Cursors.Default;
}
else
{
MessageBox.Show("Please select a filter from the grid below");
}
}
private void cbbComparators_SelectedIndexChanged(object sender, EventArgs e)
{
//starts with Is covers Is present, Is not present, Is changing, Is not changing
if (cbbAttributes.Text == "<Disconnect Time>" || cbbAttributes.Text == "<Connect Time>" || cbbComparators.Text.StartsWith("Is"))
{
if (cbbComparators.Text.StartsWith("Is"))
{
cbbValue.Text = "";
}
cbbValue.Enabled = false;
}
else if (!cbbValue.Enabled)
{
cbbValue.Enabled = true;
}
}
private void cbADMA_CheckedChanged(object sender, EventArgs e)
{
ADdata = cbADMA.Checked;
if (ADdata)
{
Cursor = Cursors.WaitCursor;
foreach (csObject csObj in csObjects)
{
//Set attribute AD values
SetAttribADvals(csObj.PendingImportHologram);
SetAttribADvals(csObj.UnappliedExportHologram);
SetAttribADvals(csObj.SynchronizedHologram);
SetAttribADvals(csObj.EscrowedExportHologram);
SetAttribADvals(csObj.UnconfirmedExportHologram);
}
Cursor = Cursors.Default;
}
}
private void cbNonChanging_CheckedChanged(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
SetFilterAttributes();
UpdateAttributeUI();
Cursor = Cursors.Default;
}
private void btnCreateReport_Click(object sender, EventArgs e)
{
if (lowMemProcessing || matchingCSobjects.Count > 0)
{
try
{
frmReport frmRep = new frmReport(filter.AvailableAttributes);
frmRep.Owner = this;
if (frmRep.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
//abort generating a report
frmRep.Dispose();
return;
}
frmRep.Dispose();
switch (report)
{
case reportType.CSV:
sfdReport.Filter = "csv files (*.csv)|*.csv";
break;
case reportType.Excel:
sfdReport.Filter = "excel files (*.xlsx)|*.xlsx";
break;
default:
sfdReport.Filter = "html files (*.html)|*.html";
break;
}
if (sfdReport.ShowDialog() != DialogResult.OK)
{
//abort generating a report
return;
}
outputFileName = sfdReport.FileName;
makeReport = true;
if (lowMemProcessing)
{
processFile();
}
else
{
frmProgressBar frmProgress = new frmProgressBar();
Thread worker;
switch (report)
{
case reportType.CSV:
worker = new Thread(BuildCSVReport);
break;
case reportType.Excel:
worker = new Thread(BuildExcelReport);
break;
default:
worker = new Thread(BuildHTMLReport);
break;
}
worker.Start(frmProgress);
if (frmProgress.ShowDialog() != DialogResult.OK)
{
MessageBox.Show("Progress window closed before report finish generating.");
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
stopProcessing = false;
}
frmProgress.Dispose();
}
if (File.Exists(outputFileName))
{
System.Diagnostics.Process.Start(outputFileName);
}
}
catch (Exception ex)
{
ExceptionHandler.handleException(ex, "Error occurred while generating report.");
Application.Exit();
}
}
else
{
MessageBox.Show("Unwilling to generate a report with 0 objects");
}
}
private void frmFilter_FormClosed(object sender, FormClosedEventArgs e)
{
if (!this.Owner.Visible)
{
Application.Exit();
}
}
private void btnBack_Click(object sender, EventArgs e)
{
ShowGetDataForm();
}
private void cbSystemAttribs_CheckedChanged(object sender, EventArgs e)
{
Cursor = Cursors.WaitCursor;
SetFilterAttributes();
UpdateAttributeUI();
Cursor = Cursors.Default;
}
private void cbbAttributes_SelectedIndexChanged(object sender, EventArgs e)
{
if (sysAttribs.Contains(cbbAttributes.Text))
{
switch (cbbAttributes.Text)
{
case "<Connect Time>":
{
cbbValue.DropDownStyle = ComboBoxStyle.DropDown;
//getDateFilterValue
FrmFilterDate dateFilter = new FrmFilterDate();
if (dateFilter.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
cbbValue.Items.Clear();
cbbValue.Enabled = false;
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Before");
cbbComparators.Items.Add("After");
cbbComparators.Items.Add("Equals");
cbbComparators.Items.Add("Does not equal");
cbbComparators.Items.Add("Is present");
cbbComparators.Items.Add("Is not present");
}
else
{
cbbValue.Text = "";
cbbAttributes.SelectedIndex = -1;
}
}
break;
case "<Disconnect Time>":
{
cbbValue.DropDownStyle = ComboBoxStyle.DropDown;
//getDateFilterValue
FrmFilterDate dateFilter = new FrmFilterDate();
if (dateFilter.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
cbbValue.Items.Clear();
cbbValue.Enabled = false;
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Before");
cbbComparators.Items.Add("After");
cbbComparators.Items.Add("Equals");
cbbComparators.Items.Add("Does not equal");
cbbComparators.Items.Add("Is present");
cbbComparators.Items.Add("Is not present");
}
else
{
cbbValue.Text = "";
cbbAttributes.SelectedIndex = -1;
}
}
break;
case "<Connector State>":
cbbValue.Text = "";
cbbValue.Items.Clear();
cbbValue.DropDownStyle = ComboBoxStyle.DropDownList;
cbbValue.Items.Add("normal");
cbbValue.Items.Add("explicit");
cbbValue.Items.Add("stay");
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Equals");
cbbComparators.Items.Add("Does not equal");
break;
case "<Connector>":
cbbValue.Text = "";
cbbValue.Items.Clear();
cbbValue.DropDownStyle = ComboBoxStyle.DropDownList;
cbbValue.Items.Add(Boolean.TrueString);
cbbValue.Items.Add(Boolean.FalseString);
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Equals");
break;
case "<Connector Operation>":
cbbValue.Text = "";
cbbValue.Items.Clear();
cbbValue.DropDownStyle = ComboBoxStyle.DropDownList;
cbbValue.Items.Add("provisioning-rules");
cbbValue.Items.Add("join-rules");
cbbValue.Items.Add("joiner-rule");
cbbValue.Items.Add("projection-rules");
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Equals");
cbbComparators.Items.Add("Does not equal");
break;
case "<DN>":
cbbValue.DropDownStyle = ComboBoxStyle.DropDown;
cbbValue.Text = "";
cbbValue.Items.Clear();
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Equals");
cbbComparators.Items.Add("Does not equal");
cbbComparators.Items.Add("Starts with");
cbbComparators.Items.Add("Does not start with");
cbbComparators.Items.Add("Ends with");
cbbComparators.Items.Add("Does not end with");
cbbComparators.Items.Add("Contains");
cbbComparators.Items.Add("Does not contain");
cbbComparators.Items.Add("Is present");
cbbComparators.Items.Add("Is not present");
break;
}
}
else
{
//reset
cbbValue.Enabled = true;
cbbValue.DropDownStyle = ComboBoxStyle.DropDown;
cbbValue.Text = "";
cbbValue.Items.Clear();
cbbComparators.Items.Clear();
cbbComparators.Items.Add("Equals");
cbbComparators.Items.Add("Does not equal");
cbbComparators.Items.Add("Starts with");
cbbComparators.Items.Add("Does not start with");
cbbComparators.Items.Add("Ends with");
cbbComparators.Items.Add("Does not end with");
cbbComparators.Items.Add("Contains");
cbbComparators.Items.Add("Does not contain");
cbbComparators.Items.Add("Is present");
cbbComparators.Items.Add("Is not present");
if (filter.FilterState != State.Synchronized)
{
cbbComparators.Items.Add("Is changing");
cbbComparators.Items.Add("Is not changing");
}
if (mvAttribs.Contains(cbbAttributes.Text))
{
cbbComparators.Items.Add(">");
cbbComparators.Items.Add("<");
cbbComparators.Items.Add("=");
}
}
}
#endregion
#region Helper Functions
#region Filtering functions
private void UpdateMatching(State filterAction)
{
try
{
lbAttribute.Items.Clear();
lbOperation.Items.Clear();
lbObjectType.Items.Clear();
cbbAttributes.Items.Clear();
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
ConcurrentBag<string> types = new ConcurrentBag<string>();
filter.FilterState = filterAction;
filter.Level = FilterLevel.State;
filter.ObjectTypes.Clear();
filter.Operations.Clear();
filter.AttributeFilters.Clear();
if (lowMemProcessing)
{
processFile();
}
else
{
Parallel.ForEach(csObjects, obj =>
{
if (MatchFilter(obj))
{
matchingCSobjects.Add(obj);
types.Add(obj.ObjectType);
}
}
);
lbObjectType.Items.AddRange(types.Distinct().ToArray());
}
}
catch (Exception ex)
{
ExceptionHandler.handleException(ex, "Error occurred evaluating filter criteria.\r\nPending Action: " + filterAction);
Application.Exit();
}
}
private void UpdateMatching(State filterAction, List<string> objTypes)
{
try
{
ConcurrentBag<string> ops = new ConcurrentBag<string>();
if (filterAction != State.Synchronized)
{
lbAttribute.Items.Clear();
lbOperation.Items.Clear();
}
cbbAttributes.Items.Clear();
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
filter.FilterState = filterAction;
filter.Level = FilterLevel.ObjectType;
filter.ObjectTypes = objTypes;
filter.Operations.Clear();
filter.AttributeFilters.Clear();
if (lowMemProcessing)
{
processFile();
}
else
{
Parallel.ForEach(csObjects, obj =>
{
if (MatchFilter(obj))
{
matchingCSobjects.Add(obj);
if (filter.FilterState != State.Synchronized)
{
ops.Add(obj.Delta(filter.FilterState).Operation.ToString());
}
}
}
);
if (filter.FilterState != State.Synchronized)
{
lbOperation.Items.AddRange(ops.Distinct().ToArray());
}
}
}
catch (Exception ex)
{
string strMessage = "Error occurred evaluating filter criteria.\r\nPending Action: " + filterAction + "\r\nObject Types: ";
foreach (string strTemp in objTypes)
{
strMessage += strTemp + " ";
}
ExceptionHandler.handleException(ex, strMessage);
Application.Exit();
}
}
private void UpdateMatching(State filterAction, List<string> objTypes, List<operation> op)
{
try
{
cbbAttributes.Items.Clear();
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
filter.FilterState = filterAction;
filter.Level = FilterLevel.Operation;
filter.ObjectTypes = objTypes;
filter.Operations = op;
filter.AttributeFilters.Clear();
if (lowMemProcessing)
{
processFile();
}
else
{
Parallel.ForEach(csObjects, obj =>
{
if (MatchFilter(obj))
{
matchingCSobjects.Add(obj);
}
}
);
}
}
catch (Exception ex)
{
string strMessage = "Error occurred evaluating filter criteria.\r\nPending Action: " + filterAction + "\r\nObject Types: ";
foreach (string strTemp in objTypes)
{
strMessage += strTemp + " ";
}
strMessage += "\r\nOperation: " + op;
ExceptionHandler.handleException(ex, strMessage);
Application.Exit();
}
}
private void UpdateMatching(State filterAction, List<string> objTypes, List<operation> op, BindingList<FilterAttribute> attribFilters)
{
try
{
cbbAttributes.Items.Clear();
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
filter.FilterState = filterAction;
filter.Level = FilterLevel.AttributeValue;
filter.ObjectTypes = objTypes;
filter.Operations = op;
filter.AttributeFilters = attribFilters;
if (lowMemProcessing)
{
processFile();
}
else
{
Parallel.ForEach(csObjects, obj =>
{
if (MatchFilter(obj))
{
matchingCSobjects.Add(obj);
}
}
);
}
}
catch (Exception ex)
{
string strMessage = "Error occurred evaluating filter criteria.\r\nPending Action: " + filterAction + "\r\nObject Types: ";
foreach (string strTemp in objTypes)
{
strMessage += strTemp + " ";
}
strMessage += "\r\nOperation: " + op;
strMessage += "\r\nAttribute Filters:";
foreach (FilterAttribute filAtrib in attribFilters)
{
strMessage += "\r\n" + filAtrib.Attribute + " " + filAtrib.Operation + " " + filAtrib.Value;
}
ExceptionHandler.handleException(ex, strMessage);
Application.Exit();
}
}
//State should be None to call this method
private void UpdateMatching(List<string> objTypes, BindingList<FilterAttribute> attribFilters)
{
try
{
cbbAttributes.Items.Clear();
cbbComparators.SelectedIndex = -1;
cbbValue.Text = "";
filter.FilterState = State.Synchronized;
filter.Level = FilterLevel.AttributeValue;
filter.ObjectTypes = objTypes;
filter.Operations.Clear();
filter.AttributeFilters = attribFilters;
if (lowMemProcessing)
{
processFile();
}
else
{
Parallel.ForEach(csObjects, obj =>
{
if (MatchFilter(obj))
{
matchingCSobjects.Add(obj);
}
}
);
}
}
catch (Exception ex)
{
string strMessage = "Error occurred evaluating filter criteria.\r\nPending Action: None\r\nObject Types: ";
foreach (string strTemp in objTypes)
{
strMessage += strTemp + " ";
}
strMessage += "\r\nAttribute Filters:";
foreach (FilterAttribute filAtrib in attribFilters)
{
strMessage += "\r\n" + filAtrib.Attribute + " " + filAtrib.Operation + " " + filAtrib.Value;
}
ExceptionHandler.handleException(ex, strMessage);
Application.Exit();
}
}
private bool MatchFilter(csObject csObj)
{
switch (filter.Level)
{
case FilterLevel.State:
if (csObj.Delta(filter.FilterState) != null && csObj.Delta(filter.FilterState).Operation != operation.none)
{
return true;
}
else if (filter.FilterState == State.Synchronized && csObj.SynchronizedHologram != null && csObj.SynchronizedHologram.Attributes.Count > 0)
{
return true;
}
break;
case FilterLevel.ObjectType:
if (csObj.Delta(filter.FilterState) != null && csObj.Delta(filter.FilterState).Operation != operation.none && filter.ObjectTypes.Contains(csObj.ObjectType))
{
return true;
}
else if (filter.FilterState == State.Synchronized && csObj.SynchronizedHologram != null && csObj.SynchronizedHologram.Attributes.Count > 0 && filter.ObjectTypes.Contains(csObj.ObjectType))
{
return true;
}
break;
case FilterLevel.Operation:
if (csObj.Delta(filter.FilterState) != null && csObj.Delta(filter.FilterState).Operation != operation.none && filter.ObjectTypes.Contains(csObj.ObjectType) && filter.Operations.Contains(csObj.Delta(filter.FilterState).Operation))
{
return true;
}
break;
case FilterLevel.AttributeValue:
switch (filter.FilterState)
{
case State.Synchronized:
if (filter.ObjectTypes.Contains(csObj.ObjectType) && MatchAttribFilter(csObj.SynchronizedHologram))
{
return true; ;
}
break;
default:
if (filter.ObjectTypes.Contains(csObj.ObjectType))
{
if (cbNonChanging.Checked && MatchAttribFilter(csObj.Delta(filter.FilterState), csObj.SynchronizedHologram, false))
{
return true;
}
else if (MatchAttribFilter(csObj.Delta(filter.FilterState), csObj.Hologram(filter.FilterState), true))
{
return true;
}
}
break;
}
break;
}
return false;
}
private bool MatchAttribFilter(Delta delta, Entry hologram, bool deltaAttribs)
{
if (delta != null && delta.Operation != operation.none && filter.Operations.Contains(delta.Operation))
{
switch (deltaAttribs)
{
case false:
return MatchAttribFilter(hologram);
case true:
return MatchAttribFilter(delta, hologram);
}
}
return false;
}
private bool MatchAttribFilter(Delta delta, Entry hologram)
{
if (hologram != null && hologram.Attributes.Count > 0)
{
foreach (FilterAttribute fa in filter.AttributeFilters)
{
if (sysAttribs.Contains(fa.Attribute))
{
return SystemAttribFilter(fa, hologram.Parent);
}
else
{
switch (fa.Operation)
{
case "Equals":
if (fa.Attribute == "<DN>")
{
if (hologram.DN == null || hologram.DN.ToUpperInvariant() != fa.Value.ToUpperInvariant())
{
return false;
}
}
else
{
if (!delta.AttributeNames.Contains(fa.Attribute) || !hologram.AttributeNames.Contains(fa.Attribute))
{
return false;
}
if (ADdata && knownADattribs.Contains(fa.Attribute))
{
if (hologram.AttributeByName(fa.Attribute).ADStringValues.All(vals => vals.ToUpperInvariant() != fa.Value.ToUpperInvariant()))
{
return false;
}
}
else
{
if (hologram.AttributeByName(fa.Attribute).StringValues.All(vals => vals.ToUpperInvariant() != fa.Value.ToUpperInvariant()))
{
return false;
}
}
}
break;
case "Does not equal":
if (fa.Attribute == "<DN>")
{
if (hologram.DN == null || hologram.DN.ToUpperInvariant() == fa.Value.ToUpperInvariant())
{
return false;
}
}
else
{
if (!delta.AttributeNames.Contains(fa.Attribute) || !hologram.AttributeNames.Contains(fa.Attribute))
{
return false;
}
if (ADdata && knownADattribs.Contains(fa.Attribute))
{
if (hologram.AttributeByName(fa.Attribute).ADStringValues.Any(vals => vals.ToUpperInvariant() == fa.Value.ToUpperInvariant()))
{
return false;
}
}
else
{
if (hologram.AttributeByName(fa.Attribute).StringValues.Any(vals => vals.ToUpperInvariant() == fa.Value.ToUpperInvariant()))
{
return false;
}
}
}
break;
case "Starts with":
if (fa.Attribute == "<DN>")
{
if (hologram.DN == null || !hologram.DN.ToUpperInvariant().StartsWith(fa.Value.ToUpperInvariant()))
{
return false;
}
}
else
{
if (!delta.AttributeNames.Contains(fa.Attribute) || !hologram.AttributeNames.Contains(fa.Attribute))
{
return false;
}
if (ADdata && knownADattribs.Contains(fa.Attribute))
{
if (hologram.AttributeByName(fa.Attribute).ADStringValues.All(vals => !vals.ToUpperInvariant().StartsWith(fa.Value.ToUpperInvariant())))
{
return false;
}
}
else
{
if (hologram.AttributeByName(fa.Attribute).StringValues.All(vals => !vals.ToUpperInvariant().StartsWith(fa.Value.ToUpperInvariant())))
{
return false;
}
}
}
break;
case "Does not start with":
if (fa.Attribute == "<DN>")
{
if (hologram.DN == null || hologram.DN.ToUpperInvariant().StartsWith(fa.Value.ToUpperInvariant()))