forked from LittleDigital/InterviewTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdExclusion.cs
73 lines (59 loc) · 2.43 KB
/
IdExclusion.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
using System;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FundsLibraryTest
{
public class IdExclusion : IFileComparisonExclusion
{
public void ApplyExclusion(FileComparisonEntry[] workingCopy, Stream fileStreamA, Stream fileStreamB)
{
//this exclusion only applies if the rest of the document is equal. If the size is different, then the document must be different so no point checking the ID
if (fileStreamA.Length != fileStreamB.Length)
{
return;
}
//reset file stream positions.
fileStreamA.Position = 0;
fileStreamB.Position = 0;
using (var streamReaderA = new StreamReader(fileStreamA))
using (var streamReaderB = new StreamReader(fileStreamA))
{
var contentsA = streamReaderA.ReadToEnd();
int streamAIdOpenIndex;
int streamAIdCloseIndex;
DetermineIdPositions(contentsA, out streamAIdOpenIndex, out streamAIdCloseIndex);
var contentsB = streamReaderA.ReadToEnd();
int streamBIdOpenIndex;
int streamBIdCloseIndex;
DetermineIdPositions(contentsA, out streamBIdOpenIndex, out streamBIdCloseIndex);
if ((streamAIdOpenIndex != -1 && streamAIdCloseIndex != -1)
&& streamAIdOpenIndex == streamBIdOpenIndex
&& streamAIdCloseIndex == streamBIdCloseIndex)
{
for (var idx = streamAIdOpenIndex; idx < streamAIdCloseIndex;idx++)
{
if (workingCopy[idx] == FileComparisonEntry.Different)
{
workingCopy[idx] = FileComparisonEntry.Mitigated;
}
}
}
}
}
private static void DetermineIdPositions(string contentsA, out int idOpenIndex, out int idCloseIndex)
{
idOpenIndex = -1;
idCloseIndex = -1;
idOpenIndex = contentsA.IndexOf("/ID [<");
if (idOpenIndex >= 0)
{
//now find closing element
idCloseIndex = contentsA.IndexOf(">]", idOpenIndex);
if (idCloseIndex >= 0)
{
}
}
}
}
}