Exemplo n.º 1
0
        private void ToolButtonClick(ToolEntry toolEntry)
        {
            if (string.IsNullOrEmpty(toolEntry.cmd))
            {
                //TODO TabIndex => To Enum
                OpenSettings(2);
                return;
            }

            if (CurrentLogWindow != null)
            {
                ILogLine     line = CurrentLogWindow.GetCurrentLine();
                ILogFileInfo info = CurrentLogWindow.GetCurrentFileInfo();
                if (line != null && info != null)
                {
                    ArgParser parser  = new ArgParser(toolEntry.args);
                    string    argLine = parser.BuildArgs(line, CurrentLogWindow.GetRealLineNum() + 1, info, this);
                    if (argLine != null)
                    {
                        StartTool(toolEntry.cmd, argLine, toolEntry.sysout, toolEntry.columnizerName,
                                  toolEntry.workingDir);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public bool WriteToPipe(ILogLine textLine, int orgLineNum)
 {
     try
     {
         lock (this.FileName)
         {
             lock (this.lineMappingList)
             {
                 try
                 {
                     this.writer.WriteLine(textLine.FullLine);
                     this.lineMappingList.Add(orgLineNum);
                     return(true);
                 }
                 catch (IOException e)
                 {
                     Logger.logError("writeToPipe(): " + e.ToString());
                     return(false);
                 }
             }
         }
     }
     catch (IOException)
     {
         Logger.logError("writeToPipe(): file was closed: " + this.FileName);
         return(false);
     }
 }
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            if (line.LineNumber == 0 || line.FullLine == EndOfLogMessage)
            {
                return(null);
            }

            var columns = new List <IColumn>();
            ColumnizedLogLine columnizedLogLine = new ColumnizedLogLine();

            columnizedLogLine.LogLine = line;

            var logParts = line.FullLine.Split(new string[] { StatsAndMessageSeperator }, StringSplitOptions.RemoveEmptyEntries);

            if (logParts.Length == 2)
            {
                var informationParts = logParts[0].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                var messagePart      = logParts[1];

                columns.AddRange(informationParts.ToList().Take(4).Select(p => GetColumn(columnizedLogLine, p)).ToList());
                columns.Add(GetColumn(columnizedLogLine, messagePart));
                columns.AddRange(informationParts.ToList().Skip(4).Take(3).Select(p => GetColumn(columnizedLogLine, p)).ToList());
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    columns.Add(GetColumn(columnizedLogLine, string.Empty));
                }
                columns.Add(GetColumn(columnizedLogLine, line.FullLine));
            }

            columnizedLogLine.ColumnValues = columns.ToArray();
            return(columnizedLogLine);
        }
Exemplo n.º 4
0
        public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine line)
        {
            IColumnizedLogLine cols = SplitLine(callback, line);

            if (cols == null || cols.ColumnValues.Length < 8)
            {
                return(DateTime.MinValue);
            }

            if (cols.ColumnValues[2].FullValue.Length == 0)
            {
                return(DateTime.MinValue);
            }

            try
            {
                DateTime dateTime = DateTime.ParseExact(cols.ColumnValues[2].FullValue, "dd/MMM/yyyy:HH:mm:ss zzz",
                                                        new CultureInfo("en-US"));
                return(dateTime);
            }
            catch (Exception)
            {
                return(DateTime.MinValue);
            }
        }
Exemplo n.º 5
0
        private IColumnizedLogLine SplitCsvLine(ILogLine line)
        {
            ColumnizedLogLine cLogLine = new ColumnizedLogLine();

            cLogLine.LogLine = line;

            using (CsvReader csv = new CsvReader(new StringReader(line.FullLine),
                                                 false,
                                                 config.delimiterChar,
                                                 config.quoteChar,
                                                 config.escapeChar, // is '\0' when not checked in config dlg
                                                 config.commentChar,
                                                 ValueTrimmingOptions.None))
            {
                csv.ReadNextRecord();
                int fieldCount = csv.FieldCount;

                List <Column> columns = new List <Column>();

                for (int i = 0; i < fieldCount; ++i)
                {
                    columns.Add(new Column {
                        FullValue = csv[i], Parent = cLogLine
                    });
                }

                cLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();

                return(cLogLine);
            }
        }
Exemplo n.º 6
0
 public bool WriteToPipe(ILogLine textLine, int orgLineNum)
 {
     try
     {
         lock (this.FileName)
         {
             lock (this.lineMappingList)
             {
                 try
                 {
                     this.writer.WriteLine(textLine.FullLine);
                     this.lineMappingList.Add(orgLineNum);
                     return(true);
                 }
                 catch (IOException e)
                 {
                     _logger.Error(e, "writeToPipe()");
                     return(false);
                 }
             }
         }
     }
     catch (IOException ex)
     {
         _logger.Error(ex, "writeToPipe(): file was closed");
         return(false);
     }
 }
Exemplo n.º 7
0
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            ColumnizedLogLine logLine = new ColumnizedLogLine();

            logLine.ColumnValues = new IColumn[columns.Length];
            if (Regex != null)
            {
                var m = Regex.Match(line.FullLine);
                for (int i = m.Groups.Count - 1; i > 0; i--)
                {
                    logLine.ColumnValues[i - 1] = new Column
                    {
                        Parent    = logLine,
                        FullValue = m.Groups[i].Value
                    };
                }
            }
            else
            {
                IColumn colVal = new Column
                {
                    Parent    = logLine,
                    FullValue = line.FullLine
                };

                logLine.ColumnValues[0] = colVal;
            }
            logLine.LogLine = line;
            return(logLine);
        }
Exemplo n.º 8
0
        public void GetColumnNames_HappyFile_ColumnNameMatches(string fileName, string expectedHeaders)
        {
            var           jsonColumnizer = new JsonColumnizer.JsonColumnizer();
            string        path           = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
            LogfileReader reader         = new LogfileReader(path, new EncodingOptions(), true, 40, 50, new MultifileOptions());

            reader.ReadFiles();

            ILogLine line = reader.GetLogLineWithWait(0);

            if (line != null)
            {
                jsonColumnizer.SplitLine(null, line);
            }

            line = reader.GetLogLineWithWait(1);
            if (line != null)
            {
                jsonColumnizer.SplitLine(null, line);
            }

            var columnHeaders = jsonColumnizer.GetColumnNames();
            var result        = string.Join(" ", columnHeaders);

            Assert.AreEqual(result, expectedHeaders);
        }
Exemplo n.º 9
0
 private static JObject ParseJson(ILogLine line)
 {
     return(JsonConvert.DeserializeObject <JObject>(line.FullLine, new JsonSerializerSettings()
     {
         Error = (sender, args) => { args.ErrorContext.Handled = true; } //We ignore the error and handle the null value
     }));
 }
Exemplo n.º 10
0
        public string ReplaceParams(ILogLine logLine, int lineNum, string fileName)
        {
            FileInfo      fileInfo = new FileInfo(fileName);
            StringBuilder builder  = new StringBuilder(this.argLine);

            builder.Replace("%L", "" + lineNum);
            builder.Replace("%P",
                            fileInfo.DirectoryName.Contains(" ") ? "\"" + fileInfo.DirectoryName + "\"" : fileInfo.DirectoryName);
            builder.Replace("%N", fileInfo.Name.Contains(" ") ? "\"" + fileInfo.Name + "\"" : fileInfo.Name);
            builder.Replace("%F",
                            fileInfo.FullName.Contains(" ") ? "\"" + fileInfo.FullName + "\"" : fileInfo.FullName);
            builder.Replace("%E",
                            fileInfo.Extension.Contains(" ") ? "\"" + fileInfo.Extension + "\"" : fileInfo.Extension);
            string stripped = StripExtension(fileInfo.Name);

            builder.Replace("%M", stripped.Contains(" ") ? "\"" + stripped + "\"" : stripped);
            int    sPos = 0;
            string reg;
            string replace;

            do
            {
                reg     = GetNextGroup(builder, ref sPos);
                replace = GetNextGroup(builder, ref sPos);
                if (reg != null && replace != null)
                {
                    string result = Regex.Replace(logLine.FullLine, reg, replace);
                    builder.Insert(sPos, result);
                }
            } while (replace != null);
            return(builder.ToString());
        }
Exemplo n.º 11
0
        public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine line)
        {
            IColumnizedLogLine cols = SplitLine(callback, line);

            if (cols == null || cols.ColumnValues == null || cols.ColumnValues.Length < 2)
            {
                return(DateTime.MinValue);
            }
            if (cols.ColumnValues[0].FullValue.Length == 0 || cols.ColumnValues[1].FullValue.Length == 0)
            {
                return(DateTime.MinValue);
            }
            FormatInfo formatInfo = _timeFormatDeterminer.DetermineDateTimeFormatInfo(line.FullLine);

            if (formatInfo == null)
            {
                return(DateTime.MinValue);
            }

            try
            {
                DateTime dateTime = DateTime.ParseExact(
                    cols.ColumnValues[0].FullValue + " " + cols.ColumnValues[1].FullValue, formatInfo.DateTimeFormat,
                    formatInfo.CultureInfo);
                return(dateTime);
            }
            catch (Exception)
            {
                return(DateTime.MinValue);
            }
        }
Exemplo n.º 12
0
        public void AddLine(ILogLine line, long filePos)
        {
            this.logLines.Add(line);
#if DEBUG
            this.filePositions.Add(filePos);
#endif
            this.LineCount++;
            IsDisposed = false;
        }
Exemplo n.º 13
0
        public ILogLine GetLineTextForClipboard(ILogLine logLine, ILogLineColumnizerCallback callback)
        {
            Log4JLogLine line = new Log4JLogLine
            {
                FullLine = logLine.FullLine.Replace(separatorChar, '|'),
                LineNumber = logLine.LineNumber
            };

            return line;
        }
Exemplo n.º 14
0
        //
        // Following two log lines should be loaded and displayed in correct grid.
        // {"time":"2019-02-13T02:55:35.5186240Z","message":"Hosting starting"}
        // {"time":"2019-02-13T02:55:35.5186240Z","level":"warning", "message":"invalid host."}
        //
        protected virtual IColumnizedLogLine SplitJsonLine(ILogLine line, JObject json)
        {
            var cLogLine = new ColumnizedLogLine {
                LogLine = line
            };

            var columns = json.Properties().Select(property => new ColumnWithName {
                FullValue = property.Value.ToString(), ColumneName = property.Name.ToString(), Parent = cLogLine
            }).ToList();

            foreach (var jsonColumn in columns)
            {
                // When find new column in a log line, add a new column in the end of the list.
                if (!ColumnSet.Contains(jsonColumn.ColumneName))
                {
                    if (ColumnList.Count == 1 && !ColumnSet.Contains(ColumnList[0].Name))
                    {
                        ColumnList.Clear();
                    }

                    ColumnSet.Add(jsonColumn.ColumneName);
                    ColumnList.Add(new JsonColumn(jsonColumn.ColumneName));
                }
            }

            //
            // Always rearrage the order of all json fields within a line to follow the sequence of columnNameList.
            // This will make sure the log line displayed correct even the order of json fields changed.
            //
            List <IColumn> returnColumns = new List <IColumn>();

            foreach (var column in ColumnList)
            {
                var existingColumn = columns.Find(x => x.ColumneName == column.Name);
                if (existingColumn != null)
                {
                    returnColumns.Add(new Column()
                    {
                        FullValue = existingColumn.FullValue, Parent = cLogLine
                    });
                    continue;
                }

                // Fields that is missing in current line should be shown as empty.
                returnColumns.Add(new Column()
                {
                    FullValue = "", Parent = cLogLine
                });
            }

            cLogLine.ColumnValues = returnColumns.ToArray();

            return(cLogLine);
        }
Exemplo n.º 15
0
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            ColumnizedLogLine columnizedLogLine = new ColumnizedLogLine();

            columnizedLogLine.LogLine = line; // Add the reference to the LogLine
            string[]      textData = line.FullLine.Split('|');
            List <Column> colData  = new List <Column>();

            if (textData.Length >= 6)
            {
                for (int i = 0; i < 5; i++)
                {
                    Column col = new Column
                    {
                        FullValue = textData[i],
                        Parent    = columnizedLogLine
                    };
                    colData.Add(col);
                }

                //The message is the last column
                Column msgCol = new Column
                {
                    FullValue = textData[textData.Length - 1],
                    Parent    = columnizedLogLine
                };
                colData.Add(msgCol);
            }
            else
            {
                //This is for log entries that extended to the next line(s)
                //Put all of it into the message
                for (int i = 0; i < columnCount - 1; i++)
                {
                    Column col = new Column
                    {
                        FullValue = string.Empty,
                        Parent    = columnizedLogLine
                    };
                    colData.Add(col);
                }

                Column msgCol = new Column
                {
                    FullValue = line.FullLine,
                    Parent    = columnizedLogLine
                };
                colData.Add(msgCol);
            }

            columnizedLogLine.ColumnValues = colData.ToArray();
            return(columnizedLogLine);
        }
Exemplo n.º 16
0
        private IColumnizedLogLine SplitJsonLine(ILogLine line, JObject json)
        {
            var cLogLine = new ColumnizedLogLine {
                LogLine = line
            };

            var columns = json.Properties().Select(property => new Column {
                FullValue = property.Value.ToString(), Parent = cLogLine
            }).ToList();

            cLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();

            return(cLogLine);
        }
Exemplo n.º 17
0
 private void testButton_Click(object sender, EventArgs e)
 {
     if (this.logTabWin.CurrentLogWindow != null)
     {
         ILogLine     line = this.logTabWin.CurrentLogWindow.GetCurrentLine();
         ILogFileInfo info = this.logTabWin.CurrentLogWindow.GetCurrentFileInfo();
         if (line != null && info != null)
         {
             ArgParser parser = new ArgParser(this.argsTextBox.Text);
             string    args   = parser.BuildArgs(line, this.logTabWin.CurrentLogWindow.GetRealLineNum() + 1, info,
                                                 this);
             this.testResultLabel.Text = args;
         }
     }
 }
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            ColumnizedLogLine columnizedLogLine = new ColumnizedLogLine();

            columnizedLogLine.LogLine = line; // Add the reference to the LogLine
            Column[] columns = Column.CreateColumns(GetColumnCount(), columnizedLogLine);
            columnizedLogLine.ColumnValues = columns.Select(a => a as IColumn).ToArray();
            String[] tmp = SplitLine(callback, line.FullLine);

            for (int i = 0; i < columns.Length; i++)
            {
                columns[i].FullValue = tmp[i];
            }
            return(columnizedLogLine);
        }
        public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine logLine)
        {
            string temp = logLine.FullLine;

            // delete '[#|' and '|#]'
            if (temp.StartsWith("[#|"))
            {
                temp = temp.Substring(3);
            }

            if (temp.EndsWith("|#]"))
            {
                temp = temp.Substring(0, temp.Length - 3);
            }

            if (temp.Length < 28)
            {
                return(DateTime.MinValue);
            }

            int endIndex = temp.IndexOf(separatorChar, 1);

            if (endIndex > 28 || endIndex < 0)
            {
                return(DateTime.MinValue);
            }

            string value = temp.Substring(0, endIndex);

            try
            {
                // convert glassfish timestamp into a readable format:
                DateTime timestamp;
                if (DateTime.TryParseExact(value, DATETIME_FORMAT, cultureInfo,
                                           System.Globalization.DateTimeStyles.None, out timestamp))
                {
                    return(timestamp.AddMilliseconds(this.timeOffset));
                }
                else
                {
                    return(DateTime.MinValue);
                }
            }
            catch (Exception)
            {
                return(DateTime.MinValue);
            }
        }
Exemplo n.º 20
0
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            ColumnizedLogLine cLogLine = new ColumnizedLogLine();

            cLogLine.LogLine      = line;
            cLogLine.ColumnValues = new IColumn[]
            {
                new Column
                {
                    FullValue = line.FullLine,
                    Parent    = cLogLine
                }
            };


            return(cLogLine);
        }
Exemplo n.º 21
0
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            if (isValidCsv)
            {
                return(SplitCsvLine(line));
            }
            else
            {
                ColumnizedLogLine cLogLine = new ColumnizedLogLine();
                cLogLine.LogLine      = line;
                cLogLine.ColumnValues = new IColumn[] { new Column {
                                                            FullValue = line.FullLine, Parent = cLogLine
                                                        } };

                return(cLogLine);
            }
        }
Exemplo n.º 22
0
        private int DoFilter(FilterParams filterParams, int startLine, int maxCount, List <int> filterResultLines,
                             List <int> lastFilterLinesList, List <int> filterHitList, ProgressCallback progressCallback)
        {
            int lineNum         = startLine;
            int count           = 0;
            int callbackCounter = 0;

            try
            {
                filterParams.Reset();
                while ((count++ < maxCount || filterParams.isInRange) && !this.ShouldCancel)
                {
                    if (lineNum >= this.callback.GetLineCount())
                    {
                        return(count);
                    }
                    ILogLine line = this.callback.GetLogLine(lineNum);
                    if (line == null)
                    {
                        return(count);
                    }
                    this.callback.LineNum = lineNum;
                    if (Util.TestFilterCondition(filterParams, line, callback))
                    {
                        AddFilterLine(lineNum, false, filterParams, filterResultLines, lastFilterLinesList,
                                      filterHitList);
                    }
                    lineNum++;
                    callbackCounter++;
                    if (lineNum % PROGRESS_BAR_MODULO == 0)
                    {
                        progressCallback(callbackCounter);
                        callbackCounter = 0;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.logError("Exception while filtering. Please report to developer: \n\n" + ex + "\n\n" +
                                ex.StackTrace);
                MessageBox.Show(null,
                                "Exception while filtering. Please report to developer: \n\n" + ex + "\n\n" + ex.StackTrace,
                                "LogExpert");
            }
            return(count);
        }
Exemplo n.º 23
0
        public string PreProcessLine(string logLine, int lineNum, int realLineNum)
        {
            if (realLineNum == 0)
            {
                // store for later field names and field count retrieval
                firstLine = new CsvLogLine
                {
                    FullLine   = logLine,
                    LineNumber = 0
                };
                if (config.minColumns > 0)
                {
                    using (CsvReader csv = new CsvReader(new StringReader(logLine),
                                                         false,
                                                         config.delimiterChar,
                                                         config.quoteChar,
                                                         config.escapeChar, // is '\0' when not checked in config dlg
                                                         config.commentChar,
                                                         ValueTrimmingOptions.None))
                    {
                        if (csv.FieldCount < config.minColumns)
                        {
                            // on invalid CSV don't hide the first line from LogExpert, since the file will be displayed in plain mode
                            isValidCsv = false;
                            return(logLine);
                        }
                    }
                }

                isValidCsv = true;
            }

            if (config.hasFieldNames && realLineNum == 0)
            {
                return(null); // hide from LogExpert
            }

            if (config.commentChar != ' ' && logLine.StartsWith("" + config.commentChar))
            {
                return(null);
            }

            return(logLine);
        }
Exemplo n.º 24
0
 internal IColumnizedLogLine GetColumnsForLine(LogfileReader logFileReader, int lineNumber, ILogLineColumnizer columnizer, ColumnizerCallback columnizerCallback)
 {
     if (_lastColumnizer != columnizer || _lastLineNumber != lineNumber && _cachedColumns != null || columnizerCallback.LineNum != lineNumber)
     {
         _lastColumnizer = columnizer;
         _lastLineNumber = lineNumber;
         ILogLine line = logFileReader.GetLogLineWithWait(lineNumber);
         if (line != null)
         {
             columnizerCallback.LineNum = lineNumber;
             _cachedColumns             = columnizer.SplitLine(columnizerCallback, line);
         }
         else
         {
             _cachedColumns = null;
         }
     }
     return(_cachedColumns);
 }
Exemplo n.º 25
0
        protected override IColumnizedLogLine SplitJsonLine(ILogLine line, JObject json)
        {
            List <IColumn> returnColumns = new List <IColumn>();
            var            cLogLine      = new ColumnizedLogLine {
                LogLine = line
            };

            var columns = json.Properties().Select(property => new ColumnWithName {
                FullValue = property.Value.ToString(), ColumneName = property.Name.ToString(), Parent = cLogLine
            }).ToList();

            //
            // Always rearrage the order of all json fields within a line to follow the sequence of columnNameList.
            // This will make sure the log line displayed correct even the order of json fields changed.
            //
            foreach (var column in _tagDict.Keys)
            {
                if (column.StartsWith("@"))
                {
                    var existingColumn = columns.Find(x => x.ColumneName == column);

                    if (existingColumn != null)
                    {
                        returnColumns.Add(new Column()
                        {
                            FullValue = existingColumn.FullValue, Parent = cLogLine
                        });
                        continue;
                    }

                    // Fields that is missing in current line should be shown as empty.
                    returnColumns.Add(new Column()
                    {
                        FullValue = "", Parent = cLogLine
                    });
                }
            }

            cLogLine.ColumnValues = returnColumns.ToArray();

            return(cLogLine);
        }
Exemplo n.º 26
0
        public IColumnizedLogLine SplitLine(ILogLineColumnizerCallback callback, ILogLine line)
        {
            JObject json = ParseJson(line);

            if (json != null)
            {
                return(SplitJsonLine(line, json));
            }

            var cLogLine = new ColumnizedLogLine {
                LogLine = line
            };

            var columns = Column.CreateColumns(_columnList.Count, cLogLine);

            columns.Last().FullValue = line.FullLine;

            cLogLine.ColumnValues = columns.Select(a => (IColumn)a).ToArray();

            return(cLogLine);
        }
Exemplo n.º 27
0
        public static bool TestFilterCondition(FilterParams filterParams, ILogLine line,
                                               LogExpert.ILogLineColumnizerCallback columnizerCallback)
        {
            if (filterParams.lastLine.Equals(line.FullLine))
            {
                return(filterParams.lastResult);
            }

            bool match = TestFilterMatch(filterParams, line, columnizerCallback);

            filterParams.lastLine = line.FullLine;

            if (filterParams.isRangeSearch)
            {
                if (!filterParams.isInRange)
                {
                    if (match)
                    {
                        filterParams.isInRange = true;
                    }
                }
                else
                {
                    if (!match)
                    {
                        match = true;
                    }
                    else
                    {
                        filterParams.isInRange = false;
                    }
                }
            }
            if (filterParams.isInvert)
            {
                match = !match;
            }
            filterParams.lastResult = match;
            return(match);
        }
Exemplo n.º 28
0
        public DateTime GetTimestamp(ILogLineColumnizerCallback callback, ILogLine line)
        {
            if (line.FullLine.Length < 15)
            {
                return(DateTime.MinValue);
            }

            int endIndex = line.FullLine.IndexOf(separatorChar, 1);

            if (endIndex > 20 || endIndex < 0)
            {
                return(DateTime.MinValue);
            }
            string value = line.FullLine.Substring(0, endIndex);

            try
            {
                // convert log4j timestamp into a readable format:
                long timestamp;
                if (long.TryParse(value, out timestamp))
                {
                    // Add the time offset before returning
                    DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    dateTime = dateTime.AddMilliseconds(timestamp);
                    if (this.config.localTimestamps)
                    {
                        dateTime = dateTime.ToLocalTime();
                    }
                    return(dateTime.AddMilliseconds(this.timeOffset));
                }
                else
                {
                    return(DateTime.MinValue);
                }
            }
            catch (Exception)
            {
                return(DateTime.MinValue);
            }
        }
Exemplo n.º 29
0
        public void Selected(ILogLineColumnizerCallback callback)
        {
            if (this.isValidCsv) // see PreProcessLine()
            {
                this.columnList.Clear();
                ILogLine line = this.config.hasFieldNames ? this.firstLine : callback.GetLogLine(0);


                if (line != null)
                {
                    using (CsvReader csv = new CsvReader(new StringReader(line.FullLine),
                                                         false,
                                                         this.config.delimiterChar,
                                                         this.config.quoteChar,
                                                         this.config.escapeChar, // is '\0' when not checked in config dlg
                                                         this.config.commentChar,
                                                         false))
                    {
                        csv.ReadNextRecord();
                        int fieldCount = csv.FieldCount;

                        List <Column> columns = new List <Column>();

                        for (int i = 0; i < fieldCount; ++i)
                        {
                            if (this.config.hasFieldNames)
                            {
                                this.columnList.Add(new CsvColumn(csv[i]));
                            }
                            else
                            {
                                this.columnList.Add(new CsvColumn("Column " + i + 1));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
        protected virtual IColumnizedLogLine SplitJsonLine(ILogLine line, JObject json)
        {
            var cLogLine = new ColumnizedLogLine {
                LogLine = line
            };

            var columns = GetFlatJsonChilds(json)
                          .Select(property => new ColumnWithName {
                FullValue = property.value, ColumneName = property.path, Parent = cLogLine
            })
                          .ToList();

            List <IColumn> returnColumns = new List <IColumn>();

            foreach (var column in ColumnList)
            {
                var existingColumn = columns.Find(x => x.ColumneName == column.Name);
                if (existingColumn != null)
                {
                    returnColumns.Add(new Column()
                    {
                        FullValue = existingColumn.FullValue, Parent = cLogLine
                    });
                    continue;
                }

                // Fields that is missing in current line should be shown as empty.
                returnColumns.Add(new Column()
                {
                    FullValue = "", Parent = cLogLine
                });
            }

            cLogLine.ColumnValues = returnColumns.ToArray();

            return(cLogLine);
        }