Exemple #1
0
        public int ProcessBatch(IEnumerable <IEnumerable <string> > buffer, int batchSize, ScheduleType scheduleType,
                                BatchArgs batchArgs)
        {
            if (_reader == null)
            {
                throw new InvalidOperationException("CifParser not initialized");
            }
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (batchSize < 1)
            {
                throw new ArgumentException("batchSize must be greater than zero", nameof(batchSize));
            }

            IEnumerable <CifRecordBase> recordDefs     = _recordDefFactory.GetRecordDefs(scheduleType);
            List <List <string> >       internalBuffer = new List <List <string> >();

            string        line       = null;
            List <string> lineValues = new List <string>();

            do
            {
                line = _reader.ReadLine();
                if (line == null)
                {
                    continue;
                }

                lineValues = ParseLine(line, recordDefs);
                if (lineValues.Count > 0)
                {
                    internalBuffer.Add(lineValues);
                }
            } while (line != null && internalBuffer.Count < batchSize);

            ((List <List <string> >)buffer).Clear();
            ((List <List <string> >)buffer).AddRange(internalBuffer);

            return(internalBuffer.Count);
        }
Exemple #2
0
        public long Process(string filename, string outputLocation, int batchSize, string scheduleType,
                            BatchArgs args)
        {
            if (filename == null)
            {
                throw new ArgumentNullException(filename);
            }
            if (outputLocation == null)
            {
                throw new ArgumentNullException(outputLocation);
            }
            if (scheduleType == null)
            {
                throw new ArgumentNullException(scheduleType);
            }

            List <List <string> > buffer = new List <List <string> >();
            long batchCount  = 0;
            long recordCount = 0;

            ScheduleType scheduleTypeEnum = GetScheduleType(scheduleType);

            _outputWriter.Open(outputLocation, scheduleTypeEnum);
            _cifProcessor.Initialize(_fileSystem.FileOpen(filename, FileMode.Open));

            int bufferCount = 0;

            while ((bufferCount = _cifProcessor.ProcessBatch(buffer, batchSize, scheduleTypeEnum, args)) > 0)
            {
                batchCount++;
                recordCount += bufferCount;
                _outputWriter.Write(buffer);
                OnBatchProcessed(
                    new BatchProcessedEventArgs {
                    BatchNumber = batchCount, BatchSize = bufferCount
                });
            }

            _outputWriter.Close();
            return(recordCount);
        }
Exemple #3
0
        public int ProcessBatch(IEnumerable <IEnumerable <string> > buffer, int batchSize, ScheduleType scheduleType,
                                BatchArgs batchArgs)
        {
            if (_reader == null)
            {
                throw new InvalidOperationException("CifEditor not initialized");
            }
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (batchArgs == null)
            {
                throw new ArgumentNullException(nameof(batchArgs));
            }

            _scheduleCriteria = GetScheduleCriteria(batchArgs);

            IEnumerable <CifRecordBase> recordDefs = _recordDefFactory.GetRecordDefs(scheduleType);

            _buffer = new List <string>();

            return(DoProcessBatch(buffer, batchSize, recordDefs));
        }
Exemple #4
0
 private IList <ScheduleCriteria> GetScheduleCriteria(BatchArgs batchArgs)
 {
     return(batchArgs?.ScheduleCriteria?.ToList() ?? new List <ScheduleCriteria>());
 }