コード例 #1
0
        public void TestCopyFromUnknownColumn()
        {
            var buffer = new LogEntryBuffer(2, LogFileColumns.Timestamp);

            new Action(() => buffer.CopyFrom(LogFileColumns.RawContent, 0, new string[0], 0, 0))
            .ShouldThrow <NoSuchColumnException>();
        }
コード例 #2
0
        public PresentationLogFile(ITaskScheduler scheduler, ILogFile source, TimeSpan maximumWaitTime, TextSettings textSettings)
            : base(scheduler)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            _maximumWaitTime = maximumWaitTime;
            _textSettings    = textSettings;
            _source          = source;

            _indices = new LogEntryList(IndexedColumns);

            _buffer = new LogEntryBuffer(MaximumLineCount, LogFileColumns.RawContent);
            _pendingModifications = new ConcurrentQueue <PendingModification>();
            _syncRoot             = new object();

            _source.AddListener(this, _maximumWaitTime, MaximumLineCount);
            StartTask();
        }
コード例 #3
0
        public void TestCopyFromNullColumn()
        {
            var buffer = new LogEntryBuffer(2, LogFileColumns.Timestamp);

            new Action(() => buffer.CopyFrom(null, 0, new string[0], 0, 0))
            .ShouldThrow <ArgumentNullException>();
        }
コード例 #4
0
        public void TestCopyFrom()
        {
            var buffer    = new LogEntryBuffer(1, LogFileColumns.Timestamp);
            var timestamp = new DateTime(2017, 12, 11, 21, 41, 0);

            buffer.CopyFrom(LogFileColumns.Timestamp, new DateTime?[] { timestamp });
            buffer[0].Timestamp.Should().Be(timestamp, "Because we've just copied this timestamp to the buffer");
        }
コード例 #5
0
        public void TestConstruction2([Values(1, 2, 5, 10, 42, 100, 9001)] int count)
        {
            var buffer = new LogEntryBuffer(count);

            buffer.Columns.Should().BeEmpty();
            buffer.Count.Should().Be(count);
            buffer.Should().HaveCount(count);
        }
コード例 #6
0
        public void TestGetEntryByIndex1([Values(-1, 0, 1)] int invalidIndex)
        {
            var buffer = new LogEntryBuffer(0);

            new Action(() =>
            {
                var unused = buffer[invalidIndex];
            }).ShouldThrow <IndexOutOfRangeException>();
        }
コード例 #7
0
        public void TestConstruction3([Values(1, 2, 5, 10, 42, 100, 9001)] int count)
        {
            var buffer = new LogEntryBuffer(count, new List <ILogFileColumn> {
                LogFileColumns.RawContent, LogFileColumns.DeltaTime
            });

            buffer.Columns.Should().Equal(new object[] { LogFileColumns.RawContent, LogFileColumns.DeltaTime });
            buffer.Count.Should().Be(count);
            buffer.Should().HaveCount(count);
        }
コード例 #8
0
        public void TestCopyFromPartial3()
        {
            var buffer = new LogEntryBuffer(2, LogFileColumns.Timestamp);

            var timestamp = new DateTime(2017, 12, 11, 21, 41, 0);

            buffer.CopyFrom(LogFileColumns.Timestamp, 1, new DateTime?[] { timestamp }, 0, 1);
            buffer[0].Timestamp.Should().BeNull("because we didn't copy any data for this timestamp");
            buffer[1].Timestamp.Should().Be(timestamp, "Because we've just copied this timestamp to the buffer");
        }
コード例 #9
0
        public void TestCopyFromOverwrite()
        {
            var buffer = new LogEntryBuffer(2, LogFileColumns.RawContent);

            buffer[0].RawContent.Should().BeNull();
            buffer[1].RawContent.Should().BeNull();

            buffer.CopyFrom(LogFileColumns.RawContent, new [] { "foo", "bar" });
            buffer[0].RawContent.Should().Be("foo");
            buffer[1].RawContent.Should().Be("bar");
        }
コード例 #10
0
        public void TestCopyFromManyRows()
        {
            const int count  = 1000;
            var       buffer = new LogEntryBuffer(count, LogFileColumns.OriginalIndex);

            buffer.CopyFrom(LogFileColumns.OriginalIndex, Enumerable.Range(0, count).Select(i => (LogLineIndex)i).ToArray());
            for (int i = 0; i < count; ++i)
            {
                buffer[i].OriginalIndex.Should().Be(i);
            }
        }
コード例 #11
0
        public void TestAccessUnavailableColumn()
        {
            var buffer = new LogEntryBuffer(1);

            new Action(() => { var unused = buffer[0].RawContent; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].Index; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].OriginalIndex; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].LineNumber; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].OriginalLineNumber; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].Timestamp; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].ElapsedTime; }).ShouldThrow <ColumnNotRetrievedException>();
            new Action(() => { var unused = buffer[0].DeltaTime; }).ShouldThrow <ColumnNotRetrievedException>();
        }
コード例 #12
0
        public void TestDebuggerVisualization1()
        {
            var content = new LogEntryBuffer(2, LogFileColumns.Minimum);

            content[0].Timestamp = new DateTime(2017, 12, 20, 13, 22, 0);
            content[1].Timestamp = new DateTime(2017, 12, 20, 13, 23, 0);
            var logFile    = CreateFromContent(content);
            var visualizer = new LogFileView(logFile);
            var logEntries = visualizer.LogEntries;

            logEntries.Should().NotBeNull();
            logEntries.Should().HaveCount(2);
        }
コード例 #13
0
        public void TestGetEntriesBySection()
        {
            var logFile          = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);
            var section          = new LogFileSection(42, 5);
            var buffer           = new LogEntryBuffer(3, LogFileColumns.DeltaTime, LogFileColumns.Timestamp);
            var destinationIndex = 2;

            logFile.GetEntries(section, buffer, destinationIndex);

            _source.Verify(x => x.GetEntries(It.Is <LogFileSection>(y => y == section),
                                             It.Is <ILogEntries>(y => y == buffer),
                                             It.Is <int>(y => y == destinationIndex)),
                           Times.Once);
        }
コード例 #14
0
        public void TestAddEntry6()
        {
            var logFile = new InMemoryLogFile(LogFileColumns.LogLevel);

            var logEntry = new LogEntry2();

            logEntry.Add(LogFileColumns.LogLevel, LevelFlags.Error);
            logFile.Add(logEntry);

            var buffer = new LogEntryBuffer(1, LogFileColumns.LogLevel);

            logFile.GetEntries(new LogFileSection(0, 1), buffer);
            buffer[0].LogLevel.Should().Be(LevelFlags.Error);
        }
コード例 #15
0
        public void TestGetEntriesByIndices()
        {
            var logFile          = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);
            var indices          = new LogLineIndex[] { 0, 2, 5 };
            var buffer           = new LogEntryBuffer(3, LogFileColumns.DeltaTime, LogFileColumns.Timestamp);
            var destinationIndex = 2;

            logFile.GetEntries(indices, buffer, destinationIndex);

            _source.Verify(x => x.GetEntries(It.Is <IReadOnlyList <LogLineIndex> >(y => y == indices),
                                             It.Is <ILogEntries>(y => y == buffer),
                                             It.Is <int>(y => y == destinationIndex)),
                           Times.Once);
        }
コード例 #16
0
        public void TestCopyFromMultipleColumns()
        {
            var buffer = new LogEntryBuffer(2,
                                            LogFileColumns.Index,
                                            LogFileColumns.Timestamp);

            buffer.CopyFrom(LogFileColumns.Index, new LogLineIndex[] { 1, 42 });
            buffer.CopyFrom(LogFileColumns.Timestamp, new DateTime?[] { DateTime.MinValue, DateTime.MaxValue });

            buffer[0].Index.Should().Be(1);
            buffer[0].Timestamp.Should().Be(DateTime.MinValue);

            buffer[1].Index.Should().Be(42);
            buffer[1].Timestamp.Should().Be(DateTime.MaxValue);
        }
コード例 #17
0
ファイル: Logger.cs プロジェクト: Acedon95/DeconTools
        /// <summary>
        /// Flush entries in LogEntryBuffer to console or disk
        /// </summary>
        /// <param name="outputFile"></param>
        private void FlushLogEntries(string outputFile)
        {
            if (string.IsNullOrWhiteSpace(outputFile))
            {
                foreach (var item in LogEntryBuffer)
                {
                    Console.WriteLine(item);
                }
            }
            else
            {
                WriteToFile(outputFile);
            }

            LogEntryBuffer.Clear();
        }
コード例 #18
0
        public void TestFillDefault3()
        {
            var buffer = new LogEntryBuffer(4, LogFileColumns.DeltaTime);
            var data   = new TimeSpan?[]
            {
                TimeSpan.FromMilliseconds(1),
                TimeSpan.FromMilliseconds(5),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(10)
            };

            buffer.CopyFrom(LogFileColumns.DeltaTime, data);
            buffer.FillDefault(LogFileColumns.DeltaTime, 1, 2);

            buffer[0].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(1));
            buffer[1].DeltaTime.Should().Be(null);
            buffer[2].DeltaTime.Should().Be(null);
            buffer[3].DeltaTime.Should().Be(TimeSpan.FromSeconds(10));
        }
コード例 #19
0
        public void TestFillDefault1([Range(0, 10)] int length)
        {
            var buffer = new LogEntryBuffer(length, LogFileColumns.RawContent);
            var data   = Enumerable.Range(0, length).Select(unused => "Foo").ToArray();

            buffer.CopyFrom(LogFileColumns.RawContent, data);

            for (int i = 0; i < length; ++i)
            {
                buffer[i].RawContent.Should().Be("Foo");
            }

            buffer.FillDefault(LogFileColumns.RawContent, 0, length);

            for (int i = 0; i < length; ++i)
            {
                buffer[i].RawContent.Should().BeNull();
            }
        }
コード例 #20
0
        public void TestFillDefault2([Range(0, 10)] int length)
        {
            var buffer = new LogEntryBuffer(length, LogFileColumns.Timestamp);
            var data   = Enumerable.Range(0, length).Select(unused => (DateTime?)new DateTime(2017, 12, 12, 18, 58, 0)).ToArray();

            buffer.CopyFrom(LogFileColumns.Timestamp, data);

            for (int i = 0; i < length; ++i)
            {
                buffer[i].Timestamp.Should().Be(new DateTime(2017, 12, 12, 18, 58, 0));
            }

            buffer.FillDefault(LogFileColumns.Timestamp, 0, length);

            for (int i = 0; i < length; ++i)
            {
                buffer[i].Timestamp.Should().BeNull();
            }
        }
コード例 #21
0
        protected override IReadOnlyLogEntries Create(IEnumerable <IReadOnlyLogEntry> entries)
        {
            if (entries.Any())
            {
                var list = new LogEntryBuffer(entries.Count(), entries.First().Columns);
                int i    = 0;
                foreach (var entry in entries)
                {
                    foreach (var column in entry.Columns)
                    {
                        var value = entry.GetValue(column);
                        list[i].SetValue(column, value);
                    }
                }
                return(list);
            }

            return(CreateEmpty(new ILogFileColumn[0]));
        }
コード例 #22
0
ファイル: Logger.cs プロジェクト: Acedon95/DeconTools
        /// <summary>
        /// Add a message to log, optionally flushing cached messages to the log file
        /// </summary>
        /// <param name="desc"></param>
        /// <param name="writeCachedEntriesToDisk"></param>
        public void AddEntry(string desc, bool writeCachedEntriesToDisk = false)
        {
            var entry = new LogEntry
            {
                LogTime        = DateTime.Now,
                LogDescription = desc
            };

            LogEntryBuffer.Add(entry);
            LogEntries.Add(entry);
            TimeOfLastUpdate = DateTime.Now;

            if (!writeCachedEntriesToDisk)
            {
                return;
            }

            FlushLogEntries(Instance.OutputFilename);
        }
コード例 #23
0
        public void TestFillAllColumns2()
        {
            var buffer = new LogEntryBuffer(4, LogFileColumns.DeltaTime, LogFileColumns.Timestamp);
            var deltas = new TimeSpan?[]
            {
                TimeSpan.FromMilliseconds(1),
                TimeSpan.FromMilliseconds(5),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(10)
            };

            buffer.CopyFrom(LogFileColumns.DeltaTime, deltas);
            var timestamps = new DateTime?[]
            {
                new DateTime(2017, 12, 12, 19, 24, 0),
                new DateTime(2017, 12, 12, 19, 25, 0),
                new DateTime(2017, 12, 12, 19, 26, 0),
                new DateTime(2017, 12, 12, 19, 27, 0)
            };

            buffer.CopyFrom(LogFileColumns.Timestamp, timestamps);

            buffer[0].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(1));
            buffer[0].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 24, 0));
            buffer[1].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(5));
            buffer[1].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 25, 0));
            buffer[2].DeltaTime.Should().Be(TimeSpan.FromSeconds(3));
            buffer[2].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 26, 0));
            buffer[3].DeltaTime.Should().Be(TimeSpan.FromSeconds(10));
            buffer[3].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 27, 0));

            buffer.FillDefault(1, 2);
            buffer[0].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(1));
            buffer[0].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 24, 0));
            buffer[1].DeltaTime.Should().BeNull();
            buffer[1].Timestamp.Should().BeNull();
            buffer[2].DeltaTime.Should().BeNull();
            buffer[2].Timestamp.Should().BeNull();
            buffer[3].DeltaTime.Should().Be(TimeSpan.FromSeconds(10));
            buffer[3].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 27, 0));
        }
コード例 #24
0
        public void TestColumn()
        {
            var buffer = new LogEntryBuffer(4, LogFileColumns.DeltaTime, LogFileColumns.Timestamp);

            buffer.Column(LogFileColumns.DeltaTime).Should().Equal(new object[] { null, null, null, null });

            buffer.CopyFrom(LogFileColumns.DeltaTime, 0, new TimeSpan?[]
            {
                TimeSpan.FromDays(1),
                TimeSpan.FromSeconds(42),
                null,
                TimeSpan.FromMinutes(-10)
            },
                            0, 4);
            buffer.Column(LogFileColumns.DeltaTime).Should().Equal(new object[]
            {
                TimeSpan.FromDays(1),
                TimeSpan.FromSeconds(42),
                null,
                TimeSpan.FromMinutes(-10)
            });
        }
コード例 #25
0
        public void TestGetElapsedTimesBySection()
        {
            var content = new LogEntryBuffer(5, LogFileColumns.Timestamp);

            content.CopyFrom(LogFileColumns.Timestamp, new DateTime?[]
            {
                new DateTime(2017, 12, 19, 15, 49, 0),
                new DateTime(2017, 12, 19, 15, 49, 2),
                new DateTime(2017, 12, 19, 15, 49, 4),
                new DateTime(2017, 12, 19, 15, 49, 8),
                new DateTime(2017, 12, 19, 15, 49, 16)
            });
            var logFile = CreateFromContent(content);
            var values  = logFile.GetColumn(new LogFileSection(0, 5), LogFileColumns.ElapsedTime);

            values.Should().Equal(new object[]
            {
                null,
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(4),
                TimeSpan.FromSeconds(8)
            });
        }
コード例 #26
0
        protected override IReadOnlyLogEntry CreateEmpty()
        {
            var buffer = new LogEntryBuffer(1);

            return(buffer[0]);
        }