-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
238 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using KustoCopyConsole.Entity.RowItems; | ||
using KustoCopyConsole.Entity.State; | ||
using System.Collections.Immutable; | ||
|
||
namespace KustoCopyConsole.Entity.InMemory | ||
{ | ||
internal class SourceBlockCache : CacheBase<SourceBlockRowItem> | ||
{ | ||
private SourceBlockCache(SourceBlockRowItem item, IImmutableList<SourceUrlCache> urls) | ||
: base(item) | ||
{ | ||
Urls = urls; | ||
} | ||
|
||
public SourceBlockCache(SourceBlockRowItem item) | ||
: this(item, ImmutableArray<SourceUrlCache>.Empty) | ||
{ | ||
} | ||
|
||
public IImmutableList<SourceUrlCache> Urls { get; } | ||
|
||
public SourceBlockCache AppendUrl(SourceUrlCache url) | ||
{ | ||
var existingUrlCache = Urls | ||
.Where(u => u.RowItem.Url == url.RowItem.Url) | ||
.FirstOrDefault(); | ||
|
||
if (existingUrlCache != null) | ||
{ | ||
var newUrls = Urls.Remove(existingUrlCache); | ||
|
||
if (url.RowItem.State != SourceUrlState.Deleted) | ||
{ | ||
newUrls = newUrls.Add(url); | ||
} | ||
|
||
return new SourceBlockCache(RowItem, newUrls); | ||
} | ||
else | ||
{ | ||
var newUrls = Urls.Add(url); | ||
|
||
return new SourceBlockCache(RowItem, newUrls); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
code/KustoCopyConsole/Entity/InMemory/SourceIterationCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using KustoCopyConsole.Entity.RowItems; | ||
using System.Collections.Immutable; | ||
|
||
namespace KustoCopyConsole.Entity.InMemory | ||
{ | ||
internal class SourceIterationCache : CacheBase<SourceTableRowItem> | ||
{ | ||
private SourceIterationCache( | ||
SourceTableRowItem item, | ||
IImmutableDictionary<long, SourceBlockCache> blockMap) | ||
: base(item) | ||
{ | ||
BlockMap = blockMap; | ||
} | ||
|
||
public SourceIterationCache(SourceTableRowItem item) | ||
: this(item, ImmutableDictionary<long, SourceBlockCache>.Empty) | ||
{ | ||
} | ||
|
||
public IImmutableDictionary<long, SourceBlockCache> BlockMap { get; } | ||
|
||
public SourceIterationCache AppendBlock(SourceBlockCache block) | ||
{ | ||
var newBlockMap = BlockMap.SetItem(block.RowItem.BlockId, block); | ||
|
||
return new SourceIterationCache(RowItem, newBlockMap); | ||
} | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
code/KustoCopyConsole/Entity/InMemory/SourceTableBlockCache.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
code/KustoCopyConsole/Entity/InMemory/SourceTableIterationCache.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using KustoCopyConsole.Entity.RowItems; | ||
using System.Collections.Immutable; | ||
|
||
namespace KustoCopyConsole.Entity.InMemory | ||
{ | ||
internal class SourceUrlCache : CacheBase<SourceUrlRowItem> | ||
{ | ||
public SourceUrlCache(SourceUrlRowItem item) | ||
: base(item) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using KustoCopyConsole.Entity.State; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace KustoCopyConsole.Entity.RowItems | ||
{ | ||
internal class SourceUrlRowItem : RowItemBase | ||
{ | ||
public SourceUrlState State { get; set; } | ||
|
||
public TableIdentity SourceTable { get; set; } = TableIdentity.Empty; | ||
|
||
public long IterationId { get; set; } | ||
|
||
public long BlockId { get; set; } | ||
|
||
public string Url { get; set; } = string.Empty; | ||
|
||
public override void Validate() | ||
{ | ||
SourceTable.Validate(); | ||
if (IterationId < 1) | ||
{ | ||
throw new InvalidDataException( | ||
$"{nameof(IterationId)} should be positive but is {IterationId}"); | ||
} | ||
if (BlockId < 1) | ||
{ | ||
throw new InvalidDataException( | ||
$"{nameof(BlockId)} should be positive but is {BlockId}"); | ||
} | ||
if (!Uri.TryCreate(Url, UriKind.Absolute, out _)) | ||
{ | ||
throw new InvalidDataException($"{nameof(Url)} is invalid: {Url}"); | ||
} | ||
} | ||
|
||
public SourceUrlRowItem ChangeState(SourceUrlState newState) | ||
{ | ||
var clone = (SourceUrlRowItem)Clone(); | ||
|
||
clone.State = newState; | ||
|
||
return clone; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.