2015-10-19 20:20:42 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-11-07 14:08:26 -08:00
|
|
|
|
using System.Diagnostics;
|
2015-11-04 20:34:49 -08:00
|
|
|
|
using System.IO;
|
2015-10-19 20:20:42 -07:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2015-10-23 15:49:04 -07:00
|
|
|
|
using System.Text.RegularExpressions;
|
2015-10-26 18:31:10 -07:00
|
|
|
|
using System.Timers;
|
2015-10-19 20:20:42 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
2015-10-26 18:31:10 -07:00
|
|
|
|
using System.Windows.Threading;
|
2016-11-21 12:54:27 -08:00
|
|
|
|
using System.ComponentModel;
|
2015-10-19 20:20:42 -07:00
|
|
|
|
|
|
|
|
|
namespace WinUI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
2016-11-09 10:32:18 -08:00
|
|
|
|
public partial class NetworkListView : Window
|
2015-10-19 20:20:42 -07:00
|
|
|
|
{
|
2015-10-26 18:08:44 -07:00
|
|
|
|
Regex charRegex = new Regex("[0-9a-fxA-FX]");
|
|
|
|
|
Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
|
2015-10-21 20:29:03 -07:00
|
|
|
|
|
2016-11-09 10:32:18 -08:00
|
|
|
|
public NetworkListView()
|
2015-10-19 20:20:42 -07:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-11-07 14:08:26 -08:00
|
|
|
|
|
2016-11-18 13:52:48 -08:00
|
|
|
|
Closed += onClosed;
|
2016-11-10 14:17:57 -08:00
|
|
|
|
|
2016-11-18 13:52:48 -08:00
|
|
|
|
NetworkMonitor.Instance.SubscribeNetworkUpdates(updateNetworks);
|
2015-10-21 20:29:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 13:52:48 -08:00
|
|
|
|
~NetworkListView()
|
2015-10-21 20:29:03 -07:00
|
|
|
|
{
|
2016-11-18 13:52:48 -08:00
|
|
|
|
}
|
2015-11-04 18:28:07 -08:00
|
|
|
|
|
2016-11-21 12:54:27 -08:00
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 13:52:48 -08:00
|
|
|
|
private void onClosed(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
NetworkMonitor.Instance.UnsubscribeNetworkUpdates(updateNetworks);
|
2015-10-21 20:29:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 14:17:57 -08:00
|
|
|
|
private void updateNetworks(List<ZeroTierNetwork> networks)
|
2015-10-21 20:29:03 -07:00
|
|
|
|
{
|
2016-11-10 14:17:57 -08:00
|
|
|
|
if (networks != null)
|
2015-10-26 18:31:10 -07:00
|
|
|
|
{
|
2016-11-10 14:17:57 -08:00
|
|
|
|
networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
networksPage.setNetworks(networks);
|
|
|
|
|
}));
|
|
|
|
|
}
|
2015-10-26 18:31:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 15:49:04 -07:00
|
|
|
|
private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
|
2015-10-23 15:36:42 -07:00
|
|
|
|
{
|
2015-10-26 18:08:44 -07:00
|
|
|
|
e.Handled = !charRegex.IsMatch(e.Text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPaste(object sender, DataObjectPastingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
|
|
|
|
|
if (!isText) return;
|
|
|
|
|
|
|
|
|
|
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
|
|
|
|
|
|
|
|
|
|
if (!wholeStringRegex.IsMatch(text))
|
|
|
|
|
{
|
|
|
|
|
e.CancelCommand();
|
|
|
|
|
}
|
2015-10-23 15:36:42 -07:00
|
|
|
|
}
|
2015-10-19 20:20:42 -07:00
|
|
|
|
}
|
|
|
|
|
}
|