Skip to content

Commit

Permalink
Chore: Refactoring & Cleanup & Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BornToBeRoot committed Sep 11, 2023
1 parent 0580c22 commit d13cf29
Show file tree
Hide file tree
Showing 37 changed files with 652 additions and 484 deletions.
187 changes: 93 additions & 94 deletions Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
<data name="ExampleSNMPCommunity" xml:space="preserve">
<value>public</value>
</data>
<data name="ExampleSNMPOID" xml:space="preserve">
<data name="ExampleSnmpOid" xml:space="preserve">
<value>1.3.6.1.2.1.1</value>
</data>
<data name="ExampleSNMPUsername" xml:space="preserve">
Expand Down Expand Up @@ -339,7 +339,7 @@
<data name="ExampleSNMPMIB" xml:space="preserve">
<value>system</value>
</data>
<data name="ExampleSNMPOIDS" xml:space="preserve">
<data name="ExampleSnmpOids" xml:space="preserve">
<value>1.3.6.1.2.1.1; 1.3.6.1.2.1.2</value>
</data>
<data name="ExamplePassword" xml:space="preserve">
Expand Down
4 changes: 2 additions & 2 deletions Source/NETworkManager.Utilities/RegexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public static class RegexHelper
// Match a number (like 12, 12.4, 12,3)
public const string NumberRegex = @"^\d+((\.|,)\d+)?$";

// Match an SNMP OID (like 1.3.6.1)
public const string SNMOIODRegex = @"^[012]\.(?:[0-9]|[1-3][0-9])(\.\d+)*$";
// Match an SNMP OID (like 1.3.6.1 or .1.3.6.2)
public const string SnmpOidRegex = @"^\.?[012]\.(?:[0-9]|[1-3][0-9])(\.\d+)*$";
}
25 changes: 11 additions & 14 deletions Source/NETworkManager.Validators/SNMPOIDValidator.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
using NETworkManager.Utilities;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Controls;

namespace NETworkManager.Validators;

public class SNMPOIDValidator : ValidationRule
public class SnmpOidValidator : ValidationRule
{
public SNMPOIDDependencyObjectWrapper Wrapper { get; set; }

public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
var oidValue = (value as string).Replace(" ", "");
var oidValue = (value as string)!.Replace(" ", "");

if (Wrapper.Mode == Models.Network.SNMPMode.Get && oidValue.Contains(';'))
{
foreach (var oid in oidValue.Split(';'))
{
if (!Regex.IsMatch(oid, RegexHelper.SNMOIODRegex))
return new ValidationResult(false, Localization.Resources.Strings.EnterValidOID);
}

return ValidationResult.ValidResult;
}

return Regex.IsMatch(oidValue, RegexHelper.SNMOIODRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidOID);
if (Wrapper.Mode != Models.Network.SNMPMode.Get || !oidValue.Contains(';'))
return Regex.IsMatch(oidValue, RegexHelper.SnmpOidRegex)
? ValidationResult.ValidResult
: new ValidationResult(false, Localization.Resources.Strings.EnterValidOID);

return oidValue.Split(';').Any(oid => !Regex.IsMatch(oid, RegexHelper.SnmpOidRegex)) ?
new ValidationResult(false, Localization.Resources.Strings.EnterValidOID) :
ValidationResult.ValidResult;
}
}
1 change: 1 addition & 0 deletions Source/NETworkManager.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rlogin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rsna/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=slovenski/@EntryIndexedValue">True</s:Boolean>

<s:Boolean x:Key="/Default/UserDictionary/Words/=sntp/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subnetmask/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subnetting/@EntryIndexedValue">True</s:Boolean>
Expand Down
3 changes: 2 additions & 1 deletion Source/NETworkManager/Resources/ContextMenu/ContextMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization">
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
>
<ContextMenu x:Key="CutCopyPasteContextMenu" MinWidth="150">
<MenuItem Header="{x:Static localization:Strings.Cut}" Command="Cut">
<MenuItem.Icon>
Expand Down
47 changes: 20 additions & 27 deletions Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NETworkManager.Settings;
using MahApps.Metro.Controls.Dialogs;
using System;
using NETworkManager.Models.Network;
using System.ComponentModel;
Expand All @@ -18,10 +17,8 @@ public class BitCalculatorViewModel : ViewModelBase
{
#region Variables
private static readonly ILog Log = LogManager.GetLogger(typeof(BitCalculatorViewModel));
private readonly IDialogCoordinator _dialogCoordinator;

private readonly bool _isLoading = true;
private bool _isViewActive = true;

private readonly bool _isLoading;

private string _input;
public string Input
Expand All @@ -39,11 +36,11 @@ public string Input

public ICollectionView InputHistoryView { get; }

private List<BitCaluclatorUnit> _units = new();
private readonly List<BitCaluclatorUnit> _units = new();
public List<BitCaluclatorUnit> Units
{
get => _units;
set
private init
{
if (value == _units)
return;
Expand All @@ -70,16 +67,16 @@ public BitCaluclatorUnit Unit
}
}

private bool _isCalculationRunning;
public bool IsCalculationRunning
private bool _isRunning;
public bool IsRunning
{
get => _isCalculationRunning;
get => _isRunning;
set
{
if (value == _isCalculationRunning)
if (value == _isRunning)
return;

_isCalculationRunning = value;
_isRunning = value;
OnPropertyChanged();
}
}
Expand All @@ -103,7 +100,7 @@ public bool IsResultVisible
public BitCaluclatorInfo Result
{
get => _result;
set
private set
{
if (value == _result)
return;
Expand All @@ -115,9 +112,9 @@ public BitCaluclatorInfo Result
#endregion

#region Constructor, load settings
public BitCalculatorViewModel(IDialogCoordinator instance)
public BitCalculatorViewModel()
{
_dialogCoordinator = instance;
_isLoading = true;

InputHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.BitCalculator_InputHistory);

Expand All @@ -137,11 +134,11 @@ private void LoadSettings()
#endregion

#region ICommands & Actions
public ICommand CalculateCommand => new RelayCommand(p => CalcualateAction(), Calculate_CanExecute);
public ICommand CalculateCommand => new RelayCommand(_ => CalculateAction(), Calculate_CanExecute);

private bool Calculate_CanExecute(object paramter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
private bool Calculate_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;

private void CalcualateAction()
private void CalculateAction()
{
Calculate();
}
Expand All @@ -151,9 +148,9 @@ private void CalcualateAction()
private async void Calculate()
{
IsResultVisible = false;
IsCalculationRunning = true;
IsRunning = true;

if (double.TryParse(Input.Replace('.', ','), out double input))
if (double.TryParse(Input.Replace('.', ','), out var input))
{
Result = await BitCaluclator.CalculateAsync(input, Unit, SettingsManager.Current.BitCalculator_Notation);
}
Expand All @@ -166,7 +163,7 @@ private async void Calculate()

AddInputToHistory(Input);

IsCalculationRunning = false;
IsRunning = false;
}

private void AddInputToHistory(string input)
Expand All @@ -184,18 +181,14 @@ private void AddInputToHistory(string input)

public void OnViewVisible()
{
_isViewActive = true;

}

public void OnViewHide()
{
_isViewActive = false;

}


#endregion

#region Event

#endregion
}
Loading

0 comments on commit d13cf29

Please sign in to comment.