Files
ReLibreHardwareMonitor/Hardware/Nic/NicGroup.cs
T
Michal 5d89cdc43d Cleanup around base collection types. (#59)
* Hardware in IGroup is now IEnumerable. No point to call ToArray each time.

* Use ValueTuple insead of custom pair.

* ListSet -> HashSet

* Ring Collection -> List

* ReadOnlyArray -> ReadOnlyList
2018-10-30 14:44:41 +01:00

76 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Text;
namespace OpenHardwareMonitor.Hardware.Nic
{
internal class NicGroup : IGroup
{
private List<Hardware> hardware = new List<Hardware>();
private NetworkInterface[] _networkInterfaces;
public NicGroup(ISettings settings)
{
int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128))
{
hardware = new List<Hardware>();
return;
}
_networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
for (int i = 0; i < _networkInterfaces.Length; i++)
{
if (_networkInterfaces[i].NetworkInterfaceType != NetworkInterfaceType.Unknown && _networkInterfaces[i].NetworkInterfaceType != NetworkInterfaceType.Loopback && _networkInterfaces[i].NetworkInterfaceType != NetworkInterfaceType.Tunnel)
{
hardware.Add(new Nic(_networkInterfaces[i].Name, settings, i, this));
}
}
}
public string GetReport()
{
if (NetworkInterfaces == null)
return null;
var report = new StringBuilder();
foreach (Nic hw in hardware)
{
report.AppendLine(hw.NetworkInterface.Description);
report.AppendLine(hw.NetworkInterface.OperationalStatus.ToString());
report.AppendLine();
foreach (var sensor in hw.Sensors)
{
report.AppendLine(sensor.Name);
report.AppendLine(sensor.Value.ToString() + sensor.SensorType);
report.AppendLine();
}
}
return report.ToString();
}
public IEnumerable<IHardware> Hardware => hardware;
public NetworkInterface[] NetworkInterfaces
{
get
{
return _networkInterfaces;
}
set
{
_networkInterfaces = value;
}
}
public void Close()
{
foreach (Hardware nic in hardware)
nic.Close();
}
}
}