public UpdateCacheCommandHandler(
     IAsyncLogProvider owner,
     LJTraceSource tracer,
     MessagesContainers.RangesManagingCollection buffer,
     Settings.IGlobalSettingsAccessor settingsAccessor
     )
 {
     this.owner            = owner;
     this.buffer           = buffer;
     this.tracer           = tracer;
     this.settingsAccessor = settingsAccessor;
 }
        void UpdateLoadedTimeStats(IPositionedMessagesReader reader)
        {
            MessagesContainers.RangesManagingCollection tmp = buffer;

            tracer.Info("Current messages: {0}", tmp);

            long bytesCount = 0;

            foreach (MessagesContainers.MessagesRange lr in tmp.Ranges)
            {
                bytesCount += reader.PositionRangeToBytes(lr.LoadedRange);
            }

            DateRange loadedTime;
            int       c = tmp.Count;

            if (c != 0)
            {
                DateTime begin = new DateTime();
                DateTime end   = new DateTime();
                foreach (IndexedMessage l in tmp.Forward(0, 1))
                {
                    tracer.Info("First message: {0}, {1}", l.Message.Time, l.Message.Text);
                    begin = l.Message.Time.ToLocalDateTime();
                }
                foreach (IndexedMessage l in tmp.Reverse(c - 1, c - 2))
                {
                    tracer.Info("Last message: {0}, {1}", l.Message.Time, l.Message.Text);
                    end = l.Message.Time.ToLocalDateTime();
                }
                loadedTime = DateRange.MakeFromBoundaryValues(begin, end);
            }
            else
            {
                loadedTime = DateRange.MakeEmpty();
            }

            tracer.Info("Calculated statistics: LoadedTime={0}, BytesLoaded={1}", loadedTime, bytesCount);

            owner.StatsTransaction(stats =>
            {
                stats.LoadedTime  = loadedTime;
                stats.LoadedBytes = bytesCount;
                return(LogProviderStatsFlag.CachedTime | LogProviderStatsFlag.BytesCount);
            });
        }