Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -18,18 +18,20 @@ public static string GetProfilesFilePath()
return Path.Combine(SettingsManager.GetSettingsLocation(), ProfilesFileName);
}

public static void Load()
public static void Load(bool deserialize = true)
{
Profiles = new ObservableCollection<NetworkInterfaceProfileInfo>();

Deserialize().ForEach(profile => AddProfile(profile));

if (deserialize)
Deserialize().ForEach(profile => AddProfile(profile));

Profiles.CollectionChanged += Profiles_CollectionChanged;
}

public static void Reload()
public static void Import(bool overwrite)
{
Profiles.Clear();
if (overwrite)
Profiles.Clear();

Deserialize().ForEach(profile => AddProfile(profile));
}
Expand Down
11 changes: 7 additions & 4 deletions Source/NETworkManager/Models/Settings/WakeOnLANClientManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows;
using System.Xml.Serialization;

namespace NETworkManager.Models.Settings
Expand All @@ -17,18 +18,20 @@ public static string GetClientsFilePath()
return Path.Combine(SettingsManager.GetSettingsLocation(), ClientsFileName);
}

public static void Load()
public static void Load(bool deserialize = true)
{
Clients = new ObservableCollection<WakeOnLANClientInfo>();

Deserialize().ForEach(client => AddClient(client));
if (deserialize)
Deserialize().ForEach(client => AddClient(client));

Clients.CollectionChanged += WakeOnLANClients_CollectionChanged;
}

public static void Reload()
public static void Import(bool overwrite)
{
Clients.Clear();
if (overwrite)
Clients.Clear();

Deserialize().ForEach(client => AddClient(client));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
<system:String x:Key="String_DefaultGateway">Standardgateway</system:String>
<system:String x:Key="String_AddTemplate">Template hinzufügen</system:String>
<system:String x:Key="String_EnterHostnameForClient">Geben Sie den Hostnamen ein, um den Client später zu identifizieren.</system:String>
<system:String x:Key="String_AllRightReserved">Alle Rechte vorbehalten.</system:String>
<system:String x:Key="String_Administrator">Administrator</system:String>
<system:String x:Key="String_RestartAsAdministrator">Neustart als Administrator</system:String>
<system:String x:Key="String_RestartAsAdministratorMessage">Zum ändern dieser Konfiguration werden administrative Rechte benötigt.</system:String>
Expand Down Expand Up @@ -224,7 +223,9 @@
<system:String x:Key="String_WakeOnLANClientsReloaded">Wake on LAN Clients neu geladen</system:String>
<system:String x:Key="String_NetworkInterfaceProfilesReloaded">Netzwerkinterface Profile neu geladen</system:String>
<system:String x:Key="String_ComingSoon">Kommt demnächst!</system:String>

<system:String x:Key="String_Override">überschreiben</system:String>
<system:String x:Key="String_Add">hinzufügen</system:String>

<!-- Buttons -->
<system:String x:Key="String_Button_Change">Wechseln</system:String>
<system:String x:Key="String_Button_Default">Standard</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
<system:String x:Key="String_DefaultGateway">Default-Gateway</system:String>
<system:String x:Key="String_AddTemplate">Add template</system:String>
<system:String x:Key="String_EnterHostnameForClient">Enter the hostname to identify the client later.</system:String>
<system:String x:Key="String_AllRightReserved">All rights reserved.</system:String>
<system:String x:Key="String_Administrator">Administrator</system:String>
<system:String x:Key="String_RestartAsAdministrator">Restart as Administrator</system:String>
<system:String x:Key="String_RestartAsAdministratorMessage">Administrative rights are required to change this configuration.</system:String>
Expand Down Expand Up @@ -224,6 +223,8 @@
<system:String x:Key="String_WakeOnLANClientsReloaded">Wake on LAN clients reloaded</system:String>
<system:String x:Key="String_NetworkInterfaceProfilesReloaded">Network interface profiles reloaded</system:String>
<system:String x:Key="String_ComingSoon">Coming Soon!</system:String>
<system:String x:Key="String_Override">override</system:String>
<system:String x:Key="String_Add">add</system:String>

<!-- Buttons -->
<system:String x:Key="String_Button_Change">Change</system:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface
DetailsDNSServer = value.DNSServer;

// Configuration
if(value.DhcpEnabled)
if (value.DhcpEnabled)
{
ConfigEnableDynamicIPAddress = true;
}
Expand All @@ -146,7 +146,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface
ConfigGateway = value.IPv4Gateway.FirstOrDefault().ToString();
}

if(value.DNSAutoconfigurationEnabled)
if (value.DNSAutoconfigurationEnabled)
{
ConfigEnableDynamicDNS = true;
}
Expand All @@ -155,7 +155,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface
ConfigEnableStaticDNS = true;

List<IPAddress> DNSServers = value.DNSServer.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToList();
ConfigPrimaryDNSServer = DNSServers.Count > 0 ? DNSServers[0].ToString() : string.Empty ;
ConfigPrimaryDNSServer = DNSServers.Count > 0 ? DNSServers[0].ToString() : string.Empty;
ConfigSecondaryDNSServer = DNSServers.Count > 1 ? DNSServers[1].ToString() : string.Empty;
}

Expand Down Expand Up @@ -629,7 +629,9 @@ public NetworkInterfaceViewModel(IDialogCoordinator instance)
LoadNetworkInterfaces();

// Load profiles
NetworkInterfaceProfileManager.Load();
if (NetworkInterfaceProfileManager.Profiles == null)
NetworkInterfaceProfileManager.Load();

_networkInterfaceProfiles = CollectionViewSource.GetDefaultView(NetworkInterfaceProfileManager.Profiles);

LoadSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public WakeOnLANViewModel(IDialogCoordinator instance)
{
dialogCoordinator = instance;

WakeOnLANClientManager.Load();
if (WakeOnLANClientManager.Clients == null)
WakeOnLANClientManager.Load();

_wakeOnLANClients = CollectionViewSource.GetDefaultView(WakeOnLANClientManager.Clients);

LoadSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ public bool ImportNetworkInterfaceProfiles
}
}

private bool _importOverrideNetworkInterfaceProfiles = true;
public bool ImportOverrideNetworkInterfaceProfiles
{
get { return _importOverrideNetworkInterfaceProfiles; }
set
{
if (value == _importOverrideNetworkInterfaceProfiles)
return;

_importOverrideNetworkInterfaceProfiles = value;
OnPropertyChanged();
}
}

private bool _importWakeOnLANClientsExists;
public bool ImportWakeOnLANClientsExists
{
Expand Down Expand Up @@ -146,6 +160,20 @@ public bool ImportWakeOnLANClients
OnPropertyChanged();
}
}

private bool _importOverrideWakeOnLANClients = true;
public bool ImportOverrideWakeOnLANClients
{
get { return _importOverrideWakeOnLANClients; }
set
{
if (value == _importOverrideWakeOnLANClients)
return;

_importOverrideWakeOnLANClients = value;
OnPropertyChanged();
}
}
#endregion

#region Export
Expand Down Expand Up @@ -327,35 +355,44 @@ private async void ImportSettingsAction()
if (ImportWakeOnLANClientsExists && (ImportEverything || ImportWakeOnLANClients))
importOptions.Add(ImportExportManager.ImportExportOptions.WakeOnLANClients);

// Load network interface profile (option: add)
if (NetworkInterfaceProfileManager.Profiles == null)
NetworkInterfaceProfileManager.Load(!ImportOverrideNetworkInterfaceProfiles);

// Load WoL clients (option: add)
if (WakeOnLANClientManager.Clients == null)
WakeOnLANClientManager.Load(!ImportOverrideWakeOnLANClients);

// Import (copy) files from zip archive
ImportExportManager.Import(ImportLocationSelectedPath, importOptions);

// Restart if application settings are changed
if (ImportExportManager.ForceRestart)
{
CloseAction();
}
else
// Do the import (replace or add)
if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles))
NetworkInterfaceProfileManager.Import(ImportEverything || ImportOverrideNetworkInterfaceProfiles);

if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients))
WakeOnLANClientManager.Import(ImportEverything || ImportOverrideWakeOnLANClients);

// Show the user a message what happened
if (!ImportExportManager.ForceRestart)
{
settings.AffirmativeButtonText = Application.Current.Resources["String_Button_OK"] as string;

message = Application.Current.Resources["String_SettingsSuccessfullyImported"] as string + Environment.NewLine;

if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles))
{
NetworkInterfaceProfileManager.Reload();

message += Environment.NewLine + string.Format("* {0}", Application.Current.Resources["String_NetworkInterfaceProfilesReloaded"] as string);
}

if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients))
{
WakeOnLANClientManager.Reload();

message += Environment.NewLine + string.Format("* {0}", Application.Current.Resources["String_WakeOnLANClientsReloaded"] as string);
}

await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_Success"] as string, message, MessageDialogStyle.Affirmative, settings);

return;
}

// Close this view (this will restart the application)
CloseAction();
}
}

Expand All @@ -370,7 +407,7 @@ private async void ExportSettingsAction()

if (ApplicationSettingsExists && (ExportEverything || ExportApplicationSettings))
exportOptions.Add(ImportExportManager.ImportExportOptions.ApplicationSettings);

if (NetworkInterfaceProfilesExists && (ExportEverything || ExportNetworkInterfaceProfiles))
exportOptions.Add(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<TextBlock Style="{StaticResource DefaultTextBlock}" Text="{StaticResource String_SelectTheSettingsYouWantToImport}" Margin="0,0,0,10" />
<RadioButton x:Name="radioButtonImportEverything" Content="{DynamicResource String_RadioButton_Everything}" IsChecked="{Binding ImportEverything}" Margin="0,0,0,10"/>
<RadioButton x:Name="radioButtonImportCustom" Content="{DynamicResource String_RadioButton_Custom}" Margin="0,0,0,10"/>
<GroupBox Margin="20,0,0,10" MinWidth="250" HorizontalAlignment="Left">
<GroupBox HorizontalAlignment="Left" Margin="20,0,0,10">
<GroupBox.Style>
<Style TargetType="{x:Type GroupBox}" BasedOn="{StaticResource WithoutHeaderGroupBox}">
<Setter Property="IsEnabled" Value="False" />
Expand All @@ -55,11 +55,41 @@
</Style.Triggers>
</Style>
</GroupBox.Style>
<StackPanel>
<CheckBox Content="{DynamicResource String_ApplicationSettings}" IsEnabled="{Binding ImportApplicationSettingsExists}" IsChecked="{Binding ImportApplicationSettings}" Margin="0,0,0,10"/>
<CheckBox Content="{DynamicResource String_NetworkInterfaceProfiles}" IsEnabled="{Binding ImportNetworkInterfaceProfilesExists}" IsChecked="{Binding ImportNetworkInterfaceProfiles}" Margin="0,0,0,10"/>
<CheckBox Content="{DynamicResource String_WakeOnLANClients}" IsEnabled="{Binding ImportWakeOnLANClientsExists}" IsChecked="{Binding ImportWakeOnLANClients}" />
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="240" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<CheckBox Grid.Column="0" Grid.Row="0" Content="{DynamicResource String_ApplicationSettings}" IsEnabled="{Binding ImportApplicationSettingsExists}" IsChecked="{Binding ImportApplicationSettings}" />
<CheckBox Grid.Column="0" Grid.Row="2" Content="{DynamicResource String_NetworkInterfaceProfiles}" IsEnabled="{Binding ImportNetworkInterfaceProfilesExists}" IsChecked="{Binding ImportNetworkInterfaceProfiles}" />
<Grid Grid.Column="2" Grid.Row="2" IsEnabled="{Binding ImportNetworkInterfaceProfilesExists}">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" />
<ColumnDefinition Width="10" />
<ColumnDefinition MinWidth="100" />
</Grid.ColumnDefinitions>
<RadioButton Grid.Column="0" Grid.Row="0" GroupName="ImportNetworkInterfaceProfiles" Content="{DynamicResource String_Override}" IsEnabled="{Binding ImportNetworkInterfaceProfilesExists}" IsChecked="{Binding ImportOverrideNetworkInterfaceProfiles}" />
<RadioButton Grid.Column="2" Grid.Row="0" GroupName="ImportNetworkInterfaceProfiles" Content="{DynamicResource String_Add}" IsEnabled="{Binding ImportNetworkInterfaceProfilesExists}" />
</Grid>
<CheckBox Grid.Column="0" Grid.Row="4" Content="{DynamicResource String_WakeOnLANClients}" IsEnabled="{Binding ImportWakeOnLANClientsExists}" IsChecked="{Binding ImportWakeOnLANClients}" />
<Grid Grid.Column="2" Grid.Row="4" IsEnabled="{Binding ImportWakeOnLANClientsExists}">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" />
<ColumnDefinition Width="10" />
<ColumnDefinition MinWidth="100" />
</Grid.ColumnDefinitions>
<RadioButton Grid.Column="0" Grid.Row="0" GroupName="ImportWakeOnLANClients" Content="{DynamicResource String_Override}" IsEnabled="{Binding ImportWakeOnLANClientsExists}" IsChecked="{Binding ImportOverrideWakeOnLANClients}" />
<RadioButton Grid.Column="2" Grid.Row="0" GroupName="ImportWakeOnLANClients" Content="{DynamicResource String_Add}" IsEnabled="{Binding ImportWakeOnLANClientsExists}" />
</Grid>
</Grid>
</GroupBox>
<Button Content="{DynamicResource String_Button_Import}" Command="{Binding ImportSettingsCommand}" HorizontalAlignment="Left" >
<Button.Style>
Expand Down