Ejemplo n.º 1
0
 /// <summary>
 /// Initializes the table type descriptor.
 /// </summary>
 private void Initialize()
 {
     this.AllColumns        = this.Columns.Select(c => new ColumnDescriptor(c, this.Constraints.Where(x => x.FromColumnName == c.Name))).Cast <IColumnDescriptor>().ToList();
     this.SimpleColumns     = this.AllColumns.Where(x => !x.IsIdentity).ToList();
     this.PrimaryKeyColumns = this.AllColumns.Where(x => x.IsPrimaryKey).ToList();
     this.IdentityColumn    = this.AllColumns.FirstOrDefault(x => x.IsIdentity);
 }
Ejemplo n.º 2
0
        static Columns()
        {
            RawContent             = new WellKnownColumnDescriptor <string>("raw_content");
            Index                  = new WellKnownColumnDescriptor <LogLineIndex>("index", LogLineIndex.Invalid);
            OriginalIndex          = new WellKnownColumnDescriptor <LogLineIndex>("original_index", LogLineIndex.Invalid);
            LogEntryIndex          = new WellKnownColumnDescriptor <LogEntryIndex>("log_entry_index", Api.LogEntryIndex.Invalid);
            LineNumber             = new WellKnownColumnDescriptor <int>("line_number");
            OriginalLineNumber     = new WellKnownColumnDescriptor <int>("original_line_number");
            OriginalDataSourceName = new WellKnownColumnDescriptor <string>("original_data_source_name");
            SourceId               = new WellKnownColumnDescriptor <LogEntrySourceId>("source_id");
            LogLevel               = new WellKnownColumnDescriptor <LevelFlags>("log_level");
            Timestamp              = new WellKnownColumnDescriptor <DateTime?>("timestamp");
            ElapsedTime            = new WellKnownColumnDescriptor <TimeSpan?>("elapsed_time");
            DeltaTime              = new WellKnownColumnDescriptor <TimeSpan?>("delta_time");
            Message                = new WellKnownColumnDescriptor <string>("message", "Message");

            Minimum = new IColumnDescriptor[]
            {
                RawContent,
                Index,
                OriginalIndex,
                LogEntryIndex,
                LineNumber,
                OriginalLineNumber,
                OriginalDataSourceName,
                LogLevel,
                Timestamp,
                ElapsedTime,
                DeltaTime
            };
        }
Ejemplo n.º 3
0
 public void GetColumn <T>(IReadOnlyList <LogLineIndex> sourceIndices,
                           IColumnDescriptor <T> column,
                           T[] destination,
                           int destinationIndex,
                           LogSourceQueryOptions queryOptions)
 {
     if (ReferenceEquals(column, Core.Columns.RawContent))
     {
         var view = new SingleColumnLogBufferView <T>(column, destination, destinationIndex, sourceIndices.Count);
         ReadRawData(sourceIndices, view, 0, queryOptions);
     }
     else if (ReferenceEquals(column, Core.Columns.Index))
     {
         GetIndices(sourceIndices, (LogLineIndex[])(object)destination, destinationIndex);
     }
     else if (ReferenceEquals(column, StreamingTextLogSource.LineOffsetInBytes))
     {
         lock (_index)
         {
             _index.CopyTo(column, sourceIndices, destination, destinationIndex);
         }
     }
     else
     {
         throw new NoSuchColumnException(column);
     }
 }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public void GetColumn <T>(IReadOnlyList <LogLineIndex> sourceIndices,
                                  IColumnDescriptor <T> column,
                                  T[] destination,
                                  int destinationIndex,
                                  LogSourceQueryOptions queryOptions)
        {
            if (sourceIndices == null)
            {
                throw new ArgumentNullException(nameof(sourceIndices));
            }
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }
            if (destinationIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(destinationIndex));
            }
            if (destinationIndex + sourceIndices.Count > destination.Length)
            {
                throw new ArgumentException("The given buffer must have an equal or greater length than destinationIndex+length");
            }

            GetEntries(sourceIndices,
                       new SingleColumnLogBufferView <T>(column, destination, destinationIndex, sourceIndices.Count),
                       0, queryOptions);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public void CopyTo <T>(IColumnDescriptor <T> column, int sourceIndex, T[] destination, int destinationIndex, int length)
        {
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }
            if (destinationIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(destinationIndex));
            }
            if (destinationIndex + length > destination.Length)
            {
                throw new ArgumentException("The given buffer must have an equal or greater length than destinationIndex+length");
            }

            if (_dataByColumn.TryGetValue(column, out var data))
            {
                ((ColumnData <T>)data).CopyTo(sourceIndex, destination, destinationIndex, length);
            }
            else
            {
                throw new NoSuchColumnException(column);
            }
        }
Ejemplo n.º 6
0
        private string GetMultipleConstraintString()
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair> MultipleConstraintList = Context.MultipleConstraintList;

            string TableName = Table.Name;

            string ConstraintString = "";

            foreach (IColumnValuePair Entry in MultipleConstraintList)
            {
                IColumnDescriptor ConstraintColumn = Entry.Column;
                object            Value            = Entry.Value;
                string            ColumnName       = ConstraintColumn.Name;
                IColumnType       ColumnType       = ConstraintColumn.Type;

                if (ConstraintString.Length > 0)
                {
                    ConstraintString += " AND ";
                }

                string FormattedValue = ColumnType.ToSqlFormat(Value);
                ConstraintString += $"({ColumnName}={FormattedValue})";
            }

            return(ConstraintString);
        }
Ejemplo n.º 7
0
        private string GetSingleConstraintString()
        {
            ITableDescriptor           Table = Context.Table;
            IColumnValueCollectionPair SingleConstraintEntry = Context.SingleConstraintEntry;

            Debug.Assert(SingleConstraintEntry != null);

            string            TableName        = Table.Name;
            IColumnDescriptor ConstraintColumn = SingleConstraintEntry.Column;
            string            ColumnName       = ConstraintColumn.Name;
            IColumnType       ColumnType       = ConstraintColumn.Type;

            string ConstraintString = "";

            foreach (object Value in SingleConstraintEntry.ValueCollection)
            {
                if (ConstraintString.Length > 0)
                {
                    ConstraintString += " OR ";
                }

                string FormattedValue = ColumnType.ToSqlFormat(Value);

                ConstraintString += $"({ColumnName}={FormattedValue})";
            }

            return(ConstraintString);
        }
Ejemplo n.º 8
0
        private static IReadOnlyList <MergedLogSourceSection> GetEntries(
            IEnumerable <MergedLogSourcePendingModification> pendingModifications)
        {
            var columns = new IColumnDescriptor[]
            {
                Columns.Index,
                Columns.LogEntryIndex,
                Columns.Timestamp
            };

            var sections = new List <MergedLogSourceSection>();

            foreach (var pendingModification in pendingModifications)
            {
                var logFile      = pendingModification.LogSource;
                var modification = pendingModification.Modification;
                if (modification.IsAppended(out var appendSection))
                {
                    var entries = logFile.GetEntries(appendSection, columns);
                    sections.Add(new MergedLogSourceSection(logFile, modification, entries));
                }
                else
                {
                    sections.Add(new MergedLogSourceSection(logFile, modification));
                }
            }

            return(sections);
        }
Ejemplo n.º 9
0
 /// <summary>
 ///     Retrieves a list of cells for a given column from this log file.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="logSource"></param>
 /// <param name="sourceIndices"></param>
 /// <param name="column"></param>
 /// <param name="destination"></param>
 public static void GetColumn <T>(this ILogSource logSource,
                                  IReadOnlyList <LogLineIndex> sourceIndices,
                                  IColumnDescriptor <T> column,
                                  T[] destination)
 {
     logSource.GetColumn(sourceIndices, column, destination, 0, LogSourceQueryOptions.Default);
 }
Ejemplo n.º 10
0
        /// <inheritdoc />
        public void GetColumn <T>(IReadOnlyList <LogLineIndex> sourceIndices, IColumnDescriptor <T> column, T[] destination, int destinationIndex, LogSourceQueryOptions queryOptions)
        {
            if (sourceIndices == null)
            {
                throw new ArgumentNullException(nameof(sourceIndices));
            }
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }
            if (destinationIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(destinationIndex));
            }
            if (destinationIndex + sourceIndices.Count > destination.Length)
            {
                throw new ArgumentException("The given buffer must have an equal or greater length than destinationIndex+length");
            }

            try
            {
                _logSource.GetColumn(sourceIndices, column, destination, destinationIndex, queryOptions);
            }
            catch (Exception e)
            {
                BlameExceptionOnPlugin(e);
            }
        }
Ejemplo n.º 11
0
        public override void GetColumn <T>(IReadOnlyList <LogLineIndex> sourceIndices,
                                           IColumnDescriptor <T> column,
                                           T[] destination,
                                           int destinationIndex,
                                           LogSourceQueryOptions queryOptions)
        {
            var source = _finalLogSource;

            if (source != null)
            {
                source.GetColumn(sourceIndices, column, destination, destinationIndex, queryOptions);
            }
            else
            {
                if (sourceIndices == null)
                {
                    throw new ArgumentNullException(nameof(sourceIndices));
                }
                if (column == null)
                {
                    throw new ArgumentNullException(nameof(column));
                }
                if (destination == null)
                {
                    throw new ArgumentNullException(nameof(destination));
                }
                if (destinationIndex < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(destinationIndex));
                }

                destination.Fill(column.DefaultValue, destinationIndex, sourceIndices.Count);
            }
        }
Ejemplo n.º 12
0
        public void TestFillDefault()
        {
            var columns = new IColumnDescriptor[] { Core.Columns.Message, Core.Columns.LogLevel };
            var entries = new[]
            {
                new LogEntry(columns)
                {
                    Message = "Foo", LogLevel = LevelFlags.Fatal
                },
                new LogEntry(columns)
                {
                    Message = "Bar", LogLevel = LevelFlags.Info
                },
                new LogEntry(columns)
                {
                    Message = "Sup", LogLevel = LevelFlags.Debug
                }
            };

            var buffer = Create(entries);

            buffer.Count.Should().Be(3);

            buffer.FillDefault(1, 2);
            buffer[0].Message.Should().Be("Foo", "because we wanted to fill everything from log entry 1 onwards with default values - 0 should have been spared");
            buffer[0].LogLevel.Should().Be(LevelFlags.Fatal, "because we wanted to fill everything from log entry 1 onwards with default values - 0 should have been spared");

            buffer[1].Message.Should().Be(Core.Columns.Message.DefaultValue);
            buffer[1].LogLevel.Should().Be(Core.Columns.LogLevel.DefaultValue);
            buffer[2].Message.Should().Be(Core.Columns.Message.DefaultValue);
            buffer[2].LogLevel.Should().Be(Core.Columns.LogLevel.DefaultValue);
        }
Ejemplo n.º 13
0
        public void TestFillDefault_InvalidOffsetPlusCount()
        {
            var columns = new IColumnDescriptor[] { Core.Columns.Message, Core.Columns.LogLevel };
            var entries = new[]
            {
                new LogEntry(columns)
                {
                    Message = "Foo", LogLevel = LevelFlags.Fatal
                },
                new LogEntry(columns)
                {
                    Message = "Bar", LogLevel = LevelFlags.Info
                },
                new LogEntry(columns)
                {
                    Message = "Sup", LogLevel = LevelFlags.Debug
                }
            };

            var buffer = Create(entries);

            buffer.Count.Should().Be(3);

            new Action(() => buffer.FillDefault(1, 3)).Should().Throw <ArgumentException>();
            buffer[0].Message.Should().Be("Foo", "because the data may not have been modified");
            buffer[0].LogLevel.Should().Be(LevelFlags.Fatal, "because the data may not have been modified");
            buffer[1].Message.Should().Be("Bar", "because the data may not have been modified");
            buffer[1].LogLevel.Should().Be(LevelFlags.Info, "because the data may not have been modified");
            buffer[2].Message.Should().Be("Sup", "because the data may not have been modified");
            buffer[2].LogLevel.Should().Be(LevelFlags.Debug, "because the data may not have been modified");
        }
Ejemplo n.º 14
0
        public void TestFillDefault_NoSuchColumn()
        {
            var columns = new IColumnDescriptor[] { Core.Columns.Message, Core.Columns.LogLevel };
            var entries = new[]
            {
                new LogEntry(columns)
                {
                    Message = "Foo", LogLevel = LevelFlags.Fatal
                },
                new LogEntry(columns)
                {
                    Message = "Bar", LogLevel = LevelFlags.Info
                }
            };

            var buffer = Create(entries);

            buffer.Count.Should().Be(2);

            new Action(() => buffer.FillDefault(Core.Columns.RawContent, 0, 2))
            .Should().Throw <NoSuchColumnException>();

            buffer[0].Message.Should().Be("Foo", "because the message may not have been modified");
            buffer[1].Message.Should().Be("Bar", "because the message may not have been modified");
            buffer[0].LogLevel.Should().Be(LevelFlags.Fatal, "because the log level may not have been modified");
            buffer[1].LogLevel.Should().Be(LevelFlags.Info, "because the log level may not have been modified");
        }
        protected virtual bool GetSingleConstraintString(out string constraintString)
        {
            ITableDescriptor           Table = Context.Table;
            IColumnValueCollectionPair SingleConstraintEntry = Context.SingleConstraintEntry;

            if (SingleConstraintEntry != null)
            {
                string            TableName        = Table.Name;
                IColumnDescriptor ConstraintColumn = SingleConstraintEntry.Column;
                string            ColumnName       = ConstraintColumn.Name;
                IColumnType       ColumnType       = ConstraintColumn.Type;

                constraintString = "";
                foreach (object Value in SingleConstraintEntry.ValueCollection)
                {
                    if (constraintString.Length > 0)
                    {
                        constraintString += " OR ";
                    }

                    string FormattedValue = ColumnType.ToSqlFormat(Value);

                    constraintString += "(" + ColumnName + "=" + FormattedValue + ")";
                }

                return(true);
            }
            else
            {
                constraintString = null;
                return(false);
            }
        }
        private bool GetMultipleConstraintString(out string constraintString)
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair> MultipleConstraintList = Context.MultipleConstraintList;

            string TableName = Table.Name;

            constraintString = "";
            foreach (IColumnValuePair Entry in MultipleConstraintList)
            {
                IColumnDescriptor ConstraintColumn = Entry.Column;
                object            Value            = Entry.Value;
                string            ColumnName       = ConstraintColumn.Name;
                IColumnType       ColumnType       = ConstraintColumn.Type;

                if (constraintString.Length > 0)
                {
                    constraintString += " AND ";
                }

                string FormattedValue = ColumnType.ToSqlFormat(Value);
                constraintString += "(" + ColumnName + "=" + FormattedValue + ")";
            }

            return(true);
        }
Ejemplo n.º 17
0
        /// <inheritdoc />
        public void GetColumn <T>(IReadOnlyList <LogLineIndex> sourceIndices, IColumnDescriptor <T> column, T[] destination, int destinationIndex, LogSourceQueryOptions queryOptions)
        {
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            ILogSource logSource = _source;

            if (logSource != null)
            {
                logSource.GetColumn(sourceIndices, column, destination, destinationIndex, queryOptions);
            }
            else
            {
                if (sourceIndices == null)
                {
                    throw new ArgumentNullException(nameof(sourceIndices));
                }
                if (destinationIndex < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(destinationIndex));
                }
                if (destinationIndex + sourceIndices.Count > destination.Length)
                {
                    throw new ArgumentException("The given buffer must have an equal or greater length than destinationIndex+length");
                }

                destination.Fill(column.DefaultValue, destinationIndex, sourceIndices.Count);
            }
        }
Ejemplo n.º 18
0
        private bool IsJoinValid(IReadOnlyDictionary <IColumnDescriptor, IColumnDescriptor> columns)
        {
            Dictionary <IColumnDescriptor, IColumnDescriptor> TestJoin = new Dictionary <IColumnDescriptor, IColumnDescriptor>();

            foreach (KeyValuePair <IColumnDescriptor, IColumnDescriptor> Entry in columns)
            {
                TestJoin.Add(Entry.Key, Entry.Value);
            }

            while (TestJoin.Count > 0)
            {
                IColumnDescriptor TestColumn = null;
                foreach (KeyValuePair <IColumnDescriptor, IColumnDescriptor> Entry in TestJoin)
                {
                    TestColumn = Entry.Key;
                    break;
                }

                IColumnDescriptor NextColumn = TestColumn;
                while (NextColumn != null && TestJoin.ContainsKey(NextColumn))
                {
                    NextColumn = TestJoin[NextColumn];
                    TestJoin.Remove(TestColumn);

                    if (NextColumn == TestColumn)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 19
0
        private void GetSourceColumnValues <T>(IColumnDescriptor <T> column, Dictionary <int, Stuff <T> > originalBuffers, LogSourceQueryOptions queryOptions)
        {
            foreach (var pair in originalBuffers)
            {
                var sourceLogFileIndex = pair.Key;
                var stuff        = pair.Value;
                var indices      = stuff.OriginalLogLineIndices;
                var columnBuffer = stuff.Buffer;

                if (sourceLogFileIndex >= 0 &&
                    sourceLogFileIndex < _sources.Count)
                {
                    var sourceLogFile = _sources[sourceLogFileIndex];
                    if (sourceLogFile.Columns.Contains(column))
                    {
                        sourceLogFile.GetColumn(indices, column, columnBuffer, 0, queryOptions);
                    }
                }
                else
                {
                    // Someone should be on the naughty list for trying to access a portion
                    // which cannot be accessed! Anyhow, we fill the buffer with default values.
                    columnBuffer.Fill(column.DefaultValue, 0, indices.Count);
                }
            }
        }
        protected virtual string GetConstraintString()
        {
            ITableDescriptor Table = Context.Table;
            IReadOnlyCollection <IColumnValuePair> ConstraintList = Context.ConstraintList;

            Debug.Assert(ConstraintList != null);
            Debug.Assert(ConstraintList.Count > 0);

            string TableName = Table.Name;

            string ConstraintString = "";

            foreach (IColumnValuePair Entry in ConstraintList)
            {
                IColumnDescriptor Column = Entry.Column;
                object            Value  = Entry.Value;

                if (ConstraintString.Length > 0)
                {
                    ConstraintString += " AND ";
                }

                string ColumnName = Column.Name;

                IColumnType ColumnType     = Column.Type;
                string      FormattedValue = ColumnType.ToSqlFormat(Value);

                ConstraintString += "(" + ColumnName + "=" + FormattedValue + ")";
            }

            Debug.Assert(!string.IsNullOrEmpty(ConstraintString));
            return(ConstraintString);
        }
Ejemplo n.º 21
0
 /// <summary>
 ///     Copies the given *non-contiguous* segment of data from the given log file into this buffer in a contiguous block.
 /// </summary>
 /// <remarks>
 ///     This buffer must be large enough already to accomodate the data.
 /// </remarks>
 /// <param name="that"></param>
 /// <param name="column">The column to copy the data from the log file to this buffer</param>
 /// <param name="destinationIndex">The first index in this buffer to which the data from the given <paramref name="source" /> is copied</param>
 /// <param name="source">The log file from which data should be copied from</param>
 /// <param name="sourceIndices">The non-contiguous section of the log file from which to copy from (e.g. from index 5, 10 entries)</param>
 public static void CopyFrom(this ILogBuffer that,
                             IColumnDescriptor column,
                             int destinationIndex,
                             ILogSource source,
                             IReadOnlyList <LogLineIndex> sourceIndices)
 {
     that.CopyFrom(column, destinationIndex, source, sourceIndices, LogSourceQueryOptions.Default);
 }
Ejemplo n.º 22
0
 /// <inheritdoc />
 public void CopyFrom(IColumnDescriptor column,
                      int destinationIndex,
                      ILogSource source,
                      IReadOnlyList <LogLineIndex> sourceIndices,
                      LogSourceQueryOptions queryOptions)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 23
0
 /// <inheritdoc />
 public void GetColumn <T>(IReadOnlyList <LogLineIndex> sourceIndices,
                           IColumnDescriptor <T> column,
                           T[] destination,
                           int destinationIndex,
                           LogSourceQueryOptions queryOptions)
 {
     _buffer.GetColumn(sourceIndices, column, destination, destinationIndex, queryOptions);
 }
Ejemplo n.º 24
0
            public override void SetValue(IColumnDescriptor column, object value)
            {
                if (!Equals(_buffer._column, column))
                {
                    throw new NoSuchColumnException(column);
                }

                _buffer._buffer[_buffer._offset + _index] = (T)value;
            }
Ejemplo n.º 25
0
            public override object GetValue(IColumnDescriptor column)
            {
                if (!Equals(_buffer._column, column))
                {
                    throw new ColumnNotRetrievedException(column);
                }

                return(_buffer._buffer[_buffer._offset + _index]);
            }
Ejemplo n.º 26
0
        private void InitFilters(IColumnDescriptor filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            InitFilters(new IColumnDescriptor[] { filter });
        }
Ejemplo n.º 27
0
            public override object GetValue(IColumnDescriptor column)
            {
                if (!TryGetValue(column, out var value))
                {
                    throw new ColumnNotRetrievedException(column);
                }

                return(value);
            }
Ejemplo n.º 28
0
            public override void SetValue(IColumnDescriptor column, object value)
            {
                if (!_array._dataByColumn.TryGetValue(column, out var data))
                {
                    throw new ColumnNotRetrievedException(column);
                }

                data[_index] = value;
            }
Ejemplo n.º 29
0
            public override void SetValue <T>(IColumnDescriptor <T> column, T value)
            {
                if (!_array._dataByColumn.TryGetValue(column, out var data))
                {
                    throw new ColumnNotRetrievedException(column);
                }

                ((ColumnData <T>)data)[_index] = value;
            }
Ejemplo n.º 30
0
        /// <inheritdoc />
        public void FillDefault(IColumnDescriptor column, int destinationIndex, int length)
        {
            if (!Equals(column, _column))
            {
                throw new NoSuchColumnException(column);
            }

            FillDefault(destinationIndex, length);
        }
Ejemplo n.º 31
0
 public override bool PaintBackground(System.Drawing.Graphics g, System.Drawing.Rectangle renderRect, IColumnDescriptor columnDescriptor, IStyle style)
 {
     return false;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// 컨텐츠를 그리는 부분입니다.
 /// </summary>
 /// <returns>
 /// 반환값이 false인 경우 기본 컨텐츠를 그려줍니다.
 /// </returns>
 public override bool PaintContents(System.Drawing.Graphics g, System.Drawing.Rectangle renderRect, IColumnDescriptor columnDescriptor, IStyle style)
 {
     string text = string.Format("{0}({1})", columnDescriptor.ColumnState, _clickCount);
     g.DrawString(text, style.Font, Brushes.Black, renderRect, _stringFormat);
     return true;
 }
Ejemplo n.º 33
0
 public override bool PaintContents(System.Drawing.Graphics g, System.Drawing.Rectangle renderRect, IColumnDescriptor columnDescriptor, IStyle style)
 {
     Rectangle buttonRectangle = ComputeButtonRectangle(renderRect);
     g.DrawImage(Properties.Resources.ButtonImage, buttonRectangle);
     return false;
 }