/// <summary> /// Gets a file engine. /// </summary> /// <param name="engineFactory">The engine factory.</param> /// <param name="recordTypes">The record types.</param> /// <param name="typeSelectorFunc">The type selector function.</param> /// <param name="handleEntryReadError">The error handler.</param> /// <param name="masterDetailStrategy">Determines how master-detail record relationships are handled.</param> /// <returns>IFlatFileMultiEngine.</returns> public static IFlatFileMultiEngine GetEngine( this DelimitedFileEngineFactory engineFactory, IEnumerable <Type> recordTypes, Func <string, int, Type> typeSelectorFunc, FileReadErrorHandler handleEntryReadError = null, IMasterDetailStrategy masterDetailStrategy = null) { var descriptorProvider = new DelimitedLayoutDescriptorProvider(); var descriptors = recordTypes.Select(type => descriptorProvider.GetDescriptor(type)).ToList(); return(engineFactory.GetEngine(descriptors, typeSelectorFunc, handleEntryReadError, masterDetailStrategy)); }
/// <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> /// <param name="masterDetailStrategy">Determines how master-detail record relationships are handled.</param> /// <returns>IFlatFileMultiEngine.</returns> public IFlatFileMultiEngine GetEngine( IEnumerable <IFixedLengthLayoutDescriptor> layoutDescriptors, Func <string, int, Type> typeSelectorFunc, FileReadErrorHandler handleEntryReadError = null, IMasterDetailStrategy masterDetailStrategy = null) { return(new FixedLengthFileMultiEngine( layoutDescriptors, typeSelectorFunc, new FixedLengthLineBuilderFactory(), lineParserFactory, masterDetailStrategy ?? new DefaultFixedLengthMasterDetailStrategy(), handleEntryReadError)); }
/// <summary> /// Initializes a new instance of the <see cref="FixedLengthFileMultiEngine"/> class. /// </summary> /// <param name="layoutDescriptors">The layout descriptors.</param> /// <param name="typeSelector">The type selector function.</param> /// <param name="lineBuilderFactory">The line builder factory.</param> /// <param name="lineParserFactory">The line parser factory.</param> /// <param name="masterDetailStrategy">Determines how master-detail record relationships are handled.</param> /// <param name="handleEntryReadError">The handle entry read error.</param> /// <exception cref="System.ArgumentNullException">typeSelectorFunc</exception> internal FixedLengthFileMultiEngine( IEnumerable <IFixedLengthLayoutDescriptor> layoutDescriptors, Func <string, int, Type> typeSelector, IFixedLengthLineBuilderFactory lineBuilderFactory, IFixedLengthLineParserFactory lineParserFactory, IMasterDetailStrategy masterDetailStrategy, FileReadErrorHandler?handleEntryReadError = null) : base(layoutDescriptors, handleEntryReadError) { _layoutDescriptors = layoutDescriptors.Select(ld => new FixedLengthImmutableLayoutDescriptor(ld)) .Cast <IFixedLengthLayoutDescriptor>() .ToDictionary(ld => ld.TargetType, ld => ld); _typeSelector = typeSelector ?? throw new ArgumentNullException(nameof(typeSelector)); _lineBuilderFactory = lineBuilderFactory ?? throw new ArgumentNullException(nameof(lineBuilderFactory)); _lineParserFactory = lineParserFactory ?? throw new ArgumentNullException(nameof(lineParserFactory)); _masterDetailStrategy = masterDetailStrategy ?? throw new ArgumentNullException(nameof(masterDetailStrategy)); }