Skip to content

Commit 71d08e3

Browse files
Refactoring
Fixing IP-Validation Refactoring code Restructuring project
1 parent 3a55f8a commit 71d08e3

File tree

12 files changed

+462
-216
lines changed

12 files changed

+462
-216
lines changed

VLSMistique/AppShell.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
x:Class="VLSMistique.AppShell"
44
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6-
xmlns:local="clr-namespace:VLSMistique"
6+
xmlns:local="clr-namespace:VLSMistique.Views"
77
Shell.FlyoutBehavior="Disabled"
88
Shell.NavBarIsVisible="False">
99

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
/*
5+
* Copyright 2023 Mathias Lund-Hansen
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
using System.Linq;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
using VLSMistique.Models;
24+
25+
namespace VLSMistique.Interfaces
26+
{
27+
/// <summary> Interface for converting a collection of subnet models to a CSV string. </summary>
28+
public interface ICsvConverter
29+
{
30+
/// <summary> Converts the collection of subnet models to a CSV string. </summary>
31+
/// <param name="subnets">The collection of subnet models to convert.</param>
32+
/// <returns>The CSV string representation of the subnet models.</returns>
33+
string Convert(ObservableCollection<SubnetModel> subnets);
34+
}
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 Mathias Lund-Hansen
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Collections.ObjectModel;
20+
using System.Linq;
21+
using System.Text;
22+
using System.Threading.Tasks;
23+
using VLSMistique.Models;
24+
25+
namespace VLSMistique.Interfaces
26+
{
27+
/// <summary> Interface responsible for validating input data. </summary>
28+
public interface IInputValidator
29+
{
30+
/// <summary> Validates the given address, subnet amount, and subnets collection. </summary>
31+
/// <param name="address">The address to validate.</param>
32+
/// <param name="subnetAmount">The number of subnets.</param>
33+
/// <param name="subnets">The collection of subnets.</param>
34+
/// <returns><c>true</c> if the input is valid, otherwise <c>false</c>.</returns>
35+
bool Validate(string address, int subnetAmount, ObservableCollection<SubnetModel> subnets);
36+
}
37+
}

VLSMistique/Interfaces/IVLSMCalculatorModel.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2023 Mathias Lund-Hansen
1+
/*
2+
* Copyright 2023 Mathias Lund-Hansen
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -10,7 +11,8 @@
1011
* distributed under the License is distributed on an "AS IS" BASIS,
1112
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
* See the License for the specific language governing permissions and
13-
* limitations under the License. */
14+
* limitations under the License.
15+
*/
1416

1517
using System;
1618
using System.Collections.Generic;
@@ -21,10 +23,14 @@
2123

2224
namespace VLSMistique.Interfaces
2325
{
24-
/// <summary> Interface for the VLSM calculator model. </summary>
26+
/// <summary> Rhe interface for VLSM calculator model. </summary>
2527
public interface IVLSMCalculatorModel
2628
{
27-
/// <summary> Calculates the subnets based on the given IP addres, the amont of subnets, and a list of host per subnet. </summary>
29+
/// <summary> Calculates subnets based on the provided IP address, subnet amount, and host amounts. </summary>
30+
/// <param name="ipAddress">The IP address.</param>
31+
/// <param name="subnetAmount">The number of subnets.</param>
32+
/// <param name="hostAmounts">The list of host amounts for each subnet.</param>
33+
/// <returns>A list of subnet models.</returns>
2834
List<SubnetModel> CalculateSubnets(string ipAddress, int subnetAmount, List<int> hostAmounts);
2935
}
3036
}

VLSMistique/MauiProgram.cs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
using Microsoft.Extensions.Logging;
1+
/*
2+
* Copyright 2023 Mathias Lund-Hansen
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using CommunityToolkit.Maui;
18+
using CommunityToolkit.Maui.Storage;
19+
using Microsoft.Maui.LifecycleEvents;
220
#if WINDOWS10_0_17763_0_OR_GREATER
321
using Microsoft.UI;
422
using Microsoft.UI.Windowing;
@@ -10,43 +28,39 @@
1028

1129
namespace VLSMistique;
1230

13-
using CommunityToolkit.Maui;
14-
using CommunityToolkit.Maui.Storage;
15-
using Microsoft.Maui.LifecycleEvents;
16-
31+
/// <summary> The main entry point for creating a Maui application. </summary>
1732
public static class MauiProgram
1833
{
1934
public static MauiApp CreateMauiApp()
2035
{
36+
// Create a builder for configuring the Maui app.
2137
var builder = MauiApp.CreateBuilder();
2238
builder
23-
.UseMauiApp<App>()
24-
// Initialize the .NET MAUI Community Toolkit by adding the below line of code
25-
.UseMauiCommunityToolkit()
26-
// After initializing the .NET MAUI Community Toolkit, optionally add additional fonts
39+
.UseMauiApp<App>() // Set the startup App for Maui.
40+
.UseMauiCommunityToolkit() // Initialize the .NET MAUI Community Toolkit.
41+
42+
// Configure custom fonts.
2743
.ConfigureFonts(fonts =>
2844
{
2945
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
3046
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
31-
});
47+
})
48+
.Services.AddSingleton<IFileSaver>(FileSaver.Default); // Register the default file saver service.
3249

3350
// Add support to use the WinUI library.
3451
builder.ConfigureLifecycleEvents(events =>
3552
{
36-
#if WINDOWS10_0_17763_0_OR_GREATER
53+
#if WINDOWS10_0_17763_0_OR_GREATER
3754
events.AddWindows(wndLifeCycleBuilder =>
3855
{
3956
wndLifeCycleBuilder.OnWindowCreated(window =>
4057
{
41-
window.TryMicaOrAcrylic(); //Adds Mica effect.
58+
window.TryMicaOrAcrylic(); //Adds the Mica or Acrylic effect depending on if it's Windows 10 or 11.
4259
});
4360
});
44-
#endif
61+
#endif
4562
});
4663

47-
// Continue initializing your .NET MAUI App here
48-
49-
builder.Services.AddSingleton<IFileSaver>(FileSaver.Default);
50-
return builder.Build();
64+
return builder.Build(); // Build and return the configured Maui app.
5165
}
52-
}
66+
}

VLSMistique/Models/SubnetModel.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Copyright 2023 Mathias Lund-Hansen
1+
/*
2+
* Copyright 2023 Mathias Lund-Hansen
23
*
34
* Licensed under the Apache License, Version 2.0 (the "License");
45
* you may not use this file except in compliance with the License.
@@ -10,18 +11,19 @@
1011
* distributed under the License is distributed on an "AS IS" BASIS,
1112
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1213
* See the License for the specific language governing permissions and
13-
* limitations under the License. */
14+
* limitations under the License.
15+
*/
1416

1517
using CommunityToolkit.Mvvm.ComponentModel;
1618
using System.Net;
1719

1820
namespace VLSMistique.Models
1921
{
20-
/// <summary> The class that represents a subnet. </summary>
22+
/// <summary> Representation of a subnet. </summary>
2123
public partial class SubnetModel : ObservableObject
2224
{
2325
private int _hostAmount;
24-
/// <summary> The required amount of hosts of the subnet. </summary>
26+
/// <summary> Gets or sets the number of hosts in the subnet. </summary>
2527
public int HostAmount
2628
{
2729
get => _hostAmount;
@@ -35,27 +37,27 @@ public int HostAmount
3537
}
3638
public event EventHandler HostAmountChanged;
3739

38-
/// <summary> The Broadcast Address of the subnet. </summary>
40+
/// <summary> The last IP address in the subnet, which is reserved for broadcast. </summary>
3941
[ObservableProperty]
4042
public IPAddress _broadcastAddress;
4143

42-
/// <summary> The Network Address of the subnet. </summary>
44+
/// <summary> The first IP address in the subnet, which is reserved for network addressing. </summary>
4345
[ObservableProperty]
4446
public IPAddress _networkAddress;
4547

46-
/// <summary> The Subnet Mask of the subnet. </summary>
48+
/// <summary> The subnet mask which determines the IP range of the subnet. </summary>
4749
[ObservableProperty]
4850
public IPAddress _mask;
4951

5052
/// <summary> The IP-range of the subnet. Meaning the first and last IP-address of the subnet. </summary>
5153
[ObservableProperty]
5254
public string _range;
5355

54-
/// <summary> The maximum amount of hosts in the subnet. </summary>
56+
/// <summary> The maximum number of hosts that the subnet can support. </summary>
5557
[ObservableProperty]
5658
public string _maxSubnetHosts;
5759

58-
/// <summary> Contains the values of the subnet. </summary>
60+
/// <summary> Constructs a new instance of the SubnetModel class. Which represents a subnet. </summary>
5961
public SubnetModel(IPAddress broadcastAddress, IPAddress networkAddress, IPAddress mask, string range, string maxSubnetHosts, int hostAmount)
6062
{
6163
BroadcastAddress = broadcastAddress;

0 commit comments

Comments
 (0)