Skip to content

Commit 7beb501

Browse files
committed
move import models to FluentCommand.Import
1 parent 61aff94 commit 7beb501

33 files changed

+1042
-821
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ indent_style = space
99
indent_size = 4
1010
insert_final_newline = true
1111
trim_trailing_whitespace = true
12+
vsspell_section_id = main
13+
vsspell_ignored_words_main = File:dictionary.dic
1214

1315
# XML Configuration Files
1416
[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct,refactorlog,runsettings}]

FluentCommand.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# 17
3+
# Visual Studio Version 17
44
VisualStudioVersion = 17.3.32804.467
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentCommand", "src\FluentCommand\FluentCommand.csproj", "{4D5F125D-8DD5-496B-959E-78F55D8BE946}"
@@ -44,6 +44,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentCommand.Caching", "sr
4444
EndProject
4545
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentCommand.Csv", "src\FluentCommand.Csv\FluentCommand.Csv.csproj", "{FE8CBF1C-7231-4D26-A2DB-EDB0E7F29871}"
4646
EndProject
47+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCommand.Import", "src\FluentCommand.Import\FluentCommand.Import.csproj", "{76F06AA7-8F9E-4A8F-8569-579DC7855618}"
48+
EndProject
4749
Global
4850
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4951
Debug|Any CPU = Debug|Any CPU
@@ -102,6 +104,10 @@ Global
102104
{FE8CBF1C-7231-4D26-A2DB-EDB0E7F29871}.Debug|Any CPU.Build.0 = Debug|Any CPU
103105
{FE8CBF1C-7231-4D26-A2DB-EDB0E7F29871}.Release|Any CPU.ActiveCfg = Release|Any CPU
104106
{FE8CBF1C-7231-4D26-A2DB-EDB0E7F29871}.Release|Any CPU.Build.0 = Release|Any CPU
107+
{76F06AA7-8F9E-4A8F-8569-579DC7855618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
108+
{76F06AA7-8F9E-4A8F-8569-579DC7855618}.Debug|Any CPU.Build.0 = Debug|Any CPU
109+
{76F06AA7-8F9E-4A8F-8569-579DC7855618}.Release|Any CPU.ActiveCfg = Release|Any CPU
110+
{76F06AA7-8F9E-4A8F-8569-579DC7855618}.Release|Any CPU.Build.0 = Release|Any CPU
105111
EndGlobalSection
106112
GlobalSection(SolutionProperties) = preSolution
107113
HideSolutionNode = FALSE

dictionary.dic

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
accessor
2+
app
3+
awaitable
4+
cacheable
5+
clr
6+
csv
7+
deconstruct
8+
deserialization
9+
deserializer
10+
deserializing
11+
inline
12+
json
13+
linq
14+
middleware
15+
mvc
16+
nullable
17+
queryable
18+
serialization
19+
serializer
20+
upsert
21+
validator

src/FluentCommand.Csv/CsvCommandExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ await dataCommand.ReadAsync(
127127
commandBehavior: CommandBehavior.SequentialAccess | CommandBehavior.SingleResult,
128128
cancellationToken: cancellationToken);
129129

130-
await streamWriter.FlushAsync();
130+
await streamWriter.FlushAsync(cancellationToken);
131131
}
132132

133133

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace FluentCommand.Import.Converters;
6+
7+
/// <summary>
8+
/// A JSON converter for serializing and deserializing <see cref="Type"/> objects using assembly-qualified names.
9+
/// </summary>
10+
public class TypeJsonConverter : JsonConverter<Type>
11+
{
12+
/// <summary>
13+
/// Reads and converts the JSON string to a <see cref="Type"/> instance.
14+
/// </summary>
15+
/// <param name="reader">The reader.</param>
16+
/// <param name="typeToConvert">The type to convert.</param>
17+
/// <param name="options">The serializer options.</param>
18+
/// <returns>The <see cref="Type"/> instance, or <c>null</c> if not found.</returns>
19+
public override Type? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
20+
{
21+
var typeName = reader.GetString();
22+
if (string.IsNullOrWhiteSpace(typeName))
23+
return null;
24+
25+
// Try to resolve the type using assembly-qualified name first
26+
var type = Type.GetType(typeName, throwOnError: false);
27+
if (type != null)
28+
return type;
29+
30+
// Try to resolve by iterating loaded assemblies (for non-assembly-qualified names)
31+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
32+
{
33+
type = assembly.GetType(typeName, throwOnError: false);
34+
if (type != null)
35+
return type;
36+
}
37+
38+
return null;
39+
}
40+
41+
/// <summary>
42+
/// Writes the <see cref="Type"/> instance as an assembly-qualified name.
43+
/// </summary>
44+
/// <param name="writer">The writer.</param>
45+
/// <param name="value">The value.</param>
46+
/// <param name="options">The serializer options.</param>
47+
public override void Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options)
48+
{
49+
// Use AssemblyQualifiedName for more robust deserialization
50+
writer.WriteStringValue(value.AssemblyQualifiedName);
51+
}
52+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace FluentCommand.Import;
2+
3+
/// <summary>
4+
/// Specifies the default value behavior for a field during import operations.
5+
/// </summary>
6+
public enum FieldDefault
7+
{
8+
/// <summary>
9+
/// Use the current user's name as the default value for the field.
10+
/// </summary>
11+
UserName,
12+
/// <summary>
13+
/// Use the current UTC date and time as the default value for the field.
14+
/// </summary>
15+
CurrentDate,
16+
/// <summary>
17+
/// Use a static, predefined value as the default for the field.
18+
/// </summary>
19+
Static
20+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace FluentCommand.Import;
4+
5+
/// <summary>
6+
/// Represents the definition and configuration of a field for import operations.
7+
/// </summary>
8+
public class FieldDefinition
9+
{
10+
/// <summary>
11+
/// Gets or sets the display name of the field, used for UI or reporting purposes.
12+
/// </summary>
13+
[JsonPropertyName("displayName")]
14+
public string? DisplayName { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the unique name of the field.
18+
/// </summary>
19+
[JsonPropertyName("name")]
20+
public string Name { get; set; } = null!;
21+
22+
/// <summary>
23+
/// Gets or sets the data type of the field.
24+
/// </summary>
25+
[JsonPropertyName("dataType")]
26+
[JsonConverter(typeof(Converters.TypeJsonConverter))]
27+
public Type? DataType { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets a value indicating whether this field is a key field.
31+
/// </summary>
32+
/// <value>
33+
/// <c>true</c> if this field is a key; otherwise, <c>false</c>.
34+
/// </value>
35+
[JsonPropertyName("isKey")]
36+
public bool IsKey { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets a value indicating whether this field can be inserted during import. The default is <c>true</c>.
40+
/// </summary>
41+
/// <value>
42+
/// <c>true</c> if this field can be inserted; otherwise, <c>false</c>.
43+
/// </value>
44+
[JsonPropertyName("canInsert")]
45+
public bool CanInsert { get; set; } = true;
46+
47+
/// <summary>
48+
/// Gets or sets a value indicating whether this field can be updated during import. The default is <c>true</c>.
49+
/// </summary>
50+
/// <value>
51+
/// <c>true</c> if this field can be updated; otherwise, <c>false</c>.
52+
/// </value>
53+
[JsonPropertyName("canUpdate")]
54+
public bool CanUpdate { get; set; } = true;
55+
56+
/// <summary>
57+
/// Gets or sets a value indicating whether this field can be mapped by users during import configuration. The default is <c>true</c>.
58+
/// </summary>
59+
/// <value>
60+
/// <c>true</c> if this field can be mapped; otherwise, <c>false</c>.
61+
/// </value>
62+
[JsonPropertyName("canMap")]
63+
public bool CanMap { get; set; } = true;
64+
65+
/// <summary>
66+
/// Gets or sets a value indicating whether this field is required for import.
67+
/// </summary>
68+
/// <value>
69+
/// <c>true</c> if the field is required; otherwise, <c>false</c>.
70+
/// </value>
71+
[JsonPropertyName("isRequired")]
72+
public bool IsRequired { get; set; }
73+
74+
/// <summary>
75+
/// Gets or sets the default value behavior for the field during import.
76+
/// </summary>
77+
/// <value>
78+
/// The <see cref="FieldDefault"/> option specifying how the default value is determined.
79+
/// </value>
80+
[JsonPropertyName("default")]
81+
public FieldDefault? Default { get; set; }
82+
83+
/// <summary>
84+
/// Gets or sets the static default value for the field, used when <see cref="Default"/> is set to <see cref="FieldDefault.Static"/>.
85+
/// </summary>
86+
/// <value>
87+
/// The static default value for the field.
88+
/// </value>
89+
[JsonPropertyName("defaultValue")]
90+
public object? DefaultValue { get; set; }
91+
92+
/// <summary>
93+
/// Gets or sets the type of the field translator, used to transform or convert field values during import.
94+
/// </summary>
95+
/// <value>
96+
/// The <see cref="Type"/> of the field translator.
97+
/// </value>
98+
[JsonPropertyName("translator")]
99+
[JsonConverter(typeof(Converters.TypeJsonConverter))]
100+
public Type? Translator { get; set; }
101+
102+
/// <summary>
103+
/// Gets or sets the list of match expressions used for mapping or validation.
104+
/// </summary>
105+
/// <value>
106+
/// A list of string expressions for matching or validation.
107+
/// </value>
108+
[JsonPropertyName("expressions")]
109+
public List<string> Expressions { get; set; } = [];
110+
111+
/// <summary>
112+
/// Returns a string that represents the current <see cref="FieldDefinition"/> instance.
113+
/// </summary>
114+
/// <returns>
115+
/// A <see cref="string"/> that contains the display name, field name, and data type.
116+
/// </returns>
117+
public override string ToString()
118+
{
119+
return $"Display: {DisplayName}, Name: {Name}, DataType: {DataType?.Name}";
120+
}
121+
}

0 commit comments

Comments
 (0)