Beispiel #1
0
        public void OnMovePageDown()
        {
            try
            {
                int count = _logSource.GetProperty(Properties.LogEntryCount);
                if (_selectedIndices.Count > 0 && _lastSelection < count - 1)
                {
                    LogLineIndex newIndex;
                    int          maxDelta = _currentlyVisibleSection.Count;
                    if (maxDelta + _lastSelection >= count)
                    {
                        newIndex = count - 1;
                    }
                    else
                    {
                        newIndex = _lastSelection + maxDelta;
                    }

                    ChangeSelectionAndBringIntoView(newIndex);
                }
            }
            catch (Exception e)
            {
                Log.ErrorFormat("Caught unexpected exception: {0}", e);
            }
        }
 /// <inheritdoc />
 public object GetProperty(IReadOnlyPropertyDescriptor property)
 {
     try
     {
         return(_logSource.GetProperty(property));
     }
     catch (Exception e)
     {
         BlameExceptionOnPlugin(e);
         return(property.DefaultValue);
     }
 }
Beispiel #3
0
        public void Export(IProgress <Percentage> progressReporter = null)
        {
            const int bufferSize = 1000;
            var       buffer     = new LogBufferArray(bufferSize, Columns.Index, Columns.RawContent);
            var       count      = _logSource.GetProperty(Properties.LogEntryCount);
            var       index      = 0;

            using (var writer = new StreamWriter(_stream, Encoding.UTF8, 1024, true))
            {
                while (index < count)
                {
                    var remaining = count - index;
                    if (remaining > bufferSize)
                    {
                        remaining = bufferSize;
                    }
                    if (!ExportPortion(writer, buffer, index, remaining))
                    {
                        break;
                    }

                    index += remaining;
                    var progress = Percentage.Of(index, count);
                    progressReporter?.Report(progress);
                }
            }
        }
Beispiel #4
0
        protected override void UpdateWidth(ILogSource logSource, TextSettings textSettings)
        {
            int lineNumberCharacterCount;

            if (logSource != null)
            {
                var lineCount = logSource.GetProperty(TextProperties.LineCount);
                if (lineCount > 0)
                {
                    lineNumberCharacterCount = (int)Math.Ceiling(Math.Log10(lineCount));
                }
                else
                {
                    lineNumberCharacterCount = 0;
                }
            }
            else
            {
                lineNumberCharacterCount = 0;
            }

            // We always reserve space for at least 3 characters.
            _lineNumberWidth = textSettings.EstimateWidthUpperLimit(Math.Max(lineNumberCharacterCount, val2: 3));
            Width            = _lineNumberWidth + textSettings.LineNumberSpacing;
        }
        public ILogSource CreateParser(IServiceContainer services, ILogSource source)
        {
            var format = source.GetProperty(Properties.Format);
            var logSourceParserPlugins = _pluginLoader?.LoadAllOfTypeWithDescription <ILogSourceParserPlugin>() ?? Enumerable.Empty <IPluginWithDescription <ILogSourceParserPlugin> >();

            foreach (var plugin in logSourceParserPlugins)
            {
                var parser = TryCreateParser(plugin, source);
                if (parser != null)
                {
                    return(parser);
                }
            }

            var logEntryParserPlugins = _pluginLoader?.LoadAllOfTypeWithDescription <ILogEntryParserPlugin>() ?? Enumerable.Empty <IPluginWithDescription <ILogEntryParserPlugin> >();

            foreach (var plugin in logEntryParserPlugins)
            {
                var parser = TryCreateParser(plugin, format);
                if (parser != null)
                {
                    return(new GenericTextLogSource(source, parser));
                }
            }

            return(new GenericTextLogSource(source, new GenericTextLogEntryParser()));
        }
        private void GetIndex(IReadOnlyList <LogLineIndex> sourceIndices, LogLineIndex[] destination, int destinationIndex)
        {
            var count = _source?.GetProperty(Core.Properties.LogEntryCount) ?? 0;

            for (int i = 0; i < sourceIndices.Count; ++i)
            {
                var sourceIndex = sourceIndices[i].Value;
                if (sourceIndex >= 0 && sourceIndex < count)
                {
                    destination[destinationIndex + i] = sourceIndex;
                }
                else
                {
                    destination[destinationIndex + i] = Core.Columns.Index.DefaultValue;
                }
            }
        }
        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);
        }
Beispiel #8
0
        private static ILogSource TryCreateMultiLineLogFile(IServiceContainer serviceContainer, ILogSource source, TimeSpan maximumWaitTime)
        {
            if (!source.GetProperty(TextProperties.AllowsMultiline))
            {
                return(null);
            }

            var multiLineLogSource = new MultiLineLogSource(serviceContainer.Retrieve <ITaskScheduler>(), source, maximumWaitTime);

            return(multiLineLogSource);
        }
        public void OnLogFileModified(ILogSource logSource, LogSourceModification modification)
        {
            var width      = _textSettings.EstimateWidthUpperLimit(logSource.GetProperty(TextProperties.MaxCharactersInLine));
            var upperWidth = (int)Math.Ceiling(width);

            // Setting an integer is an atomic operation and thus no
            // special synchronization is required.
            _maxLineWidth = Math.Max(_maxLineWidth, upperWidth);

            Interlocked.Increment(ref _pendingModificationsCount);
        }
 protected override void UpdateWidth(ILogSource logSource, TextSettings textSettings)
 {
     if (logSource != null)
     {
         var culture      = CultureInfo.CurrentCulture;
         var maximum      = ElapsedTimeFormatter.ToString(logSource.GetProperty(Properties.EndTimestamp) - logSource.GetProperty(Properties.StartTimestamp), culture);
         var maximumWidth = textSettings.EstimateWidthUpperLimit(maximum);
         Width = maximumWidth;
     }
     else
     {
         Width = 0;
     }
 }
Beispiel #11
0
 private void OnMoveEnd()
 {
     try
     {
         ILogSource logSource = _logSource;
         if (logSource != null)
         {
             var count = logSource.GetProperty(Properties.LogEntryCount);
             if (count > 0)
             {
                 var newIndex = new LogLineIndex(count - 1);
                 ChangeSelectionAndBringIntoView(newIndex);
             }
         }
     }
     catch (Exception e)
     {
         Log.ErrorFormat("Caught unexpected exception: {0}", e);
     }
 }
        public void TestExists()
        {
            ILogSource logSource = null;

            try
            {
                new Action(() => logSource = Create(File2Lines)).Should().NotThrow();

                logSource.Property(x => x.GetProperty(Properties.PercentageProcessed)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(Percentage.HundredPercent);
                logSource.Property(x => x.GetProperty(Properties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(null);

                logSource.GetProperty(Properties.EmptyReason).Should().Be(null, "Because the specified file does exist");
            }
            finally
            {
                if (logSource != null)
                {
                    logSource.Dispose();
                }
            }
        }
        public void TestDoesNotExist()
        {
            ILogSource logSource = null;

            try
            {
                new Action(() => logSource = Create("dadwdawdw")).Should().NotThrow();

                logSource.Property(x => x.GetProperty(Properties.PercentageProcessed)).ShouldAfter(TimeSpan.FromSeconds(5)).Be(Percentage.HundredPercent);
                logSource.Property(x => x.GetProperty(Properties.EmptyReason)).ShouldAfter(TimeSpan.FromSeconds(5)).NotBeNull();

                logSource.GetProperty(Properties.EmptyReason).Should().BeOfType <SourceDoesNotExist>("Because the specified file doesn't exist");
            }
            finally
            {
                if (logSource != null)
                {
                    logSource.Dispose();
                }
            }
        }
        private void GetElapsedTime(IReadOnlyList <LogLineIndex> indices, TimeSpan?[] buffer, int destinationIndex,
                                    LogSourceQueryOptions queryOptions)
        {
            var startTimestamp = _source.GetProperty(Core.Properties.StartTimestamp);

            if (startTimestamp != null)
            {
                var timestamps = _source.GetColumn(indices, Core.Columns.Timestamp, queryOptions);
                for (int i = 0; i < indices.Count; ++i)
                {
                    var timestamp = timestamps[i];
                    buffer[destinationIndex + i] = timestamp != null
                                                ? timestamp.Value - startTimestamp
                                                : Core.Columns.ElapsedTime.DefaultValue;
                }
            }
            else
            {
                for (int i = 0; i < indices.Count; ++i)
                {
                    buffer[destinationIndex + i] = Core.Columns.ElapsedTime.DefaultValue;
                }
            }
        }
Beispiel #15
0
        private void OnLogFileChanged(ILogSource oldValue, ILogSource newValue)
        {
            oldValue?.RemoveListener(this);

            PartTextCanvas.LogSource = newValue;

            if (newValue != null)
            {
                newValue.AddListener(this, TimeSpan.FromMilliseconds(value: 100), maximumLineCount: 10000);

                _maxLineWidth = (int)Math.Ceiling(_textSettings.EstimateWidthUpperLimit(newValue.GetProperty(TextProperties.MaxCharactersInLine)));
                UpdateScrollViewerRegions();
                PartTextCanvas.DetermineVerticalOffset();
                PartTextCanvas.UpdateVisibleSection();
                PartTextCanvas.UpdateVisibleLines();
            }
            else
            {
                _maxLineWidth = 0;
                TextCanvasOnVisibleLinesChanged();
                UpdateScrollViewerRegions();
            }

            MatchScrollbarValueToCurrentLine();
        }
 public override object GetProperty(IReadOnlyPropertyDescriptor property)
 {
     return(_source.GetProperty(property));
 }
        private void UpdateNoEntriesExplanation()
        {
            IDataSource dataSource       = _dataSource.DataSource;
            var         folderDataSource = dataSource as IFolderDataSource;
            ILogSource  source           = dataSource.UnfilteredLogSource;
            ILogSource  filtered         = dataSource.FilteredLogSource;

            if (filtered.GetProperty(Properties.LogEntryCount) == 0)
            {
                ILogEntryFilter filter      = dataSource.LogEntryFilter;
                var             emptyReason = source.GetProperty(Properties.EmptyReason);
                if (emptyReason != null)
                {
                    NoEntriesIcon        = emptyReason.Icon;
                    NoEntriesExplanation = emptyReason.Reason;
                    NoEntriesAction      = emptyReason.Explanation;
                }
                else if (folderDataSource != null && folderDataSource.UnfilteredFileCount == 0)
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = $"The folder \"{Path.GetFileName(dataSource.FullFileName)}\" does not contain any file";
                    NoEntriesAction      = dataSource.FullFileName;
                }
                else if (folderDataSource != null && folderDataSource.FilteredFileCount == 0)
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = $"The folder \"{Path.GetFileName(dataSource.FullFileName)}\" does not contain any file matching \"{folderDataSource.LogFileSearchPattern}\"";
                    NoEntriesAction      = dataSource.FullFileName;
                }
                else if (source.GetProperty(Properties.Size) == Size.Zero)
                {
                    NoEntriesIcon        = Icons.File;
                    NoEntriesExplanation = "Data source is empty";
                    NoEntriesAction      = null;
                }
                else if (dataSource.LevelFilter != LevelFlags.All)
                {
                    NoEntriesIcon        = Icons.FileSearch;
                    NoEntriesExplanation = "Nothing matches level filter";
                    NoEntriesAction      = "Try filtering by different levels or display everything regardless of its level again";
                }
                else if (dataSource.ScreenCleared)
                {
                    NoEntriesIcon        = Icons.PlaylistRemove;
                    NoEntriesExplanation = "The screen was cleared";
                    NoEntriesAction      = "No new log entries have been added to the data source since the screen was cleared. Try waiting for a little longer or show all log entries again.";
                }
                else if (filter != null)
                {
                    NoEntriesIcon        = Icons.FileSearch;
                    NoEntriesExplanation = "Nothing matches quick filter";
                    NoEntriesAction      = filter is FilterExpression
                                                ? $"No log entry matches \"{filter}\".\r\nTry changing your filter(s) or disable them again"
                                                : "Try filtering by different terms or disable all quick filters";
                }
                else if (source is MergedLogSource)
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = "No log entries with timestamps";
                    NoEntriesAction      = "Try merging different data sources, change the timestamp format of the data or create a plugin to help Tailviewer parse its timestamp";
                }
                else
                {
                    NoEntriesIcon        = null;
                    NoEntriesExplanation = null;
                    NoEntriesAction      = null;
                }
            }
            else
            {
                NoEntriesExplanation = null;
                NoEntriesAction      = null;
            }
        }
 private void UpdateCounts()
 {
     LogEntryCount      = _logSource.GetProperty(Properties.LogEntryCount);
     TotalLogEntryCount = _dataSource.DataSource.UnfilteredLogSource.GetProperty(Properties.LogEntryCount);
     UpdateNoEntriesExplanation();
 }