Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: IP Scanner detect common ports #2026

Merged
merged 11 commits into from
Mar 13, 2023
22 changes: 22 additions & 0 deletions Source/NETworkManager.Converters/HostUpStyleConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace NETworkManager.Converters;

public sealed class HostUpStyleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not bool isReachable)
return null;

return isReachable ? Application.Current.FindResource("HostUpRectangle") : Application.Current.FindResource("HostDownRectangle");
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class IPStatusToStringConverter : IValueConverter
/// <returns>Translated <see cref="IPStatus"/>.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is IPStatus ipStatus))
if (value is not IPStatus ipStatus)
return "-/-";

return IPStatusTranslator.GetInstance().Translate(ipStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class PingTimeToStringConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return Models.Network.Ping.TimeToString((IPStatus)values[0], (long)values[1]);
return Models.Network.Ping.TimeToString((IPStatus)values[0], (long)values[1]);
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
Expand Down
23 changes: 23 additions & 0 deletions Source/NETworkManager.Converters/PortOpenStyleConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NETworkManager.Models.Network;
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace NETworkManager.Converters;

public sealed class PortOpenStyleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not PortState portState)
return null;

return portState == PortState.Open ? Application.Current.FindResource("PortOpenRectangle") : Application.Current.FindResource("PortClosedRectangle");
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
42 changes: 42 additions & 0 deletions Source/NETworkManager.Converters/PortOpenToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Windows.Data;
using NETworkManager.Localization.Translators;
using NETworkManager.Models.Network;

namespace NETworkManager.Converters;

/// <summary>
/// Convert a <see cref="bool"/> that indicates if a port is open to a translated <see cref="string"/> or wise versa.
/// </summary>
public sealed class PortOpenToStringConverter : IValueConverter
{
/// <summary>
/// Convert a <see cref="bool"/> that indicates if a port is open to a translated <see cref="string"/>.
/// </summary>
/// <param name="value">Port up as <see cref="bool"/>.</param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns>Translated <see cref="PortState"/>.</returns>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not bool portState)
return "-/-";

return portState ? PortStateTranslator.GetInstance().Translate(PortState.Open) : PortStateTranslator.GetInstance().Translate(PortState.Closed);
}

/// <summary>
/// !!! Method not implemented !!!
/// </summary>
/// <param name="value"></param>
/// <param name="targetType"></param>
/// <param name="parameter"></param>
/// <param name="culture"></param>
/// <returns></returns>
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,4 @@
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
145 changes: 121 additions & 24 deletions Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading