2016-11-08 22:54:55 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-11-10 22:17:57 +00:00
|
|
|
|
using System.Collections.ObjectModel;
|
2016-11-17 22:13:05 +00:00
|
|
|
|
using System.ComponentModel;
|
2016-11-08 22:54:55 +00:00
|
|
|
|
using System.Linq;
|
2016-11-17 22:13:05 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2016-11-08 22:54:55 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
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.Shapes;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Timers;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
namespace WinUI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for ToolbarItem.xaml
|
|
|
|
|
/// </summary>
|
2016-11-17 22:13:05 +00:00
|
|
|
|
public partial class ToolbarItem : Window, INotifyPropertyChanged
|
2016-11-08 22:54:55 +00:00
|
|
|
|
{
|
2016-11-09 00:31:07 +00:00
|
|
|
|
private APIHandler handler = APIHandler.Instance;
|
|
|
|
|
|
2016-11-10 22:17:57 +00:00
|
|
|
|
private NetworkListView netListView = null;
|
|
|
|
|
|
2016-11-14 22:56:36 +00:00
|
|
|
|
private NetworkMonitor mon = NetworkMonitor.Instance;
|
|
|
|
|
|
2016-11-17 22:13:05 +00:00
|
|
|
|
private ObservableCollection<MenuItem> _networkCollection = new ObservableCollection<MenuItem>();
|
2016-11-10 22:17:57 +00:00
|
|
|
|
|
2016-11-17 22:13:05 +00:00
|
|
|
|
public ObservableCollection<MenuItem> NetworkCollection
|
2016-11-10 22:17:57 +00:00
|
|
|
|
{
|
|
|
|
|
get { return _networkCollection; }
|
|
|
|
|
set { _networkCollection = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 22:54:55 +00:00
|
|
|
|
public ToolbarItem()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-11-10 22:17:57 +00:00
|
|
|
|
|
2016-11-14 22:56:36 +00:00
|
|
|
|
mon.SubscribeNetworkUpdates(updateNetworks);
|
|
|
|
|
mon.SubscribeStatusUpdates(updateStatus);
|
|
|
|
|
}
|
2016-11-10 22:17:57 +00:00
|
|
|
|
|
2016-11-14 22:56:36 +00:00
|
|
|
|
~ToolbarItem()
|
|
|
|
|
{
|
|
|
|
|
mon.UnsubscribeNetworkUpdates(updateNetworks);
|
|
|
|
|
mon.UnsubscribeStatusUpdates(updateStatus);
|
2016-11-10 22:17:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 22:13:05 +00:00
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
|
|
|
|
{
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-10 22:17:57 +00:00
|
|
|
|
private void updateNetworks(List<ZeroTierNetwork> networks)
|
|
|
|
|
{
|
|
|
|
|
if (networks != null)
|
|
|
|
|
{
|
|
|
|
|
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
|
|
|
|
{
|
2016-11-17 22:13:05 +00:00
|
|
|
|
NetworkCollection.Clear();
|
2016-11-10 22:17:57 +00:00
|
|
|
|
foreach (ZeroTierNetwork n in networks)
|
|
|
|
|
{
|
2016-11-17 22:13:05 +00:00
|
|
|
|
MenuItem item = new MenuItem();
|
|
|
|
|
item.Header = n.Title;
|
|
|
|
|
item.DataContext = n;
|
|
|
|
|
item.IsChecked = n.IsConnected;
|
|
|
|
|
item.Click += ToolbarItem_NetworkClicked;
|
2016-11-10 22:17:57 +00:00
|
|
|
|
|
2016-11-17 22:13:05 +00:00
|
|
|
|
NetworkCollection.Add(item);
|
|
|
|
|
}
|
2016-11-10 22:17:57 +00:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateStatus(ZeroTierStatus status)
|
|
|
|
|
{
|
|
|
|
|
if (status != null)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
nodeIdMenuItem.Header = "Node ID: " + status.Address;
|
|
|
|
|
nodeIdMenuItem.IsEnabled = true;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 22:54:55 +00:00
|
|
|
|
private void ToolbarItem_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("TrayContextMenuOpen");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolbarItem_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("PreviewTrayContextMenuOpen");
|
|
|
|
|
}
|
2016-11-09 00:31:07 +00:00
|
|
|
|
|
|
|
|
|
private void ToolbarItem_NodeIDClicked(object sender, System.Windows.RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolbarItem_ShowNetworksClicked(object sender, System.Windows.RoutedEventArgs e)
|
|
|
|
|
{
|
2016-11-10 22:17:57 +00:00
|
|
|
|
if (netListView == null)
|
2016-11-09 00:31:07 +00:00
|
|
|
|
{
|
2016-11-10 22:17:57 +00:00
|
|
|
|
netListView = new WinUI.NetworkListView();
|
|
|
|
|
netListView.Closed += ShowNetworksClosed;
|
|
|
|
|
netListView.Show();
|
2016-11-09 00:31:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowNetworksClosed(object sender, System.EventArgs e)
|
|
|
|
|
{
|
2016-11-10 22:17:57 +00:00
|
|
|
|
netListView = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolbarItem_JoinNetworkClicked(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void JoinNetworkClosed(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
2016-11-09 00:31:07 +00:00
|
|
|
|
}
|
2016-11-17 22:13:05 +00:00
|
|
|
|
|
|
|
|
|
private void ToolbarItem_NetworkClicked(object sender, System.Windows.RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(sender.GetType() == typeof(MenuItem))
|
|
|
|
|
{
|
|
|
|
|
MenuItem item = e.Source as MenuItem;
|
|
|
|
|
if (item.DataContext != null)
|
|
|
|
|
{
|
|
|
|
|
ZeroTierNetwork network = item.DataContext as ZeroTierNetwork;
|
|
|
|
|
if (item.IsChecked)
|
|
|
|
|
{
|
|
|
|
|
APIHandler.Instance.LeaveNetwork(network.NetworkId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
APIHandler.Instance.JoinNetwork(network.NetworkId, network.AllowManaged, network.AllowGlobal, network.AllowDefault);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-08 22:54:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|