| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | 
							- using DynamicData;
 
- using DynamicData.Binding;
 
- using Microsoft.VisualStudio.Threading;
 
- using NatTypeTester.Models;
 
- using ReactiveUI;
 
- using STUN;
 
- using System.Reactive.Linq;
 
- using Volo.Abp.DependencyInjection;
 
- namespace NatTypeTester.ViewModels;
 
- [ExposeServices(
 
- 	typeof(MainWindowViewModel),
 
- 	typeof(IScreen)
 
- )]
 
- public class MainWindowViewModel : ViewModelBase, IScreen
 
- {
 
- 	public RoutingState Router => LazyServiceProvider.LazyGetRequiredService<RoutingState>();
 
- 	public Config Config => LazyServiceProvider.LazyGetRequiredService<Config>();
 
- 	private readonly IEnumerable<string> _defaultServers = new HashSet<string>
 
- 	{
 
- 		@"stun.syncthing.net",
 
- 		@"stunserver.stunprotocol.org",
 
- 		@"stun.miwifi.com",
 
- 		@"stun.qq.com"
 
- 	};
 
- 	private SourceList<string> List { get; } = new();
 
- 	public readonly IObservableCollection<string> StunServers = new ObservableCollectionExtended<string>();
 
- 	public MainWindowViewModel()
 
- 	{
 
- 		List.Connect()
 
- 			.DistinctValues(x => x)
 
- 			.ObserveOn(RxApp.MainThreadScheduler)
 
- 			.Bind(StunServers)
 
- 			.Subscribe();
 
- 	}
 
- 	public void LoadStunServer()
 
- 	{
 
- 		foreach (string? server in _defaultServers)
 
- 		{
 
- 			List.Add(server);
 
- 		}
 
- 		Config.StunServer = _defaultServers.First();
 
- 		Task.Run(() =>
 
- 		{
 
- 			const string path = @"stun.txt";
 
- 			if (!File.Exists(path))
 
- 			{
 
- 				return;
 
- 			}
 
- 			foreach (string? line in File.ReadLines(path))
 
- 			{
 
- 				if (!string.IsNullOrWhiteSpace(line) && StunServer.TryParse(line, out StunServer? stun))
 
- 				{
 
- 					List.Add(stun.ToString());
 
- 				}
 
- 			}
 
- 		}).Forget();
 
- 	}
 
- }
 
 
  |