private void WriteLogToDb(ParsedLogEntry parsedLog) { using (var repository = this.repositoryFactory.CreateLogRepository()) { var fileToCheck = repository.FindFirst <File>(x => x.Path == parsedLog.Path); if (fileToCheck == null) { WebPageInfo pageInfo; try { pageInfo = webHelper.GetPageInfo(parsedLog.Path); fileToCheck = new File() { Path = parsedLog.Path, Size = pageInfo.Size, Title = pageInfo.Title, }; } catch { fileToCheck = new File() { Path = parsedLog.Path, }; } repository.Create(fileToCheck); } var ipInBytes = IpConverter.FromString(parsedLog.IpAddress); var ipToCheck = repository.FindFirst <Ip>(x => x.Address.SequenceEqual(ipInBytes)); if (ipToCheck == null) { var organization = webHelper.GetOrganizationNameByWhois(parsedLog.IpAddress); ipToCheck = new Ip() { Address = ipInBytes, OwnerName = organization, }; repository.Create(ipToCheck); } var logEntry = new LogEntry() { IpInfo = ipToCheck, FileInfo = fileToCheck, Method = parsedLog.Method, Amount = int.Parse(parsedLog.Amount), StatusCode = short.Parse(parsedLog.Status), Date = DateTimeOffset.ParseExact( parsedLog.Date, LogSettings.DateTimeOffsetPattern, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None), }; repository.Create(logEntry); try { repository.Save(); } catch { WriteLogToDb(parsedLog); return; } Interlocked.Increment(ref entriesProcessedCount); Interlocked.Exchange(ref progressPercent, ((double)entriesProcessedCount / entriesCount * 100)); } }
public void CanCreate() { converter = new IpConverter(); converter.Should().NotBeNull(); }
private void initIpLookupStatisticsTable() { _ipLookupStatisticsTable = CreateTable <MultiLookup>(ref ipLookupStatisticsTable, ipLookupStatisticsTableContainer); CustomDataGridViewColumnDescriptorBuilder <MultiLookup> builder; // Column: prefix, IP format builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.TextBox); builder.Header("IP"); builder.Width(150); builder.UpdaterMethod((entry, cell) => { cell.Value = entry.IP; }); builder.AddChangeEvent(nameof(MultiLookup.IP)); builder.BuildAndAdd(); // Column: prefix, IP format builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.TextBox); builder.Header("IP (binary)"); builder.Width(300); builder.UpdaterMethod((entry, cell) => { cell.Value = IpConverter.IpToBinary(entry.IP, " "); }); builder.AddChangeEvent(nameof(MultiLookup.IP)); builder.BuildAndAdd(); // Column: next hop builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.TextBox); builder.Header("Next hop"); builder.Width(150); builder.UpdaterMethod((entry, cell) => { cell.Value = entry.NextHop ?? "-"; }); builder.AddChangeEvent(nameof(MultiLookup.NextHop)); builder.BuildAndAdd(); // Column: edges (original) builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.TextBox); builder.Header("Edges (original)"); builder.Width(120); builder.UpdaterMethod((entry, cell) => { cell.Value = entry.EdgesOriginal?.ToString() ?? "-"; }); builder.AddChangeEvent(nameof(MultiLookup.EdgesOriginal)); builder.BuildAndAdd(); // Column: edges (normalized) builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.TextBox); builder.Header("Edges (normalized)"); builder.Width(120); builder.UpdaterMethod((entry, cell) => { cell.Value = entry.EdgesNormalized?.ToString() ?? "-"; }); builder.AddChangeEvent(nameof(MultiLookup.EdgesNormalized)); builder.BuildAndAdd(); // Column: edges (original) builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.TextBox); builder.Header("Edges (compressed)"); builder.Width(120); builder.UpdaterMethod((entry, cell) => { cell.Value = entry.EdgesCompressed?.ToString() ?? "-"; }); builder.AddChangeEvent(nameof(MultiLookup.EdgesCompressed)); builder.BuildAndAdd(); // Column: visualize builder = new CustomDataGridViewColumnDescriptorBuilder <MultiLookup>(_ipLookupStatisticsTable); builder.Type(DataGridViewColumnType.Button); builder.Header("Visualize"); builder.Width(90); builder.ButtonText("Visualize"); builder.CellContentClickHandlerMethod((entry, cell, e) => { visualizeLookups(entry); }); builder.BuildAndAdd(); // Bind database _ipLookupStatisticsTable.BoundCollection = mMultiLookupCollection; }