-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathFixedLengthFileEngineFactory.cs
More file actions
112 lines (104 loc) · 4.9 KB
/
FixedLengthFileEngineFactory.cs
File metadata and controls
112 lines (104 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.Collections.Generic;
using FlatFile.Core.Base;
namespace FlatFile.FixedLength.Implementation
{
using System;
using FlatFile.Core;
/// <summary>
/// Class FixedLengthFileEngineFactory.
/// </summary>
public class FixedLengthFileEngineFactory : IFlatFileEngineFactory<ILayoutDescriptor<IFixedFieldSettingsContainer>, IFixedFieldSettingsContainer>
{
readonly FixedLengthLineParserFactory lineParserFactory = new FixedLengthLineParserFactory();
/// <summary>
/// Registers the line parser <typeparamref name="TParser" /> for lines matching <paramref name="targetType" />.
/// </summary>
/// <typeparam name="TParser">The type of the t parser.</typeparam>
/// <param name="targetType">The target record type.</param>
/// <exception cref="System.NotImplementedException"></exception>
public void RegisterLineParser<TParser>(Type targetType) where TParser : IFixedLengthLineParser
{
lineParserFactory.RegisterLineParser<TParser>(targetType);
}
/// <summary>
/// Registers the line parser <typeparamref name="TParser" /> for lines matching <paramref name="targetLayout" />.
/// </summary>
/// <typeparam name="TParser">The type of the t parser.</typeparam>
/// <param name="targetLayout">The target layout.</param>
/// <exception cref="System.NotImplementedException"></exception>
public void RegisterLineParser<TParser>(ILayoutDescriptor<IFieldSettings> targetLayout) where TParser : IFixedLengthLineParser
{
lineParserFactory.RegisterLineParser<TParser>(targetLayout);
}
/// <summary>
/// Gets the <see cref="IFlatFileEngine" />.
/// </summary>
/// <param name="descriptor">The descriptor.</param>
/// <param name="handleEntryReadError">The handle entry read error func.</param>
/// <returns>IFlatFileEngine.</returns>
public IFlatFileEngine GetEngine(
ILayoutDescriptor<IFixedFieldSettingsContainer> descriptor,
Func<string, Exception, bool> handleEntryReadError = null)
{
return new FixedLengthFileEngine(
descriptor,
new FixedLengthLineBuilderFactory(),
lineParserFactory,
ctx => handleEntryReadError(ctx.Line, ctx.Exception));
}
/// <summary>
/// Gets the <see cref="IFlatFileEngine" />.
/// </summary>
/// <param name="descriptor">The descriptor.</param>
/// <param name="handleEntryReadError">The handle entry read error func.</param>
/// <returns>IFlatFileEngine.</returns>
public IFlatFileEngine GetEngine(
ILayoutDescriptor<IFixedFieldSettingsContainer> descriptor,
Func<FlatFileErrorContext, bool> handleEntryReadError)
{
return new FixedLengthFileEngine(
descriptor,
new FixedLengthLineBuilderFactory(),
lineParserFactory,
handleEntryReadError);
}
/// <summary>
/// Gets the <see cref="IFlatFileMultiEngine"/>.
/// </summary>
/// <param name="layoutDescriptors">The layout descriptors.</param>
/// <param name="typeSelectorFunc">The type selector function.</param>
/// <param name="handleEntryReadError">The handle entry read error func.</param>
/// <returns>IFlatFileMultiEngine.</returns>
public IFlatFileMultiEngine GetEngine(
IEnumerable<ILayoutDescriptor<IFixedFieldSettingsContainer>> layoutDescriptors,
Func<string, int, Type> typeSelectorFunc,
Func<string, Exception, bool> handleEntryReadError = null)
{
return new FixedLengthFileMultiEngine(
layoutDescriptors,
typeSelectorFunc,
new FixedLengthLineBuilderFactory(),
lineParserFactory,
ctx => handleEntryReadError(ctx.Line, ctx.Exception));
}
/// <summary>
/// Gets the <see cref="IFlatFileMultiEngine"/>.
/// </summary>
/// <param name="layoutDescriptors">The layout descriptors.</param>
/// <param name="typeSelectorFunc">The type selector function.</param>
/// <param name="handleEntryReadError">The handle entry read error func.</param>
/// <returns>IFlatFileMultiEngine.</returns>
public IFlatFileMultiEngine GetEngine(
IEnumerable<ILayoutDescriptor<IFixedFieldSettingsContainer>> layoutDescriptors,
Func<string, int, Type> typeSelectorFunc,
Func<FlatFileErrorContext, bool> handleEntryReadError)
{
return new FixedLengthFileMultiEngine(
layoutDescriptors,
typeSelectorFunc,
new FixedLengthLineBuilderFactory(),
lineParserFactory,
handleEntryReadError);
}
}
}