コード例 #1
0
        public static IReadOnlyLogEntry GetEntry(this ILogSource logSource, LogLineIndex sourceIndex, IEnumerable <IColumnDescriptor> columns)
        {
            var buffer = new LogBufferArray(1, columns);

            logSource.GetEntries(new LogSourceSection(sourceIndex, 1), buffer);
            return(buffer[0]);
        }
コード例 #2
0
        public static IReadOnlyLogEntry GetEntry(this ILogSource logSource, LogLineIndex sourceIndex)
        {
            var buffer = new LogBufferArray(1, logSource.Columns);

            logSource.GetEntries(new LogSourceSection(sourceIndex, 1), buffer);
            return(buffer[0]);
        }
コード例 #3
0
        public static IReadOnlyLogBuffer GetEntries(this ILogSource logSource, IReadOnlyList <LogLineIndex> sourceIndices)
        {
            var buffer = new LogBufferArray(sourceIndices.Count, logSource.Columns);

            GetEntries(logSource, sourceIndices, buffer);
            return(buffer);
        }
コード例 #4
0
        public static IReadOnlyLogBuffer GetEntries(this ILogSource logSource, IReadOnlyList <LogLineIndex> sourceIndices, IEnumerable <IColumnDescriptor> columns)
        {
            var buffer = new LogBufferArray(sourceIndices.Count, columns);

            logSource.GetEntries(sourceIndices, buffer);
            return(buffer);
        }
コード例 #5
0
ファイル: FileLogSource.cs プロジェクト: tank0226/Tailviewer
        public FileLogSource(IServiceContainer services, string fileName, TimeSpan maximumWaitTime)
            : base(services.Retrieve <ITaskScheduler>())
        {
            _syncRoot     = new object();
            _filesystem   = services.Retrieve <IFilesystem>();
            _services     = services;
            _fullFilename = Path.IsPathRooted(fileName)
                                ? fileName
                                : Path.Combine(Directory.GetCurrentDirectory(), fileName);
            _maximumWaitTime = maximumWaitTime;

            _sourceDoesNotExist     = new SourceDoesNotExist(fileName);
            _sourceCannotBeAccessed = new SourceCannotBeAccessed(fileName);

            var formatMatcher = services.Retrieve <ILogFileFormatMatcher>();

            _encodingDetector = new EncodingDetector();
            _formatDetector   = new FileFormatDetector(formatMatcher);

            _buffer          = new LogBufferArray(MaximumLineCount, Core.Columns.RawContent);
            _pendingSections = new ConcurrentQueue <KeyValuePair <ILogSource, LogSourceModification> >();

            _propertiesBuffer = new PropertiesBufferList();
            _propertiesBuffer.SetValue(Core.Properties.Name, _fullFilename);

            _properties = new ConcurrentPropertiesList();

            StartTask();
        }
コード例 #6
0
        private void Append(LogSourceSection section)
        {
            var buffer = new LogBufferArray(section.Count, Core.Columns.Index, Core.Columns.Timestamp, Core.Columns.LogLevel);

            _source.GetEntries(section, buffer);

            lock (_syncRoot)
            {
                for (var i = 0; i < section.Count; ++i)
                {
                    var line = buffer[i];

                    if (_currentLogEntry.EntryIndex.IsInvalid ||
                        !AppendToCurrentLogEntry(line))
                    {
                        _currentLogEntry = _currentLogEntry.NextEntry(line.Index);
                    }

                    _indices.Add(_currentLogEntry);
                }
            }

            _currentSourceIndex += section.Count;
            _fullSourceSection   = new LogSourceSection(0, _currentSourceIndex.Value);
        }
コード例 #7
0
        public static IReadOnlyLogBuffer GetEntries(this ILogSource logSource, IReadOnlyList <IColumnDescriptor> columns)
        {
            var count  = logSource.GetProperty(Properties.LogEntryCount);
            var buffer = new LogBufferArray(count, columns);

            GetEntries(logSource, new LogSourceSection(0, count), buffer);
            return(buffer);
        }
コード例 #8
0
        /// <summary>
        ///    Returns a new log buffer which acts as a view onto the original buffer.
        ///    If the original buffer ONLY contains the desired column, then the original buffer is returned.
        ///    Otherwise a new temporary buffer is returned with the same size as the original buffer containing
        ///    only the given column.
        /// </summary>
        /// <param name="that"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public static ILogBuffer CreateViewOnlyWithColumn(this ILogBuffer that, IColumnDescriptor column)
        {
            if (that.Columns.Count == 1 && that.Contains(column))
            {
                return(that);
            }

            var temporaryBuffer = new LogBufferArray(that.Count, column);

            return(temporaryBuffer);
        }
コード例 #9
0
        public Page(int index, int pageSize, IReadOnlyList <IColumnDescriptor> columns, IReadOnlyList <IColumnDescriptor> copiedColumns)
        {
            _index          = index;
            _pageSize       = pageSize;
            _copiedColumns  = copiedColumns;
            _section        = new LogSourceSection(index * pageSize, pageSize);
            _buffer         = new LogBufferArray(pageSize, columns);
            _lastAccessTime = DateTime.MinValue;
            _numReads       = 0;

            _buffer.Fill(PageBufferedLogSource.RetrievalState, RetrievalState.NotInSource, 0, _pageSize);
        }
コード例 #10
0
        public PageBufferedLogSource(ITaskScheduler taskScheduler, ILogSource source, TimeSpan maximumWaitTime, IReadOnlyList <IColumnDescriptor> nonCachedColumns, int pageSize = DefaultPageSize, int maxNumPages = DefaultMaxPageCount)
        {
            _syncRoot      = new object();
            _taskScheduler = taskScheduler;
            _source        = source;
            _maxNumPages   = maxNumPages;
            _listeners     = new ProxyLogListenerCollection(source, this);
            _cachedColumns = source.Columns.Except(nonCachedColumns).ToList();
            _buffer        = new PagedLogBuffer(pageSize, maxNumPages, _cachedColumns);
            _fetchQueue    = new ConcurrentQueue <LogSourceSection>();
            _source.AddListener(this, maximumWaitTime, pageSize);

            _fetchBuffer = new LogBufferArray(pageSize, _cachedColumns);
            _fetchTask   = _taskScheduler.StartPeriodic(FetchPagesFromSource, maximumWaitTime);
        }
コード例 #11
0
        public LogSourcePropertyAdorner(ITaskScheduler scheduler, ILogSource source, TimeSpan maximumWaitTime, IReadOnlyList <IReadOnlyPropertyDescriptor> adornedProperties)
            : base(scheduler)
        {
            _source            = source;
            _maximumWaitTime   = maximumWaitTime;
            _adornedProperties = adornedProperties;
            _propertiesBuffer  = new PropertiesBufferList(_adornedProperties);
            _properties        = new ConcurrentPropertiesList(_adornedProperties);
            _pendingSections   = new ConcurrentQueue <LogSourceModification>();
            _requiredColumns   = GetColumnsRequiredFor(_adornedProperties);
            const int bufferSize = 1000;

            _buffer = new LogBufferArray(bufferSize, _requiredColumns);

            _source.AddListener(this, maximumWaitTime, bufferSize);
            StartTask();
        }
コード例 #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="taskScheduler"></param>
 /// <param name="source"></param>
 /// <param name="columnsToFetch"></param>
 /// <param name="overwrittenProperties"></param>
 /// <param name="maximumWaitTime"></param>
 /// <param name="maxEntryCount"></param>
 protected AbstractProcessingLogSource(ITaskScheduler taskScheduler,
                                       ILogSource source,
                                       IReadOnlyList <IColumnDescriptor> columnsToFetch,
                                       IReadOnlyList <IReadOnlyPropertyDescriptor> overwrittenProperties,
                                       TimeSpan maximumWaitTime,
                                       int maxEntryCount = 1000)
     : base(taskScheduler)
 {
     _fetchBuffer          = new LogBufferArray(maxEntryCount, columnsToFetch);
     _pendingSections      = new ConcurrentQueue <LogSourceModification>();
     _source               = source;
     _maximumWaitTime      = maximumWaitTime;
     _maxEntryCount        = maxEntryCount;
     _propertiesBuffer     = new PropertiesBufferList();
     _propertiesBufferView = new PropertiesBufferHidingView(_propertiesBuffer, overwrittenProperties);
     _properties           = new ConcurrentPropertiesList();
 }
コード例 #13
0
        /// <summary>
        ///    Returns a new log buffer which acts as a view onto the original buffer.
        ///    If the original buffer already contains the desired column, then the original buffer is returned.
        ///    If it does not, then an additional temporary buffer of equal length is created which
        ///    holds data for the given <paramref name="columns"/> and the returned buffer combines both the
        ///    <paramref name="that" /> as well as the temporary buffer into one view.
        /// </summary>
        /// <remarks>
        ///    This method exists for those cases, where, in order to fulfill a certain <see cref="ILogSource.GetEntries(System.Collections.Generic.IReadOnlyList{LogLineIndex}, ILogBuffer, int, LogSourceQueryOptions)"/>
        ///    request, one has to make certain to retrieve a particular column from the source. Nothing needs to be done
        ///    if the caller is also interested in said column, however if the caller is not, then it becomes a one liner
        ///    to create a combined buffer which acts as a proxy for the original for every column but the desired one,
        ///    which is copied into an additional buffer.
        ///
        ///    If it were permissible to query the source log file countless times, then this method wouldn't need to exist,
        ///    however since we don't want to do exactly that, we'll have to do this procedure to improve performance, now
        ///    that log files are streamed into memory on-demand.
        /// </remarks>
        /// <param name="that"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public static ILogBuffer CreateViewWithAdditionalColumns(this ILogBuffer that, IReadOnlyList <IColumnDescriptor> columns)
        {
            if (columns.Count == 0)
            {
                return(that);
            }

            var missingColumns = columns.Except(that.Columns).ToList();

            if (missingColumns.Count == 0)
            {
                return(that);
            }

            var temporaryBuffer = new LogBufferArray(that.Count, missingColumns);
            var combinedView    = new CombinedLogBufferView(new[] { that, temporaryBuffer });

            return(combinedView);
        }
コード例 #14
0
        /// <inheritdoc />
        public void GetEntries(IReadOnlyList <LogLineIndex> sourceIndices,
                               ILogBuffer destination,
                               int destinationIndex,
                               LogSourceQueryOptions queryOptions)
        {
            var source = _source;

            if (source != null)
            {
                var columnsToCopy = new IColumnDescriptor[] { Core.Columns.Index, Core.Columns.RawContent };
                var tmp           = new LogBufferArray(sourceIndices.Count, columnsToCopy);
                source.GetEntries(sourceIndices, tmp, 0, queryOptions);

                foreach (var column in columnsToCopy)
                {
                    if (destination.Contains(column))
                    {
                        destination.CopyFrom(column, destinationIndex, tmp, new Int32Range(0, sourceIndices.Count));
                    }
                }

                for (var i = 0; i < sourceIndices.Count; ++i)
                {
                    var parsedLogEntry = _parser.Parse(tmp[i]);
                    if (parsedLogEntry != null)
                    {
                        destination[destinationIndex + i].CopyFrom(parsedLogEntry);
                    }
                    else
                    {
                        destination[destinationIndex + i].CopyFrom(_nothingParsed);
                    }
                }
            }
            else
            {
                destination.FillDefault(destinationIndex, sourceIndices.Count);
            }
        }
コード例 #15
0
        /// <summary>
        ///     Initializes this object.
        /// </summary>
        /// <param name="scheduler"></param>
        /// <param name="maximumWaitTime"></param>
        /// <param name="source"></param>
        /// <param name="logLineFilter"></param>
        /// <param name="logEntryFilter"></param>
        public FilteredLogSource(ITaskScheduler scheduler,
                                 TimeSpan maximumWaitTime,
                                 ILogSource source,
                                 ILogLineFilter logLineFilter,
                                 ILogEntryFilter logEntryFilter)
            : base(scheduler)
        {
            _source = source ?? throw new ArgumentNullException(nameof(source));

            _properties       = new ConcurrentPropertiesList(source.Properties);
            _propertiesBuffer = new PropertiesBufferList();             //< Will be used as temporary storage to hold the properties from the source

            _logLineFilter        = logLineFilter ?? new NoFilter();
            _logEntryFilter       = logEntryFilter ?? new NoFilter();
            _pendingModifications = new ConcurrentQueue <LogSourceModification>();
            _indices         = new List <int>();
            _logEntryIndices = new Dictionary <int, int>();
            _array           = new LogBufferArray(BatchSize, Core.Columns.Minimum);
            _lastLogBuffer   = new LogBufferList(Core.Columns.Minimum);
            _maximumWaitTime = maximumWaitTime;

            _source.AddListener(this, maximumWaitTime, BatchSize);
            StartTask();
        }
コード例 #16
0
ファイル: LogBufferArray.cs プロジェクト: tank0226/Tailviewer
 public LogEntryAccessor(LogBufferArray array, int index)
 {
     _array = array ?? throw new ArgumentNullException(nameof(array));
     _index = index;
 }