@@ -10,63 +10,77 @@ namespace KustoCopyConsole.Entity.InMemory
10
10
internal class RowItemInMemoryCache
11
11
{
12
12
private readonly object _lock = new object ( ) ;
13
- private volatile IImmutableDictionary < ( Uri , string ) , SourceDatabaseCache > _sourceDatabaseMap
14
- = ImmutableDictionary < ( Uri , string ) , SourceDatabaseCache > . Empty ;
13
+ private volatile IImmutableDictionary < TableIdentity , SourceTableCache > _sourceTableMap =
14
+ ImmutableDictionary < TableIdentity , SourceTableCache > . Empty ;
15
15
16
16
public RowItemInMemoryCache ( IEnumerable < RowItem > items )
17
17
{
18
18
lock ( _lock )
19
19
{
20
20
foreach ( var item in items )
21
21
{
22
- AddItem ( item ) ;
22
+ AppendItem ( item ) ;
23
23
}
24
24
}
25
25
}
26
26
27
- public IImmutableDictionary < ( Uri , string ) , SourceDatabaseCache > SoureDatabaseMap
28
- => _sourceDatabaseMap ;
27
+ public IImmutableDictionary < TableIdentity , SourceTableCache > SourceTableMap
28
+ => _sourceTableMap ;
29
29
30
30
public IEnumerable < RowItem > GetItems ( )
31
31
{
32
- throw new NotImplementedException ( ) ;
32
+ foreach ( var sourceTable in SourceTableMap . Values )
33
+ {
34
+ foreach ( var sourceTableIteration in sourceTable . IterationMap . Values )
35
+ {
36
+ yield return sourceTableIteration . RowItem ;
37
+ }
38
+ }
33
39
}
34
40
35
- public void AddItem ( RowItem item )
41
+ public void AppendItem ( RowItem item )
36
42
{
37
43
lock ( _lock )
38
44
{
39
45
if ( item . RowType != RowType . FileVersion && item . RowType != RowType . Unspecified )
40
46
{
41
47
Interlocked . Exchange (
42
- ref _sourceDatabaseMap ,
43
- AddItemToCache ( item ) ) ;
48
+ ref _sourceTableMap ,
49
+ AppendItemToCache ( item ) ) ;
44
50
}
45
51
}
46
52
}
47
53
48
- private IImmutableDictionary < ( Uri , string ) , SourceDatabaseCache > AddItemToCache ( RowItem item )
54
+ private IImmutableDictionary < TableIdentity , SourceTableCache > AppendItemToCache (
55
+ RowItem item )
49
56
{
50
57
switch ( item . RowType )
51
58
{
52
- case RowType . SourceDatabase :
53
- return AddSourceDatabase ( item ) ;
59
+ case RowType . SourceTable :
60
+ return AppendSourceTable ( item ) ;
54
61
default :
55
62
throw new NotSupportedException ( $ "Not supported row type: { item . RowType } ") ;
56
63
}
57
64
}
58
65
59
- private IImmutableDictionary < ( Uri , string ) , SourceDatabaseCache > AddSourceDatabase ( RowItem item )
66
+ private IImmutableDictionary < TableIdentity , SourceTableCache > AppendSourceTable (
67
+ RowItem item )
60
68
{
61
- var key = ( NormalizedUri . NormalizeUri ( item . SourceClusterUri ) , item . SourceDatabaseName ) ;
69
+ //item.IterationId!.Value
70
+ var tableId = new TableIdentity (
71
+ NormalizedUri . NormalizeUri ( item . SourceClusterUri ) ,
72
+ item . SourceDatabaseName ,
73
+ item . SourceTableName ) ;
62
74
63
- if ( _sourceDatabaseMap . ContainsKey ( key ) )
75
+ if ( _sourceTableMap . ContainsKey ( tableId ) )
64
76
{
65
- return _sourceDatabaseMap . SetItem ( key , new SourceDatabaseCache ( item ) ) ;
77
+ return _sourceTableMap . SetItem (
78
+ tableId ,
79
+ _sourceTableMap [ tableId ] . AppendIteration ( item ) ) ;
66
80
}
67
81
else
68
82
{
69
- return _sourceDatabaseMap . Add ( key , new SourceDatabaseCache ( item ) ) ;
83
+ return _sourceTableMap . Add ( tableId , new SourceTableCache ( item ) ) ;
70
84
}
71
85
}
72
86
}
0 commit comments