/
ClassComparator.cs
156 lines (149 loc) · 4.59 KB
/
ClassComparator.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
namespace UiPathTeam.ActivityReader
{
public class ClassComparator
{
static private ClassComparator _singleton;
static ClassComparator()
{
_singleton = new ClassComparator();
}
static public ClassComparator GetInstance()
{
return _singleton;
}
public TypeFormat TypeFormat
{
get;
set;
}
private ClassComparator()
{
TypeFormat = TypeFormat.SIMPLE;
}
public int Run(ClassDatabase db1, ClassDatabase db2, IDiffActions actions)
{
int differences = 0;
var e1 = db1.Classes.GetEnumerator();
var e2 = db2.Classes.GetEnumerator();
var b1 = e1.MoveNext();
var b2 = e2.MoveNext();
while (b1 && b2)
{
var c1 = e1.Current;
var c2 = e2.Current;
if (!IsAccessibleActivity(c1))
{
b1 = e1.MoveNext();
}
else if (!IsAccessibleActivity(c2))
{
b2 = e2.MoveNext();
}
else
{
var rc = c1.Name.CompareTo(c2.Name);
if (rc < 0)
{
actions.ActivityOnlyInFirst(c1);
differences++;
b1 = e1.MoveNext();
}
else if (rc > 0)
{
actions.ActivityOnlyInSecond(c2);
differences++;
b2 = e2.MoveNext();
}
else
{
differences += Run(c1, c2, actions);
b1 = e1.MoveNext();
b2 = e2.MoveNext();
}
}
}
while (b1)
{
var c1 = e1.Current;
if (IsAccessibleActivity(c1))
{
actions.ActivityOnlyInFirst(c1);
differences++;
}
b1 = e1.MoveNext();
}
while (b2)
{
var c2 = e2.Current;
if (IsAccessibleActivity(c2))
{
actions.ActivityOnlyInSecond(c2);
differences++;
}
b2 = e2.MoveNext();
}
return differences;
}
static private bool IsAccessibleActivity(ClassRecord c)
{
return c.IsPublic && !c.IsAbstract && c.IsActivity;
}
/// <summary>
/// Finds the differences in properties.
/// </summary>
/// <returns>Number of differences found</returns>
public int Run(ClassRecord c1, ClassRecord c2, IDiffActions actions)
{
int differences = 0;
var e1 = c1.Properties.GetEnumerator();
var e2 = c2.Properties.GetEnumerator();
var b1 = e1.MoveNext();
var b2 = e2.MoveNext();
while (b1 && b2)
{
var p1 = e1.Current;
var p2 = e2.Current;
var rc = p1.Name.CompareTo(p2.Name);
if (rc < 0)
{
actions.PropertyOnlyInFirst(p1);
differences++;
b1 = e1.MoveNext();
}
else if (rc > 0)
{
actions.PropertyOnlyInSecond(p2);
differences++;
b2 = e2.MoveNext();
}
else if (TypeFormat != TypeFormat.NONE && p1.Type != p2.Type)
{
actions.PropertyOnlyInFirst(p1);
actions.PropertyOnlyInSecond(p2);
differences++;
b1 = e1.MoveNext();
b2 = e2.MoveNext();
}
else
{
actions.PropertyMatch(p1);
b1 = e1.MoveNext();
b2 = e2.MoveNext();
}
}
while (b1)
{
actions.PropertyOnlyInFirst(e1.Current);
differences++;
b1 = e1.MoveNext();
}
while (b2)
{
actions.PropertyOnlyInSecond(e2.Current);
differences++;
b2 = e2.MoveNext();
}
return differences;
}
}
}