示例#1
0
 /// <summary>
 ///     Tries to retrieve an entry from this cache.
 /// </summary>
 /// <param name="logTable"></param>
 /// <param name="index"></param>
 /// <param name="logEntry"></param>
 /// <returns></returns>
 public bool TryGetValue(ILogTable logTable, LogEntryIndex index, out LogEntry logEntry)
 {
     lock (_syncRoot)
     {
         return(_logEntries.TryGetValue(logTable, index, out logEntry));
     }
 }
示例#2
0
        public void TestIncrement()
        {
            var idx = new LogEntryIndex(0);

            ++idx;
            idx.Should().Be(new LogEntryIndex(1));
        }
示例#3
0
 /// <summary>
 ///     Removes the given entry from this cache.
 /// </summary>
 /// <param name="logTable"></param>
 /// <param name="index"></param>
 /// <returns>true if the entry was removed, false otherwise</returns>
 public bool Remove(ILogTable logTable, LogEntryIndex index)
 {
     lock (_syncRoot)
     {
         return(_logEntries.Remove(logTable, index));
     }
 }
示例#4
0
 /// <inheritdoc />
 public ITask <LogEntry> this[LogEntryIndex index]
 {
     get
     {
         lock (_syncRoot)
         {
             return(Task2.FromResult(_entries[(int)index]));
         }
     }
 }
 public void OnRead(LogEntryIndex index, int count, bool invalidate = false)
 {
     lock (_syncRoot)
     {
         foreach (var notifier in _notifiers.Values)
         {
             notifier.EmitChanged(new LogTableModification(index, count, invalidate));
         }
     }
 }
示例#6
0
        /// <summary>
        ///     Adds the given entry to this cache.
        ///     If an entry already exists, then it will be replaced.
        /// </summary>
        /// <param name="logTable"></param>
        /// <param name="index"></param>
        /// <param name="logEntry"></param>
        public void Add(ILogTable logTable, LogEntryIndex index, LogEntry logEntry)
        {
            if (logTable == null)
            {
                throw new ArgumentNullException(nameof(logTable));
            }

            lock (_syncRoot)
            {
                _logEntries.Add(logTable, index, logEntry);
                CollectIfNecessary();
            }
        }
示例#7
0
        public bool Contains(ILogTable logTable, LogEntryIndex index)
        {
            if (logTable == null)
            {
                return(false);
            }
            if (index == LogEntryIndex.Invalid)
            {
                return(false);
            }

            lock (_syncRoot)
            {
                return(_logEntries.Contains(logTable, index));
            }
        }
示例#8
0
        public void TestConstruction9()
        {
            var lineIndex  = new LogLineIndex(1);
            var entryIndex = new LogEntryIndex(42);
            var sourceId   = new LogLineSourceId(254);
            var t          = new DateTime(2017, 11, 26, 12, 20, 1);
            var line       = new LogLine(lineIndex, entryIndex, sourceId, "Hello, World!", LevelFlags.Trace, t);

            line.LineIndex.Should().Be(1);
            line.OriginalLineIndex.Should().Be(1);
            line.LogEntryIndex.Should().Be(42);
            line.SourceId.Should().Be(sourceId);
            line.Message.Should().Be("Hello, World!");
            line.Level.Should().Be(LevelFlags.Trace);
            line.Timestamp.Should().Be(t);
            line.MatchedFilters.Should().Be(0);
        }
示例#9
0
 private void GetIndex(IReadOnlyList <LogLineIndex> indices, LogEntryIndex[] buffer, int destinationIndex)
 {
     lock (_syncRoot)
     {
         for (int i = 0; i < indices.Count; ++i)
         {
             var index = indices[i];
             if (index >= 0 && index < _entries.Count)
             {
                 buffer[destinationIndex + i] = new LogEntryIndex((int)index);
             }
             else
             {
                 buffer[destinationIndex + i] = Core.Columns.LogEntryIndex.DefaultValue;
             }
         }
     }
 }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        public void RemoveFrom(LogEntryIndex index)
        {
            lock (_syncRoot)
            {
                if (index < 0)
                {
                    Log.WarnFormat("Invalid index '{0}'", index);
                    return;
                }

                if (index > _entries.Count)
                {
                    Log.WarnFormat("Invalid index '{0}', Count is '{1}'", index, _entries.Count);
                    return;
                }

                var available = _entries.Count - index;
                _entries.RemoveRange((int)index, available);
                _listeners.Invalidate((int)index, available);
                Touch();
            }
        }
示例#11
0
        /// <summary>
        ///     Adds the given range of entries to this cache.
        /// </summary>
        /// <param name="logTable"></param>
        /// <param name="startIndex"></param>
        /// <param name="logEntries"></param>
        public void AddRange(ILogTable logTable, LogEntryIndex startIndex, IEnumerable <LogEntry> logEntries)
        {
            if (logTable == null)
            {
                throw new ArgumentNullException(nameof(logTable));
            }

            lock (_syncRoot)
            {
                LogEntryIndex index = startIndex;
                foreach (var logEntry in logEntries)
                {
                    _logEntries.Add(logTable, index, logEntry);
                    ++index;
                }

                // We DO NOT want to collect inside the loop.
                // Not doing so breaks the promise of not consuming more memory
                // than configured, however that is a very weak promise from the start
                // and thus we do not bother at trying to *strictly* keep it. Instead we
                // see it as a guideline not not exceed it too often or by too much (tm).
                CollectIfNecessary();
            }
        }
示例#12
0
 public LogEntryInfo(LogEntryIndex entryIndex, LogLineIndex firstLineIndex)
 {
     EntryIndex     = entryIndex;
     FirstLineIndex = firstLineIndex;
 }
示例#13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="index"></param>
 /// <param name="count"></param>
 /// <param name="isInvalidate"></param>
 public LogTableModification(LogEntryIndex index, int count, bool isInvalidate = false)
 {
     Section      = new LogTableSection(index, count);
     IsInvalidate = isInvalidate;
     Schema       = null;
 }
示例#14
0
 public void TestIncrement()
 {
     var idx = new LogEntryIndex(0);
     ++idx;
     idx.Should().Be(new LogEntryIndex(1));
 }
示例#15
0
 public ITask<LogEntry> this[LogEntryIndex index]
 {
     get { throw new NotImplementedException(); }
 }
示例#16
0
 /// <summary>
 ///     Initializes this section.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="count"></param>
 public LogTableSection(LogEntryIndex index, int count)
 {
     Index = index;
     Count = count;
 }
示例#17
0
 public LogLine(LogLineIndex lineIndex, LogEntryIndex logEntryIndex, string message, LevelFlags level, DateTime?timestamp)
     : this((int)lineIndex, (int)logEntryIndex, message, level, timestamp)
 {
 }
示例#18
0
 public ITask<LogEntry> this[LogEntryIndex index]
 {
     get { return _accessQueue[index]; }
 }
示例#19
0
 /// <inheritdoc />
 public ITask <LogEntry> this[LogEntryIndex index]
 {
     get { throw new NotImplementedException(); }
 }
示例#20
0
 public LogLine(LogLineIndex lineIndex, LogEntryIndex logEntryIndex, LogLineSourceId sourceId, string message, LevelFlags level, DateTime?timestamp)
     : this((int)lineIndex, (int)lineIndex, (int)logEntryIndex, sourceId, message, level, timestamp, matchedFilters : 0)
 {
 }
示例#21
0
 public LogLine(LogLineIndex lineIndex, LogEntryIndex logEntryIndex, LogLine line)
     : this((int)lineIndex, (int)logEntryIndex, line.Message, line.Level, line.Timestamp)
 {
 }