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
2 changes: 0 additions & 2 deletions Source/NETworkManager.Models/Network/DNSLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ private void ProcessDnsAnswers(IEnumerable<DnsResourceRecord> answers, NameServe
if (answers is not DnsResourceRecord[] dnsResourceRecords)
return;

Debug.WriteLine(dnsResourceRecords);

// A
foreach (var record in dnsResourceRecords.OfType<ARecord>())
OnRecordReceived(new DNSLookupRecordReceivedArgs(
Expand Down
4 changes: 3 additions & 1 deletion Source/NETworkManager.Profiles/IProfileManagerMinimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public interface IProfileManagerMinimal
/// </summary>
public void OnProfileManagerDialogOpen()
{

}

/// <summary>
/// Event is fired when a dialog in the <see cref="ProfileManager" /> is closed.
/// </summary>
public void OnProfileManagerDialogClose()
{

}
}
}
2 changes: 1 addition & 1 deletion Source/NETworkManager.Utilities.WPF/BindingProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ protected override Freezable CreateInstanceCore()
{
return new BindingProxy();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Controls;
using NETworkManager.Localization.Resources;
Expand All @@ -10,7 +11,8 @@ public class ProfileFileUniqueValidator : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
return ProfileManager.ProfileFiles.Any(x => x.Name == value as string)
return ProfileManager.ProfileFiles.Any(x =>
string.Equals(x.Name, value as string, StringComparison.OrdinalIgnoreCase))
? new ValidationResult(false, Strings.ProfileNameAlreadyExists)
: ValidationResult.ValidResult;
}
Expand Down
21 changes: 15 additions & 6 deletions Source/NETworkManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,25 @@
</StackPanel>
</Button>
<Button Command="{Binding OpenWebsiteCommand}"
ToolTip="{x:Static localization:Strings.ToolTip_SupportThisProjectWithADonation}"
CommandParameter="{x:Static resources:Resources.NETworkManager_DonateUrl}"
Cursor="Hand"
Focusable="False">
ToolTip="{x:Static localization:Strings.ToolTip_SupportThisProjectWithADonation}"
CommandParameter="{x:Static resources:Resources.NETworkManager_DonateUrl}"
Cursor="Hand"
Focusable="False">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20" Height="20"
Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
<Rectangle Width="20" Height="20">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Uniform" Visual="{iconPacks:Material Kind=Heart}" />
</Rectangle.OpacityMask>
<Rectangle.Style>
<Style TargetType="Rectangle">
<Setter Property="Fill" Value="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=IsMouseOver}" Value="True">
<Setter Property="Fill" Value="#b95353" />
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</StackPanel>
</Button>
Expand Down
3 changes: 2 additions & 1 deletion Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
// Show welcome dialog
if (SettingsManager.Current.WelcomeDialog_Show)
{

var childWindow = new WelcomeChildWindow();

var viewModel = new WelcomeViewModel(instance =>
Expand Down Expand Up @@ -1443,6 +1442,8 @@ private async void LoadProfile(ProfileFileInfo info, bool showWrongPassword = fa
ProfileManager.Unload();
}, info.Name, showWrongPassword);

childWindow.Title = Strings.UnlockProfileFile;

childWindow.DataContext = viewModel;

ConfigurationManager.OnDialogOpen();
Expand Down
5 changes: 5 additions & 0 deletions Source/NETworkManager/NETworkManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\OKCancelInfoMessageChildWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="PowerShell.exe -ExecutionPolicy Bypass -NoProfile -File &quot;$(ProjectDir)..\..\Scripts\PreBuildEventCommandLine.ps1&quot; &quot;$(TargetDir)&quot;" />
Expand Down
182 changes: 96 additions & 86 deletions Source/NETworkManager/ProfileDialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
using NETworkManager.Views;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Security;
using System.Threading.Tasks;
using System.Windows;
using MahApps.Metro.SimpleChildWindow;

namespace NETworkManager;

Expand Down Expand Up @@ -306,7 +309,7 @@ private static GroupInfo ParseGroupInfo(GroupViewModel instance)
{
Name = name,
Description = instance.Description?.Trim(),

Profiles = profiles,

// Remote Desktop
Expand Down Expand Up @@ -466,133 +469,138 @@ private static GroupInfo ParseGroupInfo(GroupViewModel instance)

#region Dialog to add, edit, copy as and delete profile

public static Task ShowAddProfileDialog(object context, IProfileManagerMinimal viewModel,
IDialogCoordinator dialogCoordinator, ProfileInfo profile = null, string group = null,
public static Task ShowAddProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel,
ProfileInfo profile = null, string group = null,
ApplicationName applicationName = ApplicationName.None)
{
CustomDialog customDialog = new()
{
Title = Strings.AddProfile,
Style = (Style)Application.Current.FindResource(DialogResourceKey)
};
var childWindow = new ProfileChildWindow(parentWindow);

ProfileViewModel profileViewModel = new(async instance =>
ProfileViewModel childWindowViewModel = new(instance =>
{
await dialogCoordinator.HideMetroDialogAsync(context, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.AddProfile(ParseProfileInfo(instance));
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(context, customDialog);
Debug.WriteLine("Profile dialog closed without saving");

childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, ProfileManager.GetGroupNames(), group, ProfileEditMode.Add, profile, applicationName);

customDialog.Content = new ProfileDialog
{
DataContext = profileViewModel
};
childWindow.Title = Strings.AddProfile;

viewModel.OnProfileManagerDialogOpen();
childWindow.DataContext = childWindowViewModel;

return dialogCoordinator.ShowMetroDialogAsync(context, customDialog);
viewModel.OnProfileManagerDialogOpen();

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
}

public static Task ShowEditProfileDialog(IProfileManagerMinimal viewModel,
IDialogCoordinator dialogCoordinator, ProfileInfo profile)
public static Task ShowEditProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel,
ProfileInfo profile)
{
CustomDialog customDialog = new()
{
Title = Strings.EditProfile,
Style = (Style)Application.Current.FindResource(DialogResourceKey)
};
var childWindow = new ProfileChildWindow(parentWindow);

ProfileViewModel profileViewModel = new(async instance =>
ProfileViewModel childWindowViewModel = new(instance =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.ReplaceProfile(profile, ParseProfileInfo(instance));
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, ProfileManager.GetGroupNames(), profile.Group, ProfileEditMode.Edit, profile);

customDialog.Content = new ProfileDialog
{
DataContext = profileViewModel
};
childWindow.Title = Strings.EditProfile;

viewModel.OnProfileManagerDialogOpen();
childWindow.DataContext = childWindowViewModel;

return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
viewModel.OnProfileManagerDialogOpen();

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
}

public static Task ShowCopyAsProfileDialog(IProfileManagerMinimal viewModel,
IDialogCoordinator dialogCoordinator, ProfileInfo profile)
public static Task ShowCopyAsProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel,
ProfileInfo profile)
{
CustomDialog customDialog = new()
{
Title = Strings.CopyProfile,
Style = (Style)Application.Current.FindResource(DialogResourceKey)
};
var childWindow = new ProfileChildWindow(parentWindow);

ProfileViewModel profileViewModel = new(async instance =>
ProfileViewModel childWindowViewModel = new(instance =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.AddProfile(ParseProfileInfo(instance));
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, ProfileManager.GetGroupNames(), profile.Group, ProfileEditMode.Copy, profile);

customDialog.Content = new ProfileDialog
{
DataContext = profileViewModel
};

childWindow.Title = Strings.CopyProfile;

childWindow.DataContext = childWindowViewModel;

viewModel.OnProfileManagerDialogOpen();

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
return parentWindow.ShowChildWindowAsync(childWindow);
}

public static Task ShowDeleteProfileDialog(IProfileManagerMinimal viewModel,
IDialogCoordinator dialogCoordinator, IList<ProfileInfo> profiles)
public static Task ShowDeleteProfileDialog(Window parentWindow, IProfileManagerMinimal viewModel,
IList<ProfileInfo> profiles)
{
CustomDialog customDialog = new()
{
Title = profiles.Count == 1
? Strings.DeleteProfile
: Strings.DeleteProfiles
};

ConfirmDeleteViewModel confirmDeleteViewModel = new(async _ =>
var childWindow = new OKCancelInfoMessageChildWindow();

OKCancelInfoMessageViewModel childWindowViewModel = new(_ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.RemoveProfiles(profiles);
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
},
profiles.Count == 1
? Strings.DeleteProfileMessage
: Strings.DeleteProfilesMessage);

customDialog.Content = new ConfirmDeleteDialog
{
DataContext = confirmDeleteViewModel
};
childWindow.Title = Strings.DeleteProfile;

childWindow.DataContext = childWindowViewModel;

viewModel.OnProfileManagerDialogOpen();

Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
return parentWindow.ShowChildWindowAsync(childWindow);
}

#endregion
Expand Down Expand Up @@ -660,34 +668,36 @@ public static Task ShowEditGroupDialog(IProfileManagerMinimal viewModel, IDialog
return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
}

public static Task ShowDeleteGroupDialog(IProfileManagerMinimal viewModel,
IDialogCoordinator dialogCoordinator, GroupInfo group)
public static Task ShowDeleteGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel,
GroupInfo group)
{
CustomDialog customDialog = new()
var childWindow = new OKCancelInfoMessageChildWindow();

OKCancelInfoMessageViewModel childWindowViewModel = new(_ =>
{
Title = Strings.DeleteGroup
};

ConfirmDeleteViewModel confirmDeleteViewModel = new(async _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();

ProfileManager.RemoveGroup(group);
}, async _ =>
}, _ =>
{
await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog);
childWindow.IsOpen = false;
Settings.ConfigurationManager.Current.IsChildWindowOpen = false;

viewModel.OnProfileManagerDialogClose();
}, Strings.DeleteGroupMessage);

customDialog.Content = new ConfirmDeleteDialog
{
DataContext = confirmDeleteViewModel
};
childWindow.Title = Strings.DeleteGroup;

childWindow.DataContext = childWindowViewModel;

viewModel.OnProfileManagerDialogOpen();

return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog);
Settings.ConfigurationManager.Current.IsChildWindowOpen = true;

return parentWindow.ShowChildWindowAsync(childWindow);
}

#endregion
Expand Down
Loading