Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1e54d33
Export: shared field list and CSV / XML / JSON writer (E1)
BornToBeRoot Nov 8, 2026
aafd786
Export: WiFi uses the shared writer (E2)
BornToBeRoot Nov 8, 2026
bf78b05
Export: IP Scanner uses the shared writer (E3)
BornToBeRoot Nov 8, 2026
7652271
Export: Port Scanner uses the shared writer (E4)
BornToBeRoot Nov 8, 2026
e584a89
Export: Ping Monitor and Traceroute use the shared writer (E5)
BornToBeRoot Nov 8, 2026
a68a306
Export: Network Interface uses the shared writer (E6)
BornToBeRoot Nov 8, 2026
d81c184
Export: DNS Lookup and SNTP Lookup use the shared writer (E7)
BornToBeRoot Nov 8, 2026
0bdfd7c
Export: Connections, Listeners and Neighbor Table use the shared writ…
BornToBeRoot Nov 8, 2026
d7b512c
Export: Discovery Protocol uses the shared writer (E9)
BornToBeRoot Nov 8, 2026
406651f
Export: IP Geolocation, Hosts File Editor and Firewall use the shared…
BornToBeRoot Nov 8, 2026
bbd45e4
Export: Subnet Calculator, Bit Calculator and SNMP use the shared wri…
BornToBeRoot Nov 8, 2026
28502dd
Ping: remove unused disableSpecialChar parameter of TimeToString
BornToBeRoot Nov 8, 2026
d75f2da
Docs: export format (E12)
BornToBeRoot Nov 8, 2026
14550d1
Export: columns in a logical order instead of append-only (R0)
BornToBeRoot Nov 8, 2026
d1ffb3d
Export: Network Interface columns in the order of the details (R1)
BornToBeRoot Nov 8, 2026
387a0c8
Export: WiFi columns in the order of the grid (R2)
BornToBeRoot Nov 8, 2026
b824bd0
Export: IP Scanner columns grouped by topic (R3)
BornToBeRoot Nov 8, 2026
fa86154
Export: Discovery Protocol columns in the order shown (R4)
BornToBeRoot Nov 8, 2026
a132c96
Export: Firewall columns in the order of the grid (R5)
BornToBeRoot Nov 8, 2026
3b08201
Export: same geolocation columns in IP Geolocation and Traceroute (R6)
BornToBeRoot Nov 8, 2026
e078891
Export: Ping Monitor columns like the IP Scanner ping (R7)
BornToBeRoot Nov 8, 2026
6f944c8
Changelog: breaking note for the exports
BornToBeRoot Nov 8, 2026
9b6b2f4
Changelog: link the export entries to #3696
BornToBeRoot Nov 8, 2026
9dda4fa
Grid order: shared CollectionViewExtensions (G1)
BornToBeRoot Nov 8, 2026
0186b1d
Export: Connections, Listeners and Neighbor Table in grid order (G2)
BornToBeRoot Nov 8, 2026
639246d
Export: Firewall and Hosts File Editor in grid order (G3)
BornToBeRoot Nov 8, 2026
840fc5b
Export: DNS Lookup, SNTP Lookup and SNMP in grid order (G4)
BornToBeRoot Nov 8, 2026
ca36b4d
Export: Lookup (OUI / Port) and Subnet Calculator in grid order (G5)
BornToBeRoot Nov 8, 2026
abdf5fe
Export: Traceroute in grid order (G6)
BornToBeRoot Nov 8, 2026
d6134d1
Docs: export of the results shown in the order shown (G7)
BornToBeRoot Nov 8, 2026
c038cd5
Normalize line endings of ExportManager.IPScannerHostInfo.cs
BornToBeRoot Nov 8, 2026
2002b9f
Fix: SNTP Lookup offset and round trip delay cut off (review #2)
BornToBeRoot Nov 8, 2026
2b8224d
Docs: export dates are local time, SNTP Lookup in UTC (review #1)
BornToBeRoot Nov 8, 2026
adb3029
Grid order: one call for Export... > All / Selected (review #5)
BornToBeRoot Nov 8, 2026
e0740a1
Ping Monitor: export in the background (review #6)
BornToBeRoot Nov 8, 2026
9bc4074
Fix: SNTP Lookup local time in the DST hour, socket of failed request…
BornToBeRoot Nov 8, 2026
94aa1a9
SNTP Lookup: offset with the NTP sign (final review #3)
BornToBeRoot Nov 8, 2026
8fdd766
Export: WiFi beacon interval / uptime as numbers (final review #6)
BornToBeRoot Nov 8, 2026
e47628e
Export: remove characters XML does not allow (final review #7)
BornToBeRoot Nov 8, 2026
8821636
Docs: export format explains empty vs. empty text in the IP Scanner (…
BornToBeRoot Nov 8, 2026
3f8bbd0
Export: CSV ports parseable, empty values unquoted, streamed (review …
BornToBeRoot Nov 8, 2026
46d4f0d
SNTP Lookup: no "-0" offset (review 3 #3)
BornToBeRoot Nov 8, 2026
069e022
Grid order: selected items by reference (review 3 #4)
BornToBeRoot Nov 8, 2026
b5b5474
Remove unused usings (review 3 #8)
BornToBeRoot Nov 8, 2026
b1a5a43
Merge branch 'main' into feature/export-fields
BornToBeRoot Nov 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NETworkManager.Converters;

public sealed class IntToSecondsStringConverter : IValueConverter
public sealed class DoubleToSecondsStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Expand Down
122 changes: 22 additions & 100 deletions Source/NETworkManager.Models/Export/ExportManager.BitCaluclatorInfo.cs
Original file line number Diff line number Diff line change
@@ -1,115 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.Generic;
using NETworkManager.Models.Network;
using Newtonsoft.Json;

namespace NETworkManager.Models.Export;

public static partial class ExportManager
{
/// <summary>
/// Method to export objects from type <see cref="BitCaluclatorInfo" /> to a file.
/// Exported fields of a <see cref="BitCaluclatorInfo" />.
/// </summary>
/// <param name="filePath">Path to the export file.</param>
/// <param name="fileType">Allowed <see cref="ExportFileType" /> are CSV, XML or JSON.</param>
/// <param name="collection">Objects as <see cref="IReadOnlyList{BitCaluclatorInfo}" /> to export.</param>
public static void Export(string filePath, ExportFileType fileType, IReadOnlyList<BitCaluclatorInfo> collection)
{
switch (fileType)
{
case ExportFileType.Csv:
CreateCsv(collection, filePath);
break;
case ExportFileType.Xml:
CreateXml(collection, filePath);
break;
case ExportFileType.Json:
CreateJson(collection, filePath);
break;
case ExportFileType.Txt:
default:
throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
}
}

/// <summary>
/// Creates a CSV file from the given <see cref="BitCaluclatorInfo" /> collection.
/// </summary>
/// <param name="collection">Objects as <see cref="IReadOnlyList{BitCaluclatorInfo}" /> to export.</param>
/// <param name="filePath">Path to the export file.</param>
private static void CreateCsv(IEnumerable<BitCaluclatorInfo> collection, string filePath)
{
var stringBuilder = new StringBuilder();

stringBuilder.AppendLine(
$"{nameof(BitCaluclatorInfo.Bits)},{nameof(BitCaluclatorInfo.Bytes)},{nameof(BitCaluclatorInfo.Kilobits)},{nameof(BitCaluclatorInfo.Kilobytes)},{nameof(BitCaluclatorInfo.Megabits)},{nameof(BitCaluclatorInfo.Megabytes)},{nameof(BitCaluclatorInfo.Gigabits)},{nameof(BitCaluclatorInfo.Gigabytes)},{nameof(BitCaluclatorInfo.Terabits)},{nameof(BitCaluclatorInfo.Terabytes)},{nameof(BitCaluclatorInfo.Petabits)},{nameof(BitCaluclatorInfo.Petabytes)}");

foreach (var info in collection)
stringBuilder.AppendLine(
$"{info.Bits},{info.Bytes},{info.Kilobits},{info.Kilobytes},{info.Megabits},{info.Megabytes},{info.Gigabits},{info.Gigabytes},{info.Terabits},{info.Terabytes},{info.Petabits},{info.Petabytes}");

File.WriteAllText(filePath, stringBuilder.ToString());
}
private static readonly ExportField<BitCaluclatorInfo>[] BitCaluclatorInfoExportFields =
[
new(nameof(BitCaluclatorInfo.Bits), x => x.Bits),
new(nameof(BitCaluclatorInfo.Bytes), x => x.Bytes),
new(nameof(BitCaluclatorInfo.Kilobits), x => x.Kilobits),
new(nameof(BitCaluclatorInfo.Kilobytes), x => x.Kilobytes),
new(nameof(BitCaluclatorInfo.Megabits), x => x.Megabits),
new(nameof(BitCaluclatorInfo.Megabytes), x => x.Megabytes),
new(nameof(BitCaluclatorInfo.Gigabits), x => x.Gigabits),
new(nameof(BitCaluclatorInfo.Gigabytes), x => x.Gigabytes),
new(nameof(BitCaluclatorInfo.Terabits), x => x.Terabits),
new(nameof(BitCaluclatorInfo.Terabytes), x => x.Terabytes),
new(nameof(BitCaluclatorInfo.Petabits), x => x.Petabits),
new(nameof(BitCaluclatorInfo.Petabytes), x => x.Petabytes)
];

/// <summary>
/// Creates a XML file from the given <see cref="BitCaluclatorInfo" /> collection.
/// Method to export objects from type <see cref="BitCaluclatorInfo" /> to a file.
/// </summary>
/// <param name="collection">Objects as <see cref="IReadOnlyList{BitCaluclatorInfo}" /> to export.</param>
/// <param name="filePath">Path to the export file.</param>
private static void CreateXml(IEnumerable<BitCaluclatorInfo> collection, string filePath)
{
var document = new XDocument(DefaultXDeclaration,
new XElement(ApplicationName.BitCalculator.ToString(),
new XElement(nameof(BitCaluclatorInfo) + "s",
from info in collection
select
new XElement(nameof(BitCaluclatorInfo),
new XElement(nameof(BitCaluclatorInfo.Bits), info.Bits),
new XElement(nameof(BitCaluclatorInfo.Bytes), info.Bytes),
new XElement(nameof(BitCaluclatorInfo.Kilobits), info.Kilobits),
new XElement(nameof(BitCaluclatorInfo.Kilobytes), info.Kilobytes),
new XElement(nameof(BitCaluclatorInfo.Megabits), info.Megabits),
new XElement(nameof(BitCaluclatorInfo.Megabytes), info.Megabytes),
new XElement(nameof(BitCaluclatorInfo.Gigabits), info.Gigabits),
new XElement(nameof(BitCaluclatorInfo.Gigabytes), info.Gigabytes),
new XElement(nameof(BitCaluclatorInfo.Terabits), info.Terabits),
new XElement(nameof(BitCaluclatorInfo.Terabytes), info.Terabytes),
new XElement(nameof(BitCaluclatorInfo.Petabits), info.Petabits),
new XElement(nameof(BitCaluclatorInfo.Petabytes), info.Petabytes)))));

document.Save(filePath);
}

/// <summary>
/// Creates a JSON file from the given <see cref="BitCaluclatorInfo" /> collection.
/// </summary>
/// <param name="fileType">Allowed <see cref="ExportFileType" /> are CSV, XML or JSON.</param>
/// <param name="collection">Objects as <see cref="IReadOnlyList{BitCaluclatorInfo}" /> to export.</param>
/// <param name="filePath">Path to the export file.</param>
private static void CreateJson(IReadOnlyList<BitCaluclatorInfo> collection, string filePath)
public static void Export(string filePath, ExportFileType fileType, IReadOnlyList<BitCaluclatorInfo> collection)
{
var jsonData = new object[collection.Count];

for (var i = 0; i < collection.Count; i++)
jsonData[i] = new
{
collection[i].Bits,
collection[i].Bytes,
collection[i].Kilobits,
collection[i].Kilobytes,
collection[i].Megabits,
collection[i].Megabytes,
collection[i].Gigabits,
collection[i].Gigabytes,
collection[i].Terabits,
collection[i].Terabytes,
collection[i].Petabits,
collection[i].Petabytes
};

File.WriteAllText(filePath, JsonConvert.SerializeObject(jsonData, Formatting.Indented));
Export(filePath, fileType, collection, BitCaluclatorInfoExportFields, ApplicationName.BitCalculator);
}
}
}
119 changes: 20 additions & 99 deletions Source/NETworkManager.Models/Export/ExportManager.ConnectionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.Generic;
using NETworkManager.Models.Network;
using NETworkManager.Utilities;
using Newtonsoft.Json;

namespace NETworkManager.Models.Export;

public static partial class ExportManager
{
/// <summary>
/// Method to export objects from type <see cref="ConnectionInfo" /> to a file.
/// Exported fields of a <see cref="ConnectionInfo" />.
/// </summary>
/// <param name="filePath">Path to the export file.</param>
/// <param name="fileType">Allowed <see cref="ExportFileType" /> are CSV, XML or JSON.</param>
/// <param name="collection">Objects as <see cref="IReadOnlyList{ConnectionInfo}" /> to export.</param>
public static void Export(string filePath, ExportFileType fileType, IReadOnlyList<ConnectionInfo> collection)
{
switch (fileType)
{
case ExportFileType.Csv:
CreateCsv(collection, filePath);
break;
case ExportFileType.Xml:
CreateXml(collection, filePath);
break;
case ExportFileType.Json:
CreateJson(collection, filePath);
break;
case ExportFileType.Txt:
default:
throw new ArgumentOutOfRangeException(nameof(fileType), fileType, null);
}
}

/// <summary>
/// Creates a CSV file from the given <see cref="ConnectionInfo" /> collection.
/// </summary>
/// <param name="collection">Objects as <see cref="IReadOnlyList{ConnectionInfo}" /> to export.</param>
/// <param name="filePath">Path to the export file.</param>
private static void CreateCsv(IEnumerable<ConnectionInfo> collection, string filePath)
{
var stringBuilder = new StringBuilder();

stringBuilder.AppendLine(
$"{nameof(ConnectionInfo.Protocol)},{nameof(ConnectionInfo.LocalIPAddress)},{nameof(ConnectionInfo.LocalPort)},{nameof(ConnectionInfo.RemoteIPAddress)},{nameof(ConnectionInfo.RemotePort)},{nameof(ConnectionInfo.RemoteHostname)},{nameof(ConnectionInfo.TcpState)},{nameof(ConnectionInfo.ProcessId)},{nameof(ConnectionInfo.ProcessName)},{nameof(ConnectionInfo.ProcessPath)}"
);

foreach (var info in collection)
stringBuilder.AppendLine(
$"{info.Protocol},{info.LocalIPAddress},{info.LocalPort},{info.RemoteIPAddress},{info.RemotePort},{CsvHelper.QuoteString(info.RemoteHostname)},{info.TcpState},{info.ProcessId},{CsvHelper.QuoteString(info.ProcessName)},{CsvHelper.QuoteString(info.ProcessPath)}");

File.WriteAllText(filePath, stringBuilder.ToString());
}
private static readonly ExportField<ConnectionInfo>[] ConnectionInfoExportFields =
[
new(nameof(ConnectionInfo.Protocol), x => x.Protocol),
new(nameof(ConnectionInfo.LocalIPAddress), x => x.LocalIPAddress),
new(nameof(ConnectionInfo.LocalPort), x => x.LocalPort),
new(nameof(ConnectionInfo.RemoteIPAddress), x => x.RemoteIPAddress),
new(nameof(ConnectionInfo.RemotePort), x => x.RemotePort),
new(nameof(ConnectionInfo.RemoteHostname), x => x.RemoteHostname, true),
new(nameof(ConnectionInfo.TcpState), x => x.TcpState),
new(nameof(ConnectionInfo.ProcessId), x => x.ProcessId),
new(nameof(ConnectionInfo.ProcessName), x => x.ProcessName, true),
new(nameof(ConnectionInfo.ProcessPath), x => x.ProcessPath, true)
];

/// <summary>
/// Creates a XML file from the given <see cref="ConnectionInfo" /> collection.
/// Method to export objects from type <see cref="ConnectionInfo" /> to a file.
/// </summary>
/// <param name="collection">Objects as <see cref="IReadOnlyList{ConnectionInfo}" /> to export.</param>
/// <param name="filePath">Path to the export file.</param>
private static void CreateXml(IEnumerable<ConnectionInfo> collection, string filePath)
{
var document = new XDocument(DefaultXDeclaration,
new XElement(ApplicationName.Connections.ToString(),
new XElement(nameof(ConnectionInfo) + "s",
from info in collection
select
new XElement(nameof(ConnectionInfo),
new XElement(nameof(ConnectionInfo.Protocol), info.Protocol),
new XElement(nameof(ConnectionInfo.LocalIPAddress), info.LocalIPAddress),
new XElement(nameof(ConnectionInfo.LocalPort), info.LocalPort),
new XElement(nameof(ConnectionInfo.RemoteIPAddress), info.RemoteIPAddress),
new XElement(nameof(ConnectionInfo.RemotePort), info.RemotePort),
new XElement(nameof(ConnectionInfo.RemoteHostname), info.RemoteHostname),
new XElement(nameof(ConnectionInfo.TcpState), info.TcpState),
new XElement(nameof(ConnectionInfo.ProcessId), info.ProcessId),
new XElement(nameof(ConnectionInfo.ProcessName), info.ProcessName),
new XElement(nameof(ConnectionInfo.ProcessPath), info.ProcessPath)
))));

document.Save(filePath);
}

/// <summary>
/// Creates a JSON file from the given <see cref="ConnectionInfo" /> collection.
/// </summary>
/// <param name="fileType">Allowed <see cref="ExportFileType" /> are CSV, XML or JSON.</param>
/// <param name="collection">Objects as <see cref="IReadOnlyList{ConnectionInfo}" /> to export.</param>
/// <param name="filePath">Path to the export file.</param>
private static void CreateJson(IReadOnlyList<ConnectionInfo> collection, string filePath)
public static void Export(string filePath, ExportFileType fileType, IReadOnlyList<ConnectionInfo> collection)
{
var jsonData = new object[collection.Count];

for (var i = 0; i < collection.Count; i++)
jsonData[i] = new
{
Protocol = collection[i].Protocol.ToString(),
LocalIPAddress = collection[i].LocalIPAddress.ToString(),
collection[i].LocalPort,
RemoteIPAddress = collection[i].RemoteIPAddress.ToString(),
collection[i].RemotePort,
collection[i].RemoteHostname,
TcpState = collection[i].TcpState.ToString(),
collection[i].ProcessId,
collection[i].ProcessName,
collection[i].ProcessPath
};

File.WriteAllText(filePath, JsonConvert.SerializeObject(jsonData, Formatting.Indented));
Export(filePath, fileType, collection, ConnectionInfoExportFields, ApplicationName.Connections);
}
}
}
Loading
Loading