@@ -11,8 +11,8 @@ namespace KustoCopyConsole.Entity.InMemory
11
11
internal class RowItemInMemoryCache
12
12
{
13
13
private readonly object _lock = new object ( ) ;
14
- private volatile IImmutableDictionary < TableIdentity , TableCache > _sourceTableMap =
15
- ImmutableDictionary < TableIdentity , TableCache > . Empty ;
14
+ private volatile IImmutableDictionary < string , ActivityCache > _activityMap =
15
+ ImmutableDictionary < string , ActivityCache > . Empty ;
16
16
17
17
public RowItemInMemoryCache ( IEnumerable < RowItemBase > items )
18
18
{
@@ -25,12 +25,12 @@ public RowItemInMemoryCache(IEnumerable<RowItemBase> items)
25
25
}
26
26
}
27
27
28
- public IImmutableDictionary < TableIdentity , TableCache > SourceTableMap
29
- => _sourceTableMap ;
28
+ public IImmutableDictionary < string , ActivityCache > ActivityMap
29
+ => _activityMap ;
30
30
31
31
public IEnumerable < RowItemBase > GetItems ( )
32
32
{
33
- foreach ( var sourceTable in SourceTableMap . Values )
33
+ foreach ( var sourceTable in ActivityMap . Values )
34
34
{
35
35
foreach ( var sourceTableIteration in sourceTable . IterationMap . Values )
36
36
{
@@ -51,17 +51,19 @@ public void AppendItem(RowItemBase item)
51
51
{
52
52
lock ( _lock )
53
53
{
54
- Interlocked . Exchange ( ref _sourceTableMap , AppendItemToCache ( item ) ) ;
54
+ Interlocked . Exchange ( ref _activityMap , AppendItemToCache ( item ) ) ;
55
55
}
56
56
}
57
57
58
- private IImmutableDictionary < TableIdentity , TableCache > AppendItemToCache (
58
+ private IImmutableDictionary < string , ActivityCache > AppendItemToCache (
59
59
RowItemBase item )
60
60
{
61
61
switch ( item )
62
62
{
63
- case TableRowItem st :
64
- return AppendSourceTable ( st ) ;
63
+ case ActivityRowItem a :
64
+ return AppendActivity ( a ) ;
65
+ case IterationRowItem i :
66
+ return AppendIteration ( i ) ;
65
67
case BlockRowItem sb :
66
68
return AppendSourceBlock ( sb ) ;
67
69
case UrlRowItem url :
@@ -72,45 +74,64 @@ private IImmutableDictionary<TableIdentity, TableCache> AppendItemToCache(
72
74
}
73
75
}
74
76
75
- private IImmutableDictionary < TableIdentity , TableCache > AppendSourceTable (
76
- TableRowItem item )
77
+ private IImmutableDictionary < string , ActivityCache > AppendActivity (
78
+ ActivityRowItem item )
77
79
{
78
- var tableId = item . SourceTable ;
80
+ var activityName = item . ActivityName ;
79
81
80
- if ( _sourceTableMap . ContainsKey ( tableId ) )
82
+ if ( _activityMap . ContainsKey ( activityName ) )
81
83
{
82
- var table = _sourceTableMap [ tableId ] ;
84
+ var activity = _activityMap [ activityName ] ;
85
+
86
+ return _activityMap . SetItem (
87
+ activityName ,
88
+ new ActivityCache ( item , activity . IterationMap ) ) ;
89
+ }
90
+ else
91
+ {
92
+ return _activityMap . Add ( activityName , new ActivityCache ( item ) ) ;
93
+ }
94
+ }
95
+
96
+ private IImmutableDictionary < string , ActivityCache > AppendIteration (
97
+ IterationRowItem item )
98
+ {
99
+ var activityName = item . ActivityName ;
100
+
101
+ if ( _activityMap . ContainsKey ( activityName ) )
102
+ {
103
+ var table = _activityMap [ activityName ] ;
83
104
84
105
if ( table . IterationMap . ContainsKey ( item . IterationId ) )
85
106
{
86
107
var iteration = table . IterationMap [ item . IterationId ] ;
87
108
88
- return _sourceTableMap . SetItem (
89
- tableId ,
109
+ return _activityMap . SetItem (
110
+ activityName ,
90
111
table . AppendIteration (
91
112
new IterationCache ( item , iteration . BlockMap ) ) ) ;
92
113
}
93
114
else
94
115
{
95
- return _sourceTableMap . SetItem (
96
- tableId ,
116
+ return _activityMap . SetItem (
117
+ activityName ,
97
118
table . AppendIteration ( new IterationCache ( item ) ) ) ;
98
119
}
99
120
}
100
121
else
101
122
{
102
- return _sourceTableMap . Add ( tableId , new TableCache ( item ) ) ;
123
+ throw new NotSupportedException ( "Activity should come before block in logs" ) ;
103
124
}
104
125
}
105
126
106
- private IImmutableDictionary < TableIdentity , TableCache > AppendSourceBlock (
127
+ private IImmutableDictionary < string , ActivityCache > AppendSourceBlock (
107
128
BlockRowItem item )
108
129
{
109
- var tableId = item . SourceTable ;
130
+ var activityName = item . ActivityName ;
110
131
111
- if ( _sourceTableMap . ContainsKey ( tableId ) )
132
+ if ( _activityMap . ContainsKey ( activityName ) )
112
133
{
113
- var sourceTable = _sourceTableMap [ tableId ] ;
134
+ var sourceTable = _activityMap [ activityName ] ;
114
135
115
136
if ( sourceTable . IterationMap . ContainsKey ( item . IterationId ) )
116
137
{
@@ -120,16 +141,16 @@ private IImmutableDictionary<TableIdentity, TableCache> AppendSourceBlock(
120
141
{
121
142
var sourceBlock = sourceIteration . BlockMap [ item . BlockId ] ;
122
143
123
- return _sourceTableMap . SetItem (
124
- tableId ,
144
+ return _activityMap . SetItem (
145
+ activityName ,
125
146
sourceTable . AppendIteration (
126
147
sourceIteration . AppendBlock (
127
148
new BlockCache ( item , sourceBlock . UrlMap ) ) ) ) ;
128
149
}
129
150
else
130
151
{
131
- return _sourceTableMap . SetItem (
132
- tableId ,
152
+ return _activityMap . SetItem (
153
+ activityName ,
133
154
sourceTable . AppendIteration (
134
155
sourceIteration . AppendBlock ( new BlockCache ( item ) ) ) ) ;
135
156
}
@@ -141,18 +162,17 @@ private IImmutableDictionary<TableIdentity, TableCache> AppendSourceBlock(
141
162
}
142
163
else
143
164
{
144
- throw new NotSupportedException ( "Table should come before block in logs" ) ;
165
+ throw new NotSupportedException ( "Activity should come before block in logs" ) ;
145
166
}
146
167
}
147
168
148
- private IImmutableDictionary < TableIdentity , TableCache > AppendSourceUrl (
149
- UrlRowItem item )
169
+ private IImmutableDictionary < string , ActivityCache > AppendSourceUrl ( UrlRowItem item )
150
170
{
151
- var tableId = item . SourceTable ;
171
+ var activityName = item . ActivityName ;
152
172
153
- if ( _sourceTableMap . ContainsKey ( tableId ) )
173
+ if ( _activityMap . ContainsKey ( activityName ) )
154
174
{
155
- var sourceTable = _sourceTableMap [ tableId ] ;
175
+ var sourceTable = _activityMap [ activityName ] ;
156
176
157
177
if ( sourceTable . IterationMap . ContainsKey ( item . IterationId ) )
158
178
{
@@ -162,8 +182,8 @@ private IImmutableDictionary<TableIdentity, TableCache> AppendSourceUrl(
162
182
{
163
183
var block = sourceIteration . BlockMap [ item . BlockId ] ;
164
184
165
- return _sourceTableMap . SetItem (
166
- tableId ,
185
+ return _activityMap . SetItem (
186
+ activityName ,
167
187
sourceTable . AppendIteration (
168
188
sourceIteration . AppendBlock (
169
189
block . AppendUrl ( new UrlCache ( item ) ) ) ) ) ;
@@ -180,7 +200,7 @@ private IImmutableDictionary<TableIdentity, TableCache> AppendSourceUrl(
180
200
}
181
201
else
182
202
{
183
- throw new NotSupportedException ( "Table should come before block in logs" ) ;
203
+ throw new NotSupportedException ( "Activity should come before block in logs" ) ;
184
204
}
185
205
}
186
206
}
0 commit comments