Bruce Wayne 5 years ago
parent
commit
2344220d91
4 changed files with 106 additions and 102 deletions
  1. 5 1
      .editorconfig
  2. 21 21
      NatTypeTester-Console/Program.cs
  3. 13 13
      NatTypeTester/App.cs
  4. 67 67
      NatTypeTester/MainWindow.xaml.cs

+ 5 - 1
.editorconfig

@@ -1,4 +1,4 @@
-# http://editorconfig.org/
+# http://editorconfig.org/
 
 
 # top-most EditorConfig file
 # top-most EditorConfig file
 root = true
 root = true
@@ -6,4 +6,8 @@ root = true
 # all files
 # all files
 [*]
 [*]
 indent_style = space
 indent_style = space
+indent_size = 4
+
+[*.xaml]
+indent_style = tab
 indent_size = 4
 indent_size = 4

+ 21 - 21
NatTypeTester-Console/Program.cs

@@ -1,25 +1,25 @@
-using System;
-using STUN.Utils;
+using STUN.Utils;
+using System;
 
 
 namespace NatTypeTester_Console
 namespace NatTypeTester_Console
 {
 {
-	internal static class Program
-	{
-		private static void Main(string[] args)
-		{
-			var server = @"stun.qq.com";
-			ushort port = 3478;
-			if (args.Length > 0)
-			{
-				server = args[0];
-			}
-			if (args.Length > 1)
-			{
-				ushort.TryParse(args[1], out port);
-			}
-			var res = NetUtils.NatTypeTestCore(NetUtils.DefaultLocalEnd, server, port);
-			var natType = res.Item1;
-			Console.WriteLine(string.IsNullOrWhiteSpace(natType) ? @"Error" : natType);
-		}
-	}
+    internal static class Program
+    {
+        private static void Main(string[] args)
+        {
+            var server = @"stun.qq.com";
+            ushort port = 3478;
+            if (args.Length > 0)
+            {
+                server = args[0];
+            }
+            if (args.Length > 1)
+            {
+                ushort.TryParse(args[1], out port);
+            }
+            var res = NetUtils.NatTypeTestCore(NetUtils.DefaultLocalEnd, server, port);
+            var natType = res.Item1;
+            Console.WriteLine(string.IsNullOrWhiteSpace(natType) ? @"Error" : natType);
+        }
+    }
 }
 }

+ 13 - 13
NatTypeTester/App.cs

@@ -3,19 +3,19 @@ using System.Windows;
 
 
 namespace NatTypeTester
 namespace NatTypeTester
 {
 {
-	internal static class App
-	{
-		[STAThread]
-		private static void Main()
-		{
-			var app = new Application();
-			var win = new MainWindow();
+    internal static class App
+    {
+        [STAThread]
+        private static void Main()
+        {
+            var app = new Application();
+            var win = new MainWindow();
 
 
-			app.MainWindow = win;
-			win.Show();
+            app.MainWindow = win;
+            win.Show();
 
 
-			app.ShutdownMode = ShutdownMode.OnMainWindowClose;
-			app.Run();
-		}
-	}
+            app.ShutdownMode = ShutdownMode.OnMainWindowClose;
+            app.Run();
+        }
+    }
 }
 }

+ 67 - 67
NatTypeTester/MainWindow.xaml.cs

@@ -1,82 +1,82 @@
 using NatTypeTester.Model;
 using NatTypeTester.Model;
+using STUN.Utils;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.IO;
 using System.IO;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 using System.Windows.Input;
 using System.Windows.Input;
-using STUN.Utils;
 
 
 namespace NatTypeTester
 namespace NatTypeTester
 {
 {
-	public partial class MainWindow
-	{
-		public MainWindow()
-		{
-			InitializeComponent();
-			LoadStunServer();
-		}
+    public partial class MainWindow
+    {
+        public MainWindow()
+        {
+            InitializeComponent();
+            LoadStunServer();
+        }
 
 
-		public static HashSet<string> StunServers { get; set; } = new HashSet<string>
-		{
-				@"stun.qq.com",
-				@"stun.miwifi.com",
-				@"stun.bige0.com",
-				@"stun.syncthing.net",
-				@"stun.stunprotocol.org"
-		};
+        public static HashSet<string> StunServers { get; set; } = new HashSet<string>
+        {
+                @"stun.qq.com",
+                @"stun.miwifi.com",
+                @"stun.bige0.com",
+                @"stun.syncthing.net",
+                @"stun.stunprotocol.org"
+        };
 
 
-		private async void TestButton_OnClick(object sender, RoutedEventArgs e)
-		{
-			var stun = new StunServer();
-			if (stun.Parse(ServersComboBox.Text))
-			{
-				var server = stun.Hostname;
-				var port = stun.Port;
-				var local = LocalEndTextBox.Text;
-				TestButton.IsEnabled = false;
-				await Task.Run(() =>
-				{
-					var (natType, localEnd, publicEnd) = NetUtils.NatTypeTestCore(local, server, port);
+        private async void TestButton_OnClick(object sender, RoutedEventArgs e)
+        {
+            var stun = new StunServer();
+            if (stun.Parse(ServersComboBox.Text))
+            {
+                var server = stun.Hostname;
+                var port = stun.Port;
+                var local = LocalEndTextBox.Text;
+                TestButton.IsEnabled = false;
+                await Task.Run(() =>
+                {
+                    var (natType, localEnd, publicEnd) = NetUtils.NatTypeTestCore(local, server, port);
 
 
-					Dispatcher?.InvokeAsync(() =>
-					{
-						NatTypeTextBox.Text = natType;
-						LocalEndTextBox.Text = localEnd;
-						PublicEndTextBox.Text = publicEnd;
-						TestButton.IsEnabled = true;
-					});
-				});
-			}
-			else
-			{
-				MessageBox.Show(@"Wrong Stun server!", @"NatTypeTester", MessageBoxButton.OK, MessageBoxImage.Error);
-			}
-		}
+                    Dispatcher?.InvokeAsync(() =>
+                    {
+                        NatTypeTextBox.Text = natType;
+                        LocalEndTextBox.Text = localEnd;
+                        PublicEndTextBox.Text = publicEnd;
+                        TestButton.IsEnabled = true;
+                    });
+                });
+            }
+            else
+            {
+                MessageBox.Show(@"Wrong Stun server!", @"NatTypeTester", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+        }
 
 
-		private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
-		{
-			if (e.Key == Key.Enter)
-			{
-				TestButton_OnClick(this, new RoutedEventArgs());
-			}
-		}
+        private void MainWindow_OnKeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.Key == Key.Enter)
+            {
+                TestButton_OnClick(this, new RoutedEventArgs());
+            }
+        }
 
 
-		private async void LoadStunServer()
-		{
-			const string path = @"stun.txt";
-			if (File.Exists(path))
-			{
-				using var sw = new StreamReader(path);
-				string line;
-				var stun = new StunServer();
-				while ((line = await sw.ReadLineAsync()) != null)
-				{
-					if (!string.IsNullOrWhiteSpace(line) && stun.Parse(line))
-					{
-						StunServers.Add(stun.ToString());
-					}
-				}
-			}
-		}
-	}
+        private async void LoadStunServer()
+        {
+            const string path = @"stun.txt";
+            if (File.Exists(path))
+            {
+                using var sw = new StreamReader(path);
+                string line;
+                var stun = new StunServer();
+                while ((line = await sw.ReadLineAsync()) != null)
+                {
+                    if (!string.IsNullOrWhiteSpace(line) && stun.Parse(line))
+                    {
+                        StunServers.Add(stun.ToString());
+                    }
+                }
+            }
+        }
+    }
 }
 }