/// <summary> /// Initializes a new instance of <see cref="ImmutableLayoutDescriptor{TFieldSettings}"/> by copying another /// <see cref="ILayoutDescriptor{TFieldSettings}"/>. /// </summary> /// <param name="existing">The descriptor to copy.</param> protected ImmutableLayoutDescriptor(ILayoutDescriptor <TFieldSettings> existing) { TargetType = existing.TargetType; Fields = existing.Fields.ToList(); HasHeader = existing.HasHeader; InstanceFactory = existing.InstanceFactory; }
/// <summary> /// Initializes a new instance of the <see cref="FixedLengthFileEngine"/> class. /// </summary> /// <param name="layoutDescriptor">The layout descriptor.</param> /// <param name="lineBuilderFactory">The line builder factory.</param> /// <param name="lineParserFactory">The line parser factory.</param> /// <param name="handleEntryReadError">The handle entry read error.</param> internal FixedLengthFileEngine( ILayoutDescriptor <IFixedFieldSettingsContainer> layoutDescriptor, IFixedLengthLineBuilderFactory lineBuilderFactory, IFixedLengthLineParserFactory lineParserFactory, Func <string, Exception, bool> handleEntryReadError = null) : base(handleEntryReadError) { this.lineBuilderFactory = lineBuilderFactory; this.lineParserFactory = lineParserFactory; this.layoutDescriptor = layoutDescriptor; }
/// <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, handleEntryReadError)); }
/// <summary> /// Gets the parser. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns>IFixedLengthLineParser.</returns> public IFixedLengthLineParser GetParser(ILayoutDescriptor <IFixedFieldSettingsContainer> descriptor) { if (descriptor == null) { throw new ArgumentNullException("descriptor"); } return(descriptor.TargetType != null && lineParserRegistry.ContainsKey(descriptor.TargetType) ? (IFixedLengthLineParser)ReflectionHelper.CreateInstance(lineParserRegistry[descriptor.TargetType], true, descriptor) : new FixedLengthLineParser(descriptor)); }
/// <summary> /// Internal private file responsible to read records of historic quotes from stream /// </summary> /// <param name="streamToRead">Stream to read records from</param> /// <returns> /// All historic quotes found in the stream /// </returns> private B3HistoricMarketDataContentInfo ReadStream(Stream streamToRead) { B3HistoricMarketDataContentInfo resultado = null; // var factory = new FixedLengthFileEngineFactory(); // If using attribute mapping, pass an array of record types // rather than layout instances var layouts = new ILayoutDescriptor <IFixedFieldSettingsContainer>[] { new B3COTAHISTHeaderLayout() , new B3COTAHISTHistoricoLayout() , new B3COTAHISTTrailerLayout() }; var flatFile = factory.GetEngine(layouts, (line, lineNumber) => { // For each line, return the proper record type. // The mapping for this line will be loaded based on that type. // In this simple example, the first character determines the // record type. if (string.IsNullOrEmpty(line) || line.Length < 1) { return(null); } switch (line.Substring(0, 2)) { case "00": return(typeof(B3HistoricMarketDataHeaderInfo)); case "01": return(typeof(B3HistoricMarketDataInfo)); case "99": return(typeof(B3HistoricMarketDataTrailerInfo)); } return(null); }); flatFile.Read(streamToRead); resultado = new B3HistoricMarketDataContentInfo(); resultado.Header = flatFile.GetRecords <B3HistoricMarketDataHeaderInfo>().FirstOrDefault(); resultado.Records = flatFile.GetRecords <B3HistoricMarketDataInfo>().ToList(); resultado.Trailer = flatFile.GetRecords <B3HistoricMarketDataTrailerInfo>().FirstOrDefault(); return(resultado); }
/// <summary> /// Gets the parser. /// </summary> /// <param name="descriptor">The descriptor.</param> /// <returns>IFixedLengthLineParser.</returns> public IDelimitedLineParser GetParser(ILayoutDescriptor <IDelimitedFieldSettingsContainer> descriptor) { if (descriptor == null) { throw new ArgumentNullException("descriptor"); } if (!(descriptor is IDelimitedLayoutDescriptor)) { throw new ArgumentException("descriptor must be IDelimitedLayoutDescriptor"); } return(descriptor.TargetType != null && lineParserRegistry.ContainsKey(descriptor.TargetType) ? (IDelimitedLineParser)ReflectionHelper.CreateInstance(lineParserRegistry[descriptor.TargetType], true, descriptor) : new DelimitedLineParser((IDelimitedLayoutDescriptor)descriptor)); }
public LayoutParser() { this.Encoding = Encoding.Default; var factory = new FixedLengthFileEngineFactory(); var layouts = new ILayoutDescriptor <IFixedFieldSettingsContainer>[] { new T0HeaderLayout(), new T1ResumoLayout(), new T2EnderecoLayout(), new T3BilheteLayout(), new T4ServicoLayout(), new T5DescontoLayout(), new T9TrailerLayout(), }; this.reader = (FixedLengthFileMultiEngine)factory.GetEngine(layouts, ChooseLayout); // while Read(StreamWriter) is not exposed in the interface }
/// <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> /// 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> public void RegisterLineParser <TParser>(ILayoutDescriptor <IFieldSettings> targetLayout) where TParser : IDelimitedLineParser { _parserRegistry[targetLayout.TargetType] = typeof(TParser); }
public FixedLengthLineBuilder(ILayoutDescriptor <IFixedFieldSettingsContainer> descriptor) : base(descriptor) { }
public FixedLengthLineParser(ILayoutDescriptor <IFixedFieldSettingsContainer> layout) : base(layout) { }
public IFixedLengthLineBuilder GetBuilder(ILayoutDescriptor<IFixedFieldSettingsContainer> descriptor) { return new FixedLengthLineBuilder(descriptor); }
public IFixedLengthLineBuilder GetBuilder(ILayoutDescriptor <IFixedFieldSettingsContainer> descriptor) { return(new FixedLengthLineBuilder(descriptor)); }