Esempio n. 1
0
        /// <summary>
        /// Write the in memory queues to the disk.
        /// </summary>
        /// <param name="frontierTime">Current foremost tick time</param>
        /// <param name="finalFlush">Indicates is this is the final push to disk at the end of the data</param>
        public void FlushBuffer(DateTime frontierTime, bool finalFlush)
        {
            //Force the consolidation if time has past the bar
            _consolidator.Scan(frontierTime);

            // If this is the final packet dump it to the queue
            if (finalFlush && _consolidator.WorkingData != null)
            {
                _queue.Enqueue(_consolidator.WorkingData);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception><filterpriority>2</filterpriority>
        public bool MoveNext()
        {
            if (!_queue.TryDequeue(out _current) && _isPeriodBase)
            {
                _consolidated = false;
                lock (_consolidator)
                {
                    // if there is a working bar we will try to pull it out if the time is right, each consolidator knows when it's right
                    var localTime = _timeProvider.GetUtcNow().ConvertFromUtc(_timeZone);
                    _consolidator.Scan(localTime);
                }

                if (_consolidated)
                {
                    _queue.TryDequeue(out _current);
                }
            }

            // even if we don't have data to return, we haven't technically
            // passed the end of the collection, so always return true until
            // the enumerator is explicitly disposed or ended
            return(true);
        }
        /// <summary>
        /// Write the in memory queues to the disk.
        /// </summary>
        /// <param name="frontierTime">Current foremost tick time</param>
        /// <param name="finalFlush">Indicates is this is the final push to disk at the end of the data</param>
        public void FlushBuffer(DateTime frontierTime, bool finalFlush)
        {
            //Force the consolidation if time has past the bar
            _consolidator.Scan(frontierTime);

            // If this is the final packet dump it to the queue
            if (finalFlush)
            {
                if (_consolidator.WorkingData != null)
                {
                    _streamWriter.WriteLine(LeanData.GenerateLine(_consolidator.WorkingData, SecurityType.Future, Resolution));
                }

                _streamWriter.Flush();
                _streamWriter.Close();
                _streamWriter = null;

                Interlocked.Add(ref _curFileCount, -1);
                if (_curFileCount % 1000 == 0)
                {
                    Log.Trace("Closed some files: {0}", _curFileCount);
                }
            }
        }