private void OnShowFilenameChanged(bool showFilename)
 {
     if (showFilename)
     {
         DisplayMode = DataSourceDisplayMode.Filename;
     }
 }
 private void OnShowCharacterCodeChanged(bool showCharacterCode)
 {
     if (showCharacterCode)
     {
         DisplayMode = DataSourceDisplayMode.CharacterCode;
     }
 }
        private static string GetDataSourceName(DataSourceDisplayMode displayMode, IDataSource dataSource)
        {
            switch (displayMode)
            {
            case DataSourceDisplayMode.CharacterCode:
                return(dataSource.CharacterCode);

            case DataSourceDisplayMode.Filename:
                try
                {
                    var fullFileName = dataSource.FullFileName;
                    var fileName     = Path.GetFileName(fullFileName);
                    if (fileName != null && fileName.Length > MaximumDataSourceCharacters)
                    {
                        fileName = fileName.Substring(startIndex: 0, length: MaximumDataSourceCharacters);
                    }
                    return(fileName);
                }
                catch (IOException e)
                {
                    // This exception is expected when the path is malformed (for example because that path was passed via command line)
                    Log.DebugFormat("Caught io exception: {0}", e);
                    return(null);
                }
                catch (Exception e)
                {
                    Log.ErrorFormat("Caught unexpected exception: {0}", e);
                    return(null);
                }

            default:
                return(null);
            }
        }
        private FormattedText CreateFormattedText(DataSourceDisplayMode displayMode, string dataSourceName)
        {
            Brush brush;

            switch (displayMode)
            {
            case DataSourceDisplayMode.Filename:
                brush = TextBrushes.DataSourceFilenameForegroundBrush;
                break;

            case DataSourceDisplayMode.CharacterCode:
                brush = TextBrushes.DataSourceCharacterCodeForegroundBrush;
                break;

            default:
                brush = Brushes.Black;
                break;
            }

            var culture = CultureInfo.CurrentUICulture;

            return(new FormattedText(dataSourceName ?? string.Empty,
                                     culture,
                                     FlowDirection.LeftToRight,
                                     _textSettings.Typeface,
                                     _textSettings.FontSize,
                                     brush,
                                     1.25));
        }
Exemple #5
0
        private void OnMergedDataSourceDisplayModeChanged(DataSourceDisplayMode displayMode)
        {
            var dataSource = DataSource as IMergedDataSourceViewModel;

            if (dataSource != null)
            {
                dataSource.DisplayMode = displayMode;
            }
        }
Exemple #6
0
        public void TestConstruction2([Values(DataSourceDisplayMode.Filename, DataSourceDisplayMode.CharacterCode)] DataSourceDisplayMode displayMode)
        {
            var dataSource = _dataSources.AddGroup();

            dataSource.DisplayMode = displayMode;

            var model = new MergedDataSourceViewModel(dataSource, _actionCenter.Object);

            model.DisplayMode.Should().Be(displayMode);
        }
Exemple #7
0
        /// <summary>
        ///     Returns the length of the longest name of any of the given data sources for
        ///     that particular display mode.
        /// </summary>
        /// <param name="displayMode"></param>
        /// <param name="dataSources"></param>
        /// <returns></returns>
        private static int GetMaximumCharacterCount(DataSourceDisplayMode displayMode, IReadOnlyList <IDataSource> dataSources)
        {
            var max = 0;

            for (var i = 0; i < dataSources.Count; ++i)
            {
                var name = GetDataSourceName(displayMode, dataSources[i]);
                max = Math.Max(name.Length, max);
            }
            return(max);
        }
        public void TestChangeDataSource(
            [Values(DataSourceDisplayMode.Filename, DataSourceDisplayMode.CharacterCode)] DataSourceDisplayMode displayMode)
        {
            var dataSource = new Mock <IMergedDataSourceViewModel>();

            dataSource.SetupProperty(x => x.DisplayMode);
            dataSource.Object.DisplayMode = displayMode;

            _control.DataSource = dataSource.Object;
            _control.MergedDataSourceDisplayMode.Should()
            .Be(displayMode,
                "because the view model determines the initial display mode and thus the control should just use that");
            dataSource.Object.DisplayMode.Should()
            .Be(displayMode, "because the display mode of the view model shouldn't have been changed in the process");
        }
Exemple #9
0
        public void TestUpdateNoSources([Values(DataSourceDisplayMode.Filename, DataSourceDisplayMode.CharacterCode)] DataSourceDisplayMode displayMode)
        {
            var canvas = new DataSourceCanvas(TextSettings.Default)
            {
                DisplayMode = displayMode
            };
            var folderDataSource = new Mock <IFolderDataSource>();

            folderDataSource.Setup(x => x.FilteredLogSource).Returns(new Mock <ILogSource>().Object);
            var dataSource = new Mock <IDataSource>();

            folderDataSource.Setup(x => x.OriginalSources).Returns(new List <IDataSource> {
                dataSource.Object
            });

            new Action(() => canvas.UpdateDataSources(folderDataSource.Object, new LogSourceSection(0, 2), 0))
            .Should().NotThrow();
        }
Exemple #10
0
 private void OnMergedDataSourceDisplayModeChanged(DataSourceDisplayMode displayMode)
 {
     _dataSourceCanvas.DisplayMode = displayMode;
 }
 private void OnDisplayModeChanged(DataSourceDisplayMode displayMode)
 {
     ShowFilename      = displayMode == DataSourceDisplayMode.Filename;
     ShowCharacterCode = displayMode == DataSourceDisplayMode.CharacterCode;
 }
Exemple #12
0
        public void Restore(XmlReader reader, out bool neededPatching)
        {
            int count = reader.AttributeCount;

            for (int i = 0; i < count; ++i)
            {
                reader.MoveToAttribute(i);
                switch (reader.Name)
                {
                case "file":
                    File = reader.Value;
                    break;

                case "followtail":
                    FollowTail = reader.ReadContentAsBool();
                    break;

                case "showlinenumbers":
                    ShowLineNumbers = reader.ReadContentAsBool();
                    break;

                case "showdeltatimes":
                    ShowDeltaTimes = reader.ReadContentAsBool();
                    break;

                case "showelapsedtime":
                    ShowElapsedTime = reader.ReadContentAsBool();
                    break;

                case "stringfilter":
                case "searchterm":
                    SearchTerm = reader.Value;
                    break;

                case "levelfilter":
                    LevelFilter = reader.ReadContentAsEnum <LevelFlags>();
                    break;

                case "colorbylevel":
                    ColorByLevel = reader.ReadContentAsBool();
                    break;

                case "hideemptylines":
                    HideEmptyLines = reader.ReadContentAsBool();
                    break;

                case "singleline":
                    IsSingleLine = reader.ReadContentAsBool();
                    break;

                case "expanded":
                    IsExpanded = reader.ReadContentAsBool();
                    break;

                case "visibleentryindex":
                    VisibleLogLine = reader.ReadContentAsInt();
                    break;

                case "id":
                    Id = reader.ReadContentAsDataSourceId();
                    break;

                case "parentid":
                    ParentId = reader.ReadContentAsDataSourceId();
                    break;

                case "logfilefolderpath":
                    LogFileFolderPath = reader.ReadContentAsString();
                    break;

                case "logfileregex":
                    LogFileSearchPattern = reader.ReadContentAsString();
                    break;

                case "recursive":
                    Recursive = reader.ReadContentAsBoolean();
                    break;

                case "lastviewed":
                    LastViewed = reader.ReadContentAsDateTime2();
                    break;

                case "horizontaloffset":
                    HorizontalOffset = reader.ReadContentAsDouble2();
                    break;

                case "mergeddatasourcedisplaymode":
                    MergedDataSourceDisplayMode = reader.ReadContentAsEnum <DataSourceDisplayMode>();
                    break;

                case "displayname":
                    DisplayName = reader.ReadContentAsString();
                    break;
                }
            }

            if (Id == DataSourceId.Empty)
            {
                Id = DataSourceId.CreateNew();
                Log.InfoFormat("Data Source '{0}' doesn't have an ID yet, setting it to: {1}",
                               File,
                               Id
                               );
                neededPatching = true;
            }
            else
            {
                neededPatching = false;
            }

            reader.MoveToContent();

            XmlReader subtree = reader.ReadSubtree();

            while (subtree.Read())
            {
                switch (subtree.Name)
                {
                case "activatedquickfilters":
                    IEnumerable <QuickFilterId> filters = ReadActivatedQuickFilters(reader);
                    ActivatedQuickFilters.Clear();
                    ActivatedQuickFilters.AddRange(filters);
                    break;
                }
            }
        }
        public void TestClone([ValueSource(nameof(Bool))] bool hideEmptyLines,
                              [ValueSource(nameof(Bool))] bool showLineNumbers,
                              [ValueSource(nameof(Bool))] bool showDeltaTimes,
                              [ValueSource(nameof(Bool))] bool showElapsedTime,
                              [ValueSource(nameof(Bool))] bool colorByLevel,
                              [ValueSource(nameof(Bool))] bool followTail,
                              [ValueSource(nameof(Bool))] bool isSingleLine,
                              [ValueSource(nameof(Bool))] bool isExpanded,
                              [ValueSource(nameof(DisplayModes))] DataSourceDisplayMode displayMode)
        {
            var id         = DataSourceId.CreateNew();
            var parent     = DataSourceId.CreateNew();
            var filter     = QuickFilterId.CreateNew();
            var dataSource = new DataSource
            {
                VisibleLogLine   = new LogLineIndex(42),
                LastViewed       = new DateTime(2017, 5, 1, 17, 4, 0),
                Order            = 10,
                HideEmptyLines   = hideEmptyLines,
                File             = @"F:\foo.db",
                Id               = id,
                ShowLineNumbers  = showLineNumbers,
                ShowDeltaTimes   = showDeltaTimes,
                ShowElapsedTime  = showElapsedTime,
                HorizontalOffset = 101,
                ColorByLevel     = colorByLevel,
                FollowTail       = followTail,
                IsSingleLine     = isSingleLine,
                IsExpanded       = isExpanded,
                LevelFilter      = LevelFlags.Fatal,
                ParentId         = parent,
                SearchTerm       = "stuff",
                SelectedLogLines =
                {
                    new LogLineIndex(1),
                    new LogLineIndex(10)
                },
                ActivatedQuickFilters       = { filter },
                MergedDataSourceDisplayMode = displayMode,
                DisplayName = "Some fancy name"
            };
            var cloned = ((ICloneable)dataSource).Clone() as DataSource;

            cloned.Should().NotBeNull();
            cloned.Should().NotBeSameAs(dataSource);
            cloned.VisibleLogLine.Should().Be(new LogLineIndex(42));
            cloned.LastViewed.Should().Be(new DateTime(2017, 5, 1, 17, 4, 0));
            cloned.Order.Should().Be(10);
            cloned.HideEmptyLines.Should().Be(hideEmptyLines);
            cloned.File.Should().Be(@"F:\foo.db");
            cloned.Id.Should().Be(id);
            cloned.ShowLineNumbers.Should().Be(showLineNumbers);
            cloned.ShowDeltaTimes.Should().Be(showDeltaTimes);
            cloned.ShowElapsedTime.Should().Be(showElapsedTime);
            cloned.HorizontalOffset.Should().Be(101);
            cloned.ColorByLevel.Should().Be(colorByLevel);
            cloned.FollowTail.Should().Be(followTail);
            cloned.IsSingleLine.Should().Be(isSingleLine);
            cloned.IsExpanded.Should().Be(isExpanded);
            cloned.LevelFilter.Should().Be(LevelFlags.Fatal);
            cloned.ParentId.Should().Be(parent);
            cloned.SearchTerm.Should().Be("stuff");
            cloned.SelectedLogLines.Should().BeEquivalentTo(new LogLineIndex(1), new LogLineIndex(10));
            cloned.SelectedLogLines.Should().NotBeSameAs(dataSource.SelectedLogLines);
            cloned.ActivatedQuickFilters.Should().Equal(new object[] { filter });
            cloned.ActivatedQuickFilters.Should().NotBeSameAs(dataSource.ActivatedQuickFilters);
            cloned.MergedDataSourceDisplayMode.Should().Be(displayMode);
            cloned.DisplayName.Should().Be("Some fancy name");
        }
        public void TestSaveRestore([ValueSource(nameof(Bool))] bool hideEmptyLines,
                                    [ValueSource(nameof(Bool))] bool showLineNumbers,
                                    [ValueSource(nameof(Bool))] bool showDeltaTimes,
                                    [ValueSource(nameof(Bool))] bool showElapsedTime,
                                    [ValueSource(nameof(Bool))] bool colorByLevel,
                                    [ValueSource(nameof(Bool))] bool followTail,
                                    [ValueSource(nameof(Bool))] bool isSingleLine,
                                    [ValueSource(nameof(Bool))] bool isExpanded,
                                    [ValueSource(nameof(DisplayModes))] DataSourceDisplayMode displayMode)
        {
            var id     = DataSourceId.CreateNew();
            var parent = DataSourceId.CreateNew();
            var filter = QuickFilterId.CreateNew();

            using (var stream = new MemoryStream())
            {
                using (var writer = XmlWriter.Create(stream))
                {
                    writer.WriteStartElement("Test");

                    var dataSource = new DataSource
                    {
                        VisibleLogLine = new LogLineIndex(42),
                        LastViewed     = new DateTime(2017, 5, 1, 17, 4, 0),
                        //Order = 10,
                        HideEmptyLines   = hideEmptyLines,
                        File             = @"F:\foo.db",
                        Id               = id,
                        ShowLineNumbers  = showLineNumbers,
                        ShowDeltaTimes   = showDeltaTimes,
                        ShowElapsedTime  = showElapsedTime,
                        HorizontalOffset = 101,
                        ColorByLevel     = colorByLevel,
                        FollowTail       = followTail,
                        IsSingleLine     = isSingleLine,
                        IsExpanded       = isExpanded,
                        LevelFilter      = LevelFlags.Fatal,
                        ParentId         = parent,
                        SearchTerm       = "stuff",
                        //SelectedLogLines =
                        //{
                        //	new LogLineIndex(1),
                        //	new LogLineIndex(10)
                        //},
                        ActivatedQuickFilters       = { filter },
                        MergedDataSourceDisplayMode = displayMode,
                        DisplayName = "A stupid name"
                    };
                    dataSource.Save(writer);
                }
                stream.Position = 0;
                //Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));

                using (var reader = XmlReader.Create(stream))
                {
                    reader.MoveToContent();

                    var  dataSource = new DataSource();
                    bool unused;
                    dataSource.Restore(reader, out unused);
                    dataSource.VisibleLogLine.Should().Be(new LogLineIndex(42));
                    dataSource.LastViewed.Should().Be(new DateTime(2017, 5, 1, 17, 4, 0));
                    //dataSource.Order.Should().Be(10);
                    dataSource.HideEmptyLines.Should().Be(hideEmptyLines);
                    dataSource.File.Should().Be(@"F:\foo.db");
                    dataSource.Id.Should().Be(id);
                    dataSource.ShowLineNumbers.Should().Be(showLineNumbers);
                    dataSource.ShowDeltaTimes.Should().Be(showDeltaTimes);
                    dataSource.ShowElapsedTime.Should().Be(showElapsedTime);
                    dataSource.HorizontalOffset.Should().Be(101);
                    dataSource.ColorByLevel.Should().Be(colorByLevel);
                    dataSource.FollowTail.Should().Be(followTail);
                    dataSource.IsSingleLine.Should().Be(isSingleLine);
                    dataSource.IsExpanded.Should().Be(isExpanded);
                    dataSource.LevelFilter.Should().Be(LevelFlags.Fatal);
                    dataSource.ParentId.Should().Be(parent);
                    dataSource.SearchTerm.Should().Be("stuff");
                    //dataSource.SelectedLogLines.Should().BeEquivalentTo(new LogLineIndex(1), new LogLineIndex(10));
                    dataSource.ActivatedQuickFilters.Should().Equal(new object[] { filter });
                    dataSource.MergedDataSourceDisplayMode.Should().Be(displayMode);
                    dataSource.DisplayName.Should().Be("A stupid name");
                }
            }
        }
Exemple #15
0
        public void TestSaveRestore2([ValueSource(nameof(Bool))] bool followTail,
                                     [ValueSource(nameof(Bool))] bool isSingleLine,
                                     [ValueSource(nameof(Bool))] bool isExpanded,
                                     [ValueSource(nameof(Bool))] bool recursive,
                                     [ValueSource(nameof(DisplayModes))] DataSourceDisplayMode displayMode)
        {
            var id       = DataSourceId.CreateNew();
            var parent   = DataSourceId.CreateNew();
            var filter   = QuickFilterId.CreateNew();
            var excluded = new HashSet <DataSourceId>
            {
                DataSourceId.CreateNew(),
                DataSourceId.CreateNew()
            };

            using (var stream = new MemoryStream())
            {
                using (var writer = XmlWriter.Create(stream))
                {
                    writer.WriteStartElement("Test");

                    var dataSource = new DataSource
                    {
                        VisibleLogLine = new LogLineIndex(42),
                        LastViewed     = new DateTime(2017, 5, 1, 17, 4, 0),
                        //Order = 10,
                        File                 = @"F:\foo.db",
                        Id                   = id,
                        HorizontalOffset     = 101,
                        FollowTail           = followTail,
                        IsSingleLine         = isSingleLine,
                        IsExpanded           = isExpanded,
                        LevelFilter          = LevelFlags.Fatal,
                        ParentId             = parent,
                        LogFileFolderPath    = @"E:\logs\",
                        LogFileSearchPattern = "*.txt",
                        Recursive            = recursive,
                        SearchTerm           = "stuff",
                        //SelectedLogLines =
                        //{
                        //	new LogLineIndex(1),
                        //	new LogLineIndex(10)
                        //},
                        ActivatedQuickFilters       = { filter },
                        MergedDataSourceDisplayMode = displayMode,
                        DisplayName         = "A stupid name",
                        ExcludedDataSources = excluded
                    };
                    dataSource.Save(writer);
                }

                stream.Position = 0;
                //Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));

                using (var reader = XmlReader.Create(stream))
                {
                    reader.MoveToContent();

                    var  dataSource = new DataSource();
                    bool unused;
                    dataSource.Restore(reader, out unused);
                    dataSource.VisibleLogLine.Should().Be(new LogLineIndex(42));
                    dataSource.LastViewed.Should().Be(new DateTime(2017, 5, 1, 17, 4, 0));
                    //dataSource.Order.Should().Be(10);
                    dataSource.File.Should().Be(@"F:\foo.db");
                    dataSource.Id.Should().Be(id);
                    dataSource.HorizontalOffset.Should().Be(101);
                    dataSource.FollowTail.Should().Be(followTail);
                    dataSource.IsSingleLine.Should().Be(isSingleLine);
                    dataSource.IsExpanded.Should().Be(isExpanded);
                    dataSource.LevelFilter.Should().Be(LevelFlags.Fatal);
                    dataSource.ParentId.Should().Be(parent);
                    dataSource.LogFileFolderPath.Should().Be(@"E:\logs\");
                    dataSource.LogFileSearchPattern.Should().Be("*.txt");
                    dataSource.Recursive.Should().Be(recursive);
                    dataSource.SearchTerm.Should().Be("stuff");
                    //dataSource.SelectedLogLines.Should().BeEquivalentTo(new LogLineIndex(1), new LogLineIndex(10));
                    dataSource.ActivatedQuickFilters.Should().Equal(new object[] { filter });
                    dataSource.MergedDataSourceDisplayMode.Should().Be(displayMode);
                    dataSource.DisplayName.Should().Be("A stupid name");
                    dataSource.ExcludedDataSources.Should().BeEquivalentTo(excluded);
                }
            }
        }
Exemple #16
0
        public void TestClone2([ValueSource(nameof(Bool))] bool followTail,
                               [ValueSource(nameof(Bool))] bool isSingleLine,
                               [ValueSource(nameof(Bool))] bool isExpanded,
                               [ValueSource(nameof(Bool))] bool recursive,
                               [ValueSource(nameof(DisplayModes))] DataSourceDisplayMode displayMode)
        {
            var id         = DataSourceId.CreateNew();
            var parent     = DataSourceId.CreateNew();
            var filter     = QuickFilterId.CreateNew();
            var dataSource = new DataSource
            {
                VisibleLogLine       = new LogLineIndex(42),
                LastViewed           = new DateTime(2017, 5, 1, 17, 4, 0),
                Order                = 10,
                File                 = @"F:\foo.db",
                Id                   = id,
                HorizontalOffset     = 101,
                FollowTail           = followTail,
                IsSingleLine         = isSingleLine,
                IsExpanded           = isExpanded,
                LevelFilter          = LevelFlags.Fatal,
                ParentId             = parent,
                LogFileFolderPath    = @"C:\temp\logs",
                LogFileSearchPattern = "*.log",
                Recursive            = recursive,
                SearchTerm           = "stuff",
                SelectedLogLines     =
                {
                    new LogLineIndex(1),
                    new LogLineIndex(10)
                },
                ActivatedQuickFilters       = { filter },
                MergedDataSourceDisplayMode = displayMode,
                DisplayName         = "Some fancy name",
                ExcludedDataSources = new HashSet <DataSourceId>
                {
                    DataSourceId.CreateNew(),
                DataSourceId.CreateNew()
                }
            };
            var cloned = ((ICloneable)dataSource).Clone() as DataSource;

            cloned.Should().NotBeNull();
            cloned.Should().NotBeSameAs(dataSource);
            cloned.VisibleLogLine.Should().Be(new LogLineIndex(42));
            cloned.LastViewed.Should().Be(new DateTime(2017, 5, 1, 17, 4, 0));
            cloned.Order.Should().Be(10);
            cloned.File.Should().Be(@"F:\foo.db");
            cloned.Id.Should().Be(id);
            cloned.HorizontalOffset.Should().Be(101);
            cloned.FollowTail.Should().Be(followTail);
            cloned.IsSingleLine.Should().Be(isSingleLine);
            cloned.IsExpanded.Should().Be(isExpanded);
            cloned.LevelFilter.Should().Be(LevelFlags.Fatal);
            cloned.ParentId.Should().Be(parent);
            cloned.LogFileFolderPath.Should().Be(@"C:\temp\logs");
            cloned.LogFileSearchPattern.Should().Be("*.log");
            cloned.Recursive.Should().Be(recursive);
            cloned.SearchTerm.Should().Be("stuff");
            cloned.SelectedLogLines.Should().BeEquivalentTo(new LogLineIndex(1), new LogLineIndex(10));
            cloned.SelectedLogLines.Should().NotBeSameAs(dataSource.SelectedLogLines);
            cloned.ActivatedQuickFilters.Should().Equal(new object[] { filter });
            cloned.ActivatedQuickFilters.Should().NotBeSameAs(dataSource.ActivatedQuickFilters);
            cloned.MergedDataSourceDisplayMode.Should().Be(displayMode);
            cloned.DisplayName.Should().Be("Some fancy name");
            cloned.ExcludedDataSources.Should().NotBeSameAs(dataSource.ExcludedDataSources);
            cloned.ExcludedDataSources.Should().BeEquivalentTo(dataSource.ExcludedDataSources);
        }