コード例 #1
0
 /// <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;
 }
コード例 #2
0
 /// <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;
 }
コード例 #3
0
 /// <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));
 }
コード例 #4
0
        /// <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));
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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));
        }
コード例 #7
0
        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
        }
コード例 #8
0
 /// <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);
 }
コード例 #9
0
 /// <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);
 }
コード例 #10
0
 public FixedLengthLineBuilder(ILayoutDescriptor <IFixedFieldSettingsContainer> descriptor)
     : base(descriptor)
 {
 }
コード例 #11
0
 public FixedLengthLineParser(ILayoutDescriptor <IFixedFieldSettingsContainer> layout)
     : base(layout)
 {
 }
コード例 #12
0
 public IFixedLengthLineBuilder GetBuilder(ILayoutDescriptor<IFixedFieldSettingsContainer> descriptor)
 {
     return new FixedLengthLineBuilder(descriptor);
 }
コード例 #13
0
 public IFixedLengthLineBuilder GetBuilder(ILayoutDescriptor <IFixedFieldSettingsContainer> descriptor)
 {
     return(new FixedLengthLineBuilder(descriptor));
 }