private void ResizeLogColumns(FlatProject proj, ColumnDefinitionList colDefList) { int colPos = LG_COL_POS_CONTENT_START; if (proj.ShowFileName) { int fileColWidth = maxCellWidthDictionary[LG_COL_NAME_FILE]; logSheet.SetColumnWidth(colPos, fileColWidth); colPos++; } int lineColWidth = maxCellWidthDictionary[LG_COL_NAME_LINE]; logSheet.SetColumnWidth(colPos, lineColWidth); colPos++; foreach (ColumnDefinition colDef in colDefList) { if (!colDef.Visble) { continue; } int width = maxCellWidthDictionary[colDef.ColumnName]; logSheet.SetColumnWidth(colPos, width); colPos++; } }
public ViewColumnSettingDialog(FlatProject project) { InitializeComponent(); columnDefList = project.PatternDefinition.ColumnDefinitionList; ShowFileNameCheckBox.Checked = project.ShowFileName; ShowColumnList(); }
/// <summary> /// Constructor /// </summary> /// <param name="fileName">Database file name</param> /// <param name="patternDef">Analyzing pattern definition</param> public IntermediateLogReader(String fileName, PatternDefinition patternDef) { log.In(fileName, patternDef); this.colDefList = patternDef.ColumnDefinitionList; connection = SQLiteUtil.OpenConnection(fileName); log.Out(); }
public void LoadingNonExistentFileReturnsEmptyList() { // Arrange const string fileName = "non.existing.file"; var list = new ColumnDefinitionList(fileName); // Act var loaded = list.Load().ToArray(); // Assert Assert.AreEqual(0, loaded.Length); }
public HighlightSettingDialog(FlatProject project) { InitializeComponent(); if (project == null) { return; } columnDefList = project.PatternDefinition.ColumnDefinitionList; highlightDefList = HighlightDefinitionList.Copy(project.HighlightDefinitionList); }
/// <summary> /// Read log lines from database /// </summary> /// <param name="criteria">Search condition</param> /// <param name="colDefList">Column definition list</param> /// <param name="highlightDefList">Highlight definition list</param> /// <param name="offset">Read start position</param> /// <param name="limit">Read log lines limit</param> /// <returns>Parsed log lines</returns> public ParsedLog ReadLines(SearchCriteria criteria, ColumnDefinitionList colDefList, HighlightDefinitionList highlightDefList, int offset, int limit) { log.In(criteria, offset, limit); SQLiteCommand comm = connection.CreateCommand(); SetSelectStatement(comm, colDefList, criteria, offset, limit); ParsedLog parsedLog = new ParsedLog(); List <ParsedLogLine> lineList = new List <ParsedLogLine>(); using (SQLiteDataReader reader = comm.ExecuteReader()) { while (reader.Read()) { ParsedLogLine logLine = new ParsedLogLine(); logLine.File = new FileValue(); logLine.File.Name = GetStringValue(reader, IntermediateLogConstants.COL_NAME_LF_FILE_NAME); logLine.LineNumber = GetIntValue(reader, IntermediateLogConstants.COL_NAME_PL_LINE_NUM); logLine.HasError = GetBooleanValue(reader, IntermediateLogConstants.COL_NAME_PL_HAS_ERROR); logLine.NotParsedLog = GetStringValue(reader, IntermediateLogConstants.COL_NAME_PL_NOT_PARSED_LINE); foreach (ColumnDefinition colDef in colDefList) { ParsedLogColumn col = new ParsedLogColumn(); col.ColumnDefinition = colDef; col.Value = GetStringValue(reader, colDef.ColumnName); if (highlightDefList != null) { SetHighlights(col, highlightDefList); } logLine.ColumnList.Add(col); } lineList.Add(logLine); } } parsedLog.TotalLineCount = GetTotalLineCount(); parsedLog.TargetLineCount = GetLineCount(criteria); parsedLog.LogLineList = lineList; log.Out(lineList); return(parsedLog); }
public void SavedColumnDefinitionsCanBeLoaded() { // Arrange var mentionDef = new ColumnDefinition(ColumnType.Mentions) { Width = 123, TargetAccounts = new ulong[] { 1234u, 45678u }, SourceAccounts = new ulong[] { 456u } }; var timelineDef = new ColumnDefinition(ColumnType.Timeline) { Width = 223, TargetAccounts = new ulong[] { 111u, 222u }, SourceAccounts = new ulong[] { 2344u } }; var definitions = new[] { mentionDef, timelineDef }; var fileName = Path.GetTempFileName(); var list = new ColumnDefinitionList(fileName) { Serializer = new Serializer() }; // Act list.Save(definitions); var loaded = list.Load().ToArray(); // Assert var col = loaded.SingleOrDefault(c => c.Type == ColumnType.Mentions); Assert.IsNotNull(col); Assert.AreEqual(mentionDef.Width, col.Width); Assert.AreEqual(mentionDef.Type, col.Type); CollectionAssert.AreEqual(mentionDef.SourceAccounts, col.SourceAccounts); CollectionAssert.AreEqual(mentionDef.TargetAccounts, col.TargetAccounts); col = loaded.SingleOrDefault(c => c.Type == ColumnType.Timeline); Assert.IsNotNull(col); Assert.AreEqual(timelineDef.Width, col.Width); Assert.AreEqual(timelineDef.Type, col.Type); CollectionAssert.AreEqual(timelineDef.SourceAccounts, col.SourceAccounts); CollectionAssert.AreEqual(timelineDef.TargetAccounts, col.TargetAccounts); }
/// <summary> /// Create ParsedLog table /// </summary> /// <param name="com">Command</param> /// <param name="colDefList">Column definition list</param> private void CreateParsedLogTable(SQLiteCommand com, ColumnDefinitionList colDefList) { log.InPrivate(com, colDefList); com.CommandText = "create table " + IntermediateLogConstants.TABLE_NAME_PARSED_LOGS + "("; com.CommandText += IntermediateLogConstants.COL_NAME_PL_ID + " integer primary key autoincrement, "; com.CommandText += IntermediateLogConstants.COL_NAME_PL_LINE_NUM + " integer, "; com.CommandText += IntermediateLogConstants.COL_NAME_PL_FILE_ID + " integer, "; com.CommandText += IntermediateLogConstants.COL_NAME_PL_HAS_ERROR + " integer, "; com.CommandText += IntermediateLogConstants.COL_NAME_PL_NOT_PARSED_LINE + " text, "; foreach (ColumnDefinition colDef in colDefList) { com.CommandText += colDef.ColumnName; if (colDef.IsDateTimeField || colDef.Hashable) { com.CommandText += " integer, "; } else { com.CommandText += " text, "; } } // Remove last ", " com.CommandText = com.CommandText.Substring(0, com.CommandText.Length - 2); com.CommandText += ")"; com.ExecuteNonQuery(); foreach (ColumnDefinition colDef in colDefList) { if (colDef.IsDateTimeField) { com.CommandText = "create index " + IntermediateLogConstants.TABLE_NAME_PARSED_LOGS + "_" + colDef.ColumnName + IDX_SUFFIX + " on " + IntermediateLogConstants.TABLE_NAME_PARSED_LOGS + "(" + colDef + ")"; com.ExecuteNonQuery(); } } log.OutPrivate(); }
/// <summary> /// Constructor /// </summary> /// <param name="fileName">Database file name</param> /// <param name="patternDef">Analyzing pattern</param> public IntermediateLogWriter(string fileName, PatternDefinition patternDef) { log.In(fileName, patternDef); this.regex = new Regex(patternDef.RegularExpression); this.columnDefList = patternDef.ColumnDefinitionList; if (File.Exists(fileName) == false) { CreateDB(fileName, patternDef.ColumnDefinitionList); } connection = SQLiteUtil.OpenConnection(fileName); log.Out(); }
public FilteringColumnSettingDialog(FlatProject project) { InitializeComponent(); this.colDefList = project.PatternDefinition.ColumnDefinitionList; this.searchCriteria = SearchCriteria.Copy(project.ColumnsSearchCriteria); if (this.searchCriteria == null) { this.searchCriteria = new SearchCriteria(); } ShowColumnList(); if (ColumnListBox.Items.Count > 0) { ColumnListBox.SelectedIndex = 0; } }
public void SavingColumnsRaisesChangeEvent() { // Arrange var fileName = Path.GetTempFileName(); var serializer = new Mock <ISerializer>(); var list = new ColumnDefinitionList(fileName) { Serializer = serializer.Object }; bool raised = false; list.ColumnsChanged += (s, e) => raised = true; // Act list.Save(Enumerable.Empty <ColumnDefinition>()); // Assert Assert.IsTrue(raised); }
/// <summary> /// Create database file /// </summary> /// <param name="fileName">Database file name</param> /// <param name="colDefList">Column definition list</param> private void CreateDB(string fileName, ColumnDefinitionList colDefList) { log.InPrivate(); SQLiteConnection.CreateFile(fileName); using (SQLiteConnection initCon = SQLiteUtil.OpenConnection(fileName)) { using (SQLiteCommand com = initCon.CreateCommand()) { CreateHashedValueTable(com); CreateLogFileTable(com); CreateParsedLogTable(com, colDefList); } } log.OutPrivate(); }
public void AddingColumnsPreservesExistingOnes() { // Arrange var fileName = Path.GetTempFileName(); var list = new ColumnDefinitionList(fileName) { Serializer = new Serializer() }; var mentionDef = new ColumnDefinition(ColumnType.Mentions) { Width = 123, TargetAccounts = new ulong[] { 1234u, 45678u }, SourceAccounts = new ulong[] { 456u } }; var timelineDef = new ColumnDefinition(ColumnType.Timeline) { Width = 223, TargetAccounts = new ulong[] { 111u, 222u }, SourceAccounts = new ulong[] { 2344u } }; var definitions = new[] { timelineDef }; list.Save(definitions); // Act list.AddColumns(new[] { mentionDef }); var loaded = list.Load().ToArray(); // Assert Assert.AreEqual(2, loaded.Length); Assert.IsNotNull(loaded.SingleOrDefault(c => c.Type == ColumnType.Mentions)); Assert.IsNotNull(loaded.SingleOrDefault(c => c.Type == ColumnType.Timeline)); }
public void DefinitionCanBeRemoved() { // Arrange var fileName = Path.GetTempFileName(); var list = new ColumnDefinitionList(fileName) { Serializer = new Serializer() }; list.AddColumns(new[] { new ColumnDefinition(ColumnType.User) }); // Act var saved = list.Load().ToArray(); var countBefore = saved.Length; list.Remove(saved); var countAfter = list.Load().Count(); // Assert Assert.AreNotEqual(0, countBefore); Assert.AreEqual(0, countAfter); }
/// <summary> /// Set select statement to command /// </summary> /// <param name="comm">Command</param> /// <param name="colDefList">Column definition list</param> /// <param name="criteria">Search condition</param> /// <param name="offset">Result count offset</param> /// <param name="limit">Result count limit</param> private void SetSelectStatement(SQLiteCommand comm, ColumnDefinitionList colDefList, SearchCriteria criteria, int offset, int limit) { log.InPrivate(comm); StringBuilder selectSb = new StringBuilder(); selectSb.Append("select "); selectSb.Append(CreatePLColumnName(IntermediateLogConstants.COL_NAME_PL_LINE_NUM)); selectSb.Append(","); selectSb.Append(CreatePLColumnName(IntermediateLogConstants.COL_NAME_PL_HAS_ERROR)); selectSb.Append(","); selectSb.Append(CreatePLColumnName(IntermediateLogConstants.COL_NAME_PL_NOT_PARSED_LINE)); selectSb.Append(","); selectSb.Append(CreateLFColumnName(IntermediateLogConstants.COL_NAME_LF_FILE_NAME)); selectSb.Append(","); foreach (ColumnDefinition colDef in colDefList) { if (colDef.Hashable) { selectSb.Append(CreateHVColumnNameWithAlias(colDef.ColumnName)); selectSb.Append(","); } else { selectSb.Append(CreatePLColumnName(colDef.ColumnName)); selectSb.Append(","); } } //Remove last comma selectSb.Remove(selectSb.Length - 1, 1); selectSb.Append(" from "); selectSb.Append(IntermediateLogConstants.TABLE_NAME_PARSED_LOGS); selectSb.Append(","); selectSb.Append(IntermediateLogConstants.TABLE_NAME_LOG_FILES); foreach (ColumnDefinition colDef in colDefList) { if (colDef.Hashable) { selectSb.Append(" left join "); selectSb.Append(CreateHVTableName(colDef.ColumnName)); selectSb.Append(" on "); selectSb.Append(CreatePLColumnName(colDef.ColumnName)); selectSb.Append("="); selectSb.Append(CreateHVColumnName(colDef.ColumnName)); } } StringBuilder whereSb = new StringBuilder(); whereSb.Append(" where ("); whereSb.Append(CreatePLColumnName(IntermediateLogConstants.COL_NAME_PL_FILE_ID)); whereSb.Append("="); whereSb.Append(CreateLFColumnName(IntermediateLogConstants.COL_NAME_LF_ID)); whereSb.Append(" and "); //Remove last AND whereSb.Remove(whereSb.Length - " and ".Length, " and ".Length); whereSb.Append(") "); comm.CommandText = selectSb.ToString() + whereSb.ToString(); AddWhereClause(comm, criteria, false); comm.CommandText += " order by "; foreach (ColumnDefinition colDef in colDefList) { if (colDef.IsDateTimeField) { comm.CommandText += colDef.ColumnName + " asc,"; } } comm.CommandText += IntermediateLogConstants.COL_NAME_PL_LINE_NUM + " asc"; comm.CommandText += " limit " + limit + " offset " + offset; log.Info(comm.CommandText); log.OutPrivate(); }
/// <summary> /// Parse log line /// </summary> /// <param name="file">Log file name</param> /// <param name="line">Target log line</param> /// <param name="regex">Analyzing regex</param> /// <param name="colDefList">Column definition list</param> /// <returns>Parsed log line</returns> private ParsedLogLine ParseLine(FileValue file, string line, Regex regex, ColumnDefinitionList colDefList) { log.InPrivate(line, regex, colDefList); ParsedLogLine logLine = new ParsedLogLine(); logLine.File = file; logLine.ColumnList = new List <ParsedLogColumn>(); string[] lineElems = regex.Split(line); lineElems = RemoveFirstAndLastEmptyElems(lineElems); if (lineElems.Length != colDefList.Count) { log.Warn("Log element size is different.Skip this line. Expected=" + colDefList.Count.ToString() + " Actual=" + lineElems.Length); logLine.HasError = true; logLine.NotParsedLog = line; log.OutPrivate(logLine); return(logLine); } int index = 0; foreach (string lineElem in lineElems) { ColumnDefinition colDef = colDefList[index]; ParsedLogColumn col = new ParsedLogColumn(); col.ColumnDefinition = colDef; if (colDef.IsDateTimeField) { if (SetDataTimeValue(lineElem, col, colDef) == false) { logLine.HasError = true; log.Warn("Could not parse DateTime value. Value=" + lineElem); } } else if (colDef.Hashable) { SetHashedValue(lineElem, col); } else { col.Value = lineElem; } logLine.ColumnList.Add(col); index++; } if (logLine.HasError || line.Trim() == "") { logLine.ColumnList.Clear(); logLine.HasError = true; logLine.NotParsedLog = line; } log.OutPrivate(logLine); return(logLine); }