Skip to content

Commit 764d6cf

Browse files
committed
.
1 parent 5b6afc4 commit 764d6cf

23 files changed

+169
-358
lines changed

code/KustoCopyConsole/Entity/DatabaseReference.cs

-21
This file was deleted.

code/KustoCopyConsole/Entity/DestinationBlockEntity.cs

-26
This file was deleted.

code/KustoCopyConsole/Entity/State/DestinationBlockState.cs code/KustoCopyConsole/Entity/DestinationBlockState.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace KustoCopyConsole.Entity.State
1+
namespace KustoCopyConsole.Entity
22
{
33
public enum DestinationBlockState
44
{

code/KustoCopyConsole/Entity/DestinationDatabaseEntity.cs

-14
This file was deleted.

code/KustoCopyConsole/Entity/DestinationDatabaseEntityBase.cs

-19
This file was deleted.

code/KustoCopyConsole/Entity/State/DestinationDatabaseState.cs code/KustoCopyConsole/Entity/DestinationDatabaseState.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace KustoCopyConsole.Entity.State
1+
namespace KustoCopyConsole.Entity
22
{
33
public enum DestinationDatabaseState
44
{

code/KustoCopyConsole/Entity/DestinationTableEntity.cs

-21
This file was deleted.

code/KustoCopyConsole/Entity/State/DestinationTableState.cs code/KustoCopyConsole/Entity/DestinationTableState.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace KustoCopyConsole.Entity.State
1+
namespace KustoCopyConsole.Entity
22
{
33
public enum DestinationTableState
44
{

code/KustoCopyConsole/Entity/State/IRowItemSerializable.cs code/KustoCopyConsole/Entity/IRowItemSerializable.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace KustoCopyConsole.Entity.State
7+
namespace KustoCopyConsole.Entity
88
{
99
internal interface IRowItemSerializable
1010
{

code/KustoCopyConsole/Entity/IterationEntityBase.cs

-38
This file was deleted.
+141-11
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,173 @@
1-
using CsvHelper.Configuration.Attributes;
2-
using KustoCopyConsole.Entity.State;
1+
using CsvHelper.Configuration;
2+
using CsvHelper;
3+
using CsvHelper.Configuration.Attributes;
4+
using CsvHelper.TypeConversion;
5+
using KustoCopyConsole.Entity;
36
using System;
47
using System.Collections.Generic;
58
using System.Linq;
69
using System.Text;
710
using System.Threading.Tasks;
11+
using System.Text.Json.Serialization;
12+
using System.Text.Json;
813

914
namespace KustoCopyConsole.Entity
1015
{
1116
internal class RowItem
1217
{
18+
#region Inner types
19+
private class RowTypeConverter : DefaultTypeConverter
20+
{
21+
public override object? ConvertFromString(
22+
string? text,
23+
IReaderRow row,
24+
MemberMapData memberMapData)
25+
{
26+
if (string.IsNullOrWhiteSpace(text))
27+
{
28+
return RowType.Unspecified;
29+
}
30+
else
31+
{
32+
try
33+
{
34+
var state = RowType.Parse<RowType>(text);
35+
36+
return state;
37+
}
38+
catch (Exception ex)
39+
{
40+
throw new CopyException($"Can't deserialize row type: '{text}'", false, ex);
41+
}
42+
}
43+
}
44+
45+
public override string? ConvertToString(
46+
object? value,
47+
IWriterRow row,
48+
MemberMapData memberMapData)
49+
{
50+
if (value != null)
51+
{
52+
var text = value.ToString();
53+
54+
return text;
55+
}
56+
else
57+
{
58+
return string.Empty;
59+
}
60+
}
61+
}
62+
#endregion
63+
64+
#region Data
1365
[Index(0)]
1466
public string FileVersion { get; set; } = string.Empty;
1567

1668
[Index(1)]
17-
public DateTime? Created { get; set; }
69+
public DateTime? Created { get; set; } = DateTime.Now;
1870

1971
[Index(2)]
20-
public DateTime? Updated { get; set; }
72+
public DateTime? Updated { get; set; } = DateTime.Now;
2173

2274
[Index(3)]
23-
public string State { get; set; } = string.Empty;
75+
[TypeConverter(typeof(RowTypeConverter))]
76+
public RowType RowType { get; set; } = RowType.Unspecified;
2477

2578
[Index(4)]
26-
public string SourceClusterUri { get; set; } = string.Empty;
79+
public string State { get; set; } = string.Empty;
2780

2881
[Index(5)]
29-
public string SourceDatabaseName { get; set; } = string.Empty;
82+
public string SourceClusterUri { get; set; } = string.Empty;
3083

3184
[Index(6)]
32-
public long? IterationId { get; set; }
85+
public string SourceDatabaseName { get; set; } = string.Empty;
3386

3487
[Index(7)]
35-
public string CursorStart { get; set; } = string.Empty;
88+
public string DestinationClusterUri { get; set; } = string.Empty;
3689

3790
[Index(8)]
38-
public string CursorEnd { get; set; } = string.Empty;
91+
public string DestinationDatabaseName { get; set; } = string.Empty;
3992

4093
[Index(9)]
41-
public string SourceTableName { get; set; } = string.Empty;
94+
public string TableName { get; set; } = string.Empty;
95+
96+
[Index(10)]
97+
public long? IterationId { get; set; }
98+
99+
[Index(11)]
100+
public string CursorStart { get; set; } = string.Empty;
101+
102+
[Index(12)]
103+
public string CursorEnd { get; set; } = string.Empty;
104+
105+
[Index(13)]
106+
public long? BlockId { get; set; }
107+
#endregion
108+
109+
public T ParseState<T>() where T : struct
110+
{
111+
try
112+
{
113+
return Enum.Parse<T>(State);
114+
}
115+
catch (Exception ex)
116+
{
117+
throw new CopyException($"Invalid state: '{State}'", false, ex);
118+
}
119+
}
120+
121+
public void Validate()
122+
{
123+
if (RowType == RowType.Unspecified)
124+
{
125+
throw new CopyException("Invalid row type", false);
126+
}
127+
ValidateProperty(
128+
nameof(FileVersion),
129+
string.IsNullOrWhiteSpace(FileVersion),
130+
RowType != RowType.FileVersion);
131+
ValidateProperty(
132+
nameof(Created),
133+
Created == null,
134+
false);
135+
ValidateProperty(
136+
nameof(Updated),
137+
Created == null,
138+
false);
139+
ValidateProperty(
140+
nameof(State),
141+
string.IsNullOrWhiteSpace(State),
142+
RowType == RowType.FileVersion);
143+
}
144+
145+
public RowItem Clone()
146+
{
147+
var clone = (RowItem)MemberwiseClone();
148+
149+
clone.Updated = DateTime.Now;
150+
151+
return clone;
152+
}
153+
154+
private void ValidateProperty(
155+
string propertyName,
156+
bool isNull,
157+
bool shouldBeNull)
158+
{
159+
if (isNull && !shouldBeNull)
160+
{
161+
throw new CopyException(
162+
$"{propertyName} doesn't have value but should",
163+
false);
164+
}
165+
if (!isNull && shouldBeNull)
166+
{
167+
throw new CopyException(
168+
$"{propertyName} has value but should not",
169+
false);
170+
}
171+
}
42172
}
43173
}

0 commit comments

Comments
 (0)