void FillCache(int itemIndex, int windowSize) { UIErrorHelper.CheckedExec(delegate { var list = SuperLog.getPagedEntries(_cookie, (uint)windowSize); if (list != null) { int i = 0; foreach (var dto in list.getEntries()) { _viewCache[itemIndex + i++] = dto; } } var entries = new List <SuperLogDto>(); for (int startIndex = _viewCache.Keys.Count - 1, i = 0; startIndex >= 0; startIndex--, i++) { if (i > pageSize) { _viewCache.Remove(startIndex); } else { ISuperLogEntry item; if (_viewCache.TryGetValue(startIndex, out item)) { var endTime = item.getEndTime(); var startTime = item.getStartTime(); var errorCode = (int)item.getErrorCode(); var errordesc = GetErrorDescription(errorCode); var dto = new SuperLogDto { Port = item.getServerPort().ToString(), LoginDN = item.getLoginDN(), Operation = item.getOperation(), ErrorCode = errordesc, Duration = (endTime - startTime).ToString(), DurationLong = (long)(endTime - startTime), ClientIP = item.getClientIP(), String = item.getString() }; entries.Add(dto); } } } this.SuperLogsTableView.DataSource = new SuperLoggingTableViewDataSource(entries); this.SuperLogsTableView.ReloadData(); }); }
private void btnFilter_Click(object sender, EventArgs e) { UIErrorHelper.CheckedExec(delegate { var row = (int)CboColumns.SelectedIndex; var op = (int)CbOperator.SelectedIndex; if (row > 0 && !string.IsNullOrEmpty(TxtFilterValue.StringValue) && op >= 0) { var entries = new List <SuperLogDto> (); for (int startIndex = _viewCache.Keys.Count; startIndex >= 0; startIndex--) { ISuperLogEntry item; if (_viewCache.TryGetValue(startIndex, out item)) { var endTime = item.getEndTime(); var startTime = item.getStartTime(); var errorCode = (int)item.getErrorCode(); var errordesc = GetErrorDescription(errorCode); var dto = new SuperLogDto { Port = item.getServerPort().ToString(), LoginDN = item.getLoginDN(), Operation = item.getOperation(), ErrorCode = errordesc, Duration = (endTime - startTime).ToString(), DurationLong = (long)(endTime - startTime), ClientIP = item.getClientIP(), String = item.getString() }; entries.Add(dto); } } var filtered = new List <SuperLogDto> (); SuperLoggingColumn column; Operation oper; if (Enum.TryParse(row.ToString(), out column) && Enum.TryParse(op.ToString(), out oper)) { switch (column) { case SuperLoggingColumn.Port: switch (oper) { case Operation.StartsWith: case Operation.GreaterThan: filtered = entries.Where(x => x.Port.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.Port == TxtFilterValue.StringValue).ToList(); break; case Operation.EndsWith: case Operation.LessThan: filtered = entries.Where(x => x.Port.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.Port.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } break; case SuperLoggingColumn.LoginDN: switch (oper) { case Operation.StartsWith: case Operation.GreaterThan: filtered = entries.Where(x => x.LoginDN.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.LoginDN == TxtFilterValue.StringValue).ToList(); break; case Operation.EndsWith: case Operation.LessThan: filtered = entries.Where(x => x.LoginDN.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.LoginDN.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } break; case SuperLoggingColumn.Operation: switch (oper) { case Operation.StartsWith: case Operation.GreaterThan: filtered = entries.Where(x => x.Operation.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.Operation == TxtFilterValue.StringValue).ToList(); break; case Operation.EndsWith: case Operation.LessThan: filtered = entries.Where(x => x.Operation.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.Operation.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } break; case SuperLoggingColumn.ErrorCode: switch (oper) { case Operation.StartsWith: case Operation.GreaterThan: filtered = entries.Where(x => x.ErrorCode.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.ErrorCode == TxtFilterValue.StringValue).ToList(); break; case Operation.EndsWith: case Operation.LessThan: filtered = entries.Where(x => x.ErrorCode.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.ErrorCode.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } break; case SuperLoggingColumn.Duration: long value; if (long.TryParse(TxtFilterValue.StringValue, out value)) { switch (oper) { case Operation.StartsWith: filtered = entries.Where(x => x.Duration.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.GreaterThan: filtered = entries.Where(x => x.DurationLong > value).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.DurationLong == value).ToList(); break; case Operation.EndsWith: filtered = entries.Where(x => x.Duration.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.LessThan: filtered = entries.Where(x => x.DurationLong < value).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.Duration.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } } else { throw new Exception("The filer value is not a valid duration"); } break; case SuperLoggingColumn.ClientIP: switch (oper) { case Operation.StartsWith: case Operation.GreaterThan: filtered = entries.Where(x => x.ClientIP.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.ClientIP == TxtFilterValue.StringValue).ToList(); break; case Operation.EndsWith: case Operation.LessThan: filtered = entries.Where(x => x.ClientIP.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.ClientIP.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } break; case SuperLoggingColumn.String: switch (oper) { case Operation.StartsWith: case Operation.GreaterThan: filtered = entries.Where(x => x.String.StartsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Equals: filtered = entries.Where(x => x.String == TxtFilterValue.StringValue).ToList(); break; case Operation.EndsWith: case Operation.LessThan: filtered = entries.Where(x => x.String.EndsWith(TxtFilterValue.StringValue)).ToList(); break; case Operation.Contains: filtered = entries.Where(x => x.String.Contains(TxtFilterValue.StringValue)).ToList(); break; default: break; } break; } this.SuperLogsTableView.DataSource = new SuperLoggingTableViewDataSource(filtered); this.SuperLogsTableView.ReloadData(); } } }); }