-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
667 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Application | ||
x:Class="NatTypeTester.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
<Application.Resources> | ||
<ResourceDictionary> | ||
<ResourceDictionary.MergedDictionaries> | ||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /> | ||
<!-- Other merged dictionaries here --> | ||
</ResourceDictionary.MergedDictionaries> | ||
<!-- Other app resources here --> | ||
</ResourceDictionary> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace NatTypeTester; | ||
|
||
public partial class App | ||
{ | ||
private readonly IAbpApplicationWithInternalServiceProvider _application; | ||
|
||
public App() | ||
{ | ||
InitializeComponent(); | ||
_application = AbpApplicationFactory.Create<NatTypeTesterModule>(options => options.UseAutofac()); | ||
_application.Initialize(); | ||
_application.ServiceProvider.UseMicrosoftDependencyResolver(); | ||
} | ||
|
||
protected override void OnLaunched(LaunchActivatedEventArgs args) | ||
{ | ||
_application.ServiceProvider.GetRequiredService<MainWindow>().Activate(); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace NatTypeTester.Extensions; | ||
|
||
internal static class ContentDialogExtensions | ||
{ | ||
public static async ValueTask HandleExceptionWithContentDialogAsync(this Exception ex, XamlRoot root) | ||
{ | ||
ContentDialog dialog = new(); | ||
try | ||
{ | ||
dialog.XamlRoot = root; | ||
dialog.Title = nameof(NatTypeTester); | ||
dialog.Content = ex.Message; | ||
dialog.PrimaryButtonText = @"OK"; | ||
|
||
await dialog.ShowAsync(); | ||
} | ||
finally | ||
{ | ||
dialog.Hide(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace NatTypeTester.Extensions; | ||
|
||
internal static class DIExtension | ||
{ | ||
public static T GetRequiredService<T>(this IReadonlyDependencyResolver resolver, string? contract = null) where T : notnull | ||
{ | ||
Requires.NotNull(resolver); | ||
|
||
T? service = resolver.GetService<T>(contract); | ||
|
||
Verify.Operation(service is not null, $@"No service for type {typeof(T)} has been registered."); | ||
|
||
return service; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Window | ||
x:Class="NatTypeTester.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
> | ||
<Frame x:Name="MainFrame" /> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace NatTypeTester; | ||
|
||
public sealed partial class MainWindow : ISingletonDependency | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
Title = nameof(NatTypeTester); | ||
ExtendsContentIntoTitleBar = true; | ||
|
||
AppWindow.Resize(new SizeInt32(500, 590)); | ||
AppWindow.SetIcon(@"Assets\icon.ico"); | ||
|
||
// CenterScreen | ||
{ | ||
DisplayArea displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest); | ||
int x = (displayArea.WorkArea.Width - AppWindow.Size.Width) / 2; | ||
int y = (displayArea.WorkArea.Height - AppWindow.Size.Height) / 2; | ||
AppWindow.Move(new PointInt32(x, y)); | ||
} | ||
|
||
MainFrame.Navigate(typeof(MainPage)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework> | ||
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> | ||
<RootNamespace>NatTypeTester</RootNamespace> | ||
<AssemblyName>NatTypeTester</AssemblyName> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
<Platforms>x64;ARM64</Platforms> | ||
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers> | ||
<UseWinUI>true</UseWinUI> | ||
<ApplicationIcon>Assets\icon.ico</ApplicationIcon> | ||
<Version>8.0.0</Version> | ||
<EnableMsixTooling>true</EnableMsixTooling> | ||
<WindowsPackageType>None</WindowsPackageType> | ||
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231115000" /> | ||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" /> | ||
<PackageReference Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="1.3.1" PrivateAssets="all" /> | ||
<PackageReference Include="ReactiveUI.WinUI" Version="19.5.1" /> | ||
<PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" Version="14.8.6" /> | ||
<PackageReference Include="Volo.Abp.Autofac" Version="7.4.2" /> | ||
<Manifest Include="$(ApplicationManifest)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\NatTypeTester.ViewModels\NatTypeTester.ViewModels.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
global using JetBrains.Annotations; | ||
global using Microsoft; | ||
global using Microsoft.Extensions.DependencyInjection; | ||
global using Microsoft.Extensions.DependencyInjection.Extensions; | ||
global using Microsoft.UI.Windowing; | ||
global using Microsoft.UI.Xaml; | ||
global using Microsoft.UI.Xaml.Controls; | ||
global using Microsoft.VisualStudio.Threading; | ||
global using NatTypeTester.Extensions; | ||
global using NatTypeTester.ViewModels; | ||
global using NatTypeTester.Views; | ||
global using ReactiveMarbles.ObservableEvents; | ||
global using ReactiveUI; | ||
global using Splat; | ||
global using Splat.Microsoft.Extensions.DependencyInjection; | ||
global using STUN.Enums; | ||
global using System.Reactive.Disposables; | ||
global using System.Reactive.Linq; | ||
global using Volo.Abp; | ||
global using Volo.Abp.Autofac; | ||
global using Volo.Abp.DependencyInjection; | ||
global using Volo.Abp.Modularity; | ||
global using Windows.Graphics; | ||
global using Windows.System; | ||
|
||
namespace NatTypeTester; | ||
|
||
[DependsOn( | ||
typeof(AbpAutofacModule), | ||
typeof(NatTypeTesterViewModelModule) | ||
)] | ||
[UsedImplicitly] | ||
internal class NatTypeTesterModule : AbpModule | ||
{ | ||
public override void PreConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
context.Services.UseMicrosoftDependencyResolver(); | ||
Locator.CurrentMutable.InitializeSplat(); | ||
Locator.CurrentMutable.InitializeReactiveUI(RegistrationNamespace.WinUI); | ||
} | ||
|
||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
context.Services.TryAddTransient<RoutingState>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<views:MainReactivePage | ||
x:Class="NatTypeTester.Views.MainPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:views="using:NatTypeTester.Views" | ||
xmlns:reactiveUi="using:ReactiveUI" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid RowDefinitions="28,Auto,*" > | ||
|
||
<!-- TitleBar --> | ||
<StackPanel | ||
Padding="8,0,0,0" | ||
Orientation="Horizontal" | ||
Spacing="5"> | ||
<Image Height="16" Source="/Assets/icon.ico" /> | ||
<TextBlock | ||
Style="{StaticResource CaptionTextBlockStyle}" | ||
VerticalAlignment="Center" | ||
Text="NatTypeTester" /> | ||
</StackPanel> | ||
|
||
<StackPanel Grid.Row="1"> | ||
<ComboBox x:Name="ServersComboBox" | ||
Margin="10,10" | ||
IsEditable="True" | ||
Header="STUN Server" | ||
HorizontalAlignment="Stretch"> | ||
<ComboBox.ItemTemplate> | ||
<DataTemplate> | ||
<TextBlock Text="{Binding }"/> | ||
</DataTemplate> | ||
</ComboBox.ItemTemplate> | ||
</ComboBox> | ||
</StackPanel> | ||
|
||
<NavigationView | ||
Grid.Row="2" | ||
x:Name="NavigationView" | ||
IsBackEnabled="False" | ||
IsBackButtonVisible="Collapsed" | ||
PaneDisplayMode="LeftCompact" | ||
IsPaneOpen="False"> | ||
|
||
<NavigationView.MenuItems> | ||
<NavigationViewItem Content="RFC 5780" Tag="1"> | ||
<NavigationViewItem.Icon> | ||
<FontIcon Glyph="" /> | ||
</NavigationViewItem.Icon> | ||
</NavigationViewItem> | ||
<NavigationViewItem Content="RFC 3489" Tag="2"> | ||
<NavigationViewItem.Icon> | ||
<FontIcon Glyph="" /> | ||
</NavigationViewItem.Icon> | ||
</NavigationViewItem> | ||
</NavigationView.MenuItems> | ||
|
||
<reactiveUi:RoutedViewHost | ||
x:Name="RoutedViewHost" | ||
HorizontalContentAlignment="Stretch" | ||
VerticalContentAlignment="Stretch"> | ||
<reactiveUi:RoutedViewHost.ContentTransitions> | ||
<TransitionCollection> | ||
<ContentThemeTransition /> | ||
</TransitionCollection> | ||
</reactiveUi:RoutedViewHost.ContentTransitions> | ||
</reactiveUi:RoutedViewHost> | ||
|
||
</NavigationView> | ||
|
||
</Grid> | ||
</views:MainReactivePage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace NatTypeTester.Views; | ||
|
||
internal sealed partial class MainPage | ||
{ | ||
public MainPage() | ||
{ | ||
InitializeComponent(); | ||
ViewModel = Locator.Current.GetRequiredService<MainWindowViewModel>(); | ||
|
||
IAbpLazyServiceProvider serviceProvider = Locator.Current.GetRequiredService<IAbpLazyServiceProvider>(); | ||
|
||
this.WhenActivated(d => | ||
{ | ||
this.Bind(ViewModel, | ||
vm => vm.Config.StunServer, | ||
v => v.ServersComboBox.Text | ||
).DisposeWith(d); | ||
|
||
this.OneWayBind(ViewModel, | ||
vm => vm.StunServers, | ||
v => v.ServersComboBox.ItemsSource | ||
).DisposeWith(d); | ||
|
||
this.OneWayBind(ViewModel, vm => vm.Router, v => v.RoutedViewHost.Router).DisposeWith(d); | ||
|
||
NavigationView.Events().SelectionChanged.Subscribe(parameter => | ||
{ | ||
if (parameter.args.IsSettingsSelected) | ||
{ | ||
ViewModel.Router.Navigate.Execute(serviceProvider.LazyGetRequiredService<SettingViewModel>()).Subscribe().Dispose(); | ||
return; | ||
} | ||
|
||
if (parameter.args.SelectedItem is not NavigationViewItem { Tag: string tag }) | ||
{ | ||
return; | ||
} | ||
|
||
switch (tag) | ||
{ | ||
case @"1": | ||
{ | ||
ViewModel.Router.Navigate.Execute(serviceProvider.LazyGetRequiredService<RFC5780ViewModel>()).Subscribe().Dispose(); | ||
break; | ||
} | ||
case @"2": | ||
{ | ||
ViewModel.Router.Navigate.Execute(serviceProvider.LazyGetRequiredService<RFC3489ViewModel>()).Subscribe().Dispose(); | ||
break; | ||
} | ||
} | ||
}).DisposeWith(d); | ||
NavigationView.SelectedItem = NavigationView.MenuItems.OfType<NavigationViewItem>().First(); | ||
|
||
ViewModel.LoadStunServer(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.