From 5b6ddaa2d744dfc726829da0893a7f03c9043c8a Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 21 Oct 2015 20:29:03 -0700 Subject: [PATCH] Base windows UI is working. * No joining/leaving networks yet, but they do display. * Nothing is updated yet after first load of the app. Need to set up a background task to run updates. --- .gitignore | 1 + windows/WinUI/APIHandler.cs | 69 +++++++++++++++++ windows/WinUI/MainWindow.xaml | 15 ++-- windows/WinUI/MainWindow.xaml.cs | 21 +++++ windows/WinUI/NetworkInfoView.xaml | 107 ++++++++++++++------------ windows/WinUI/NetworkInfoView.xaml.cs | 40 +++++++++- windows/WinUI/NetworksPage.xaml | 11 +++ windows/WinUI/NetworksPage.xaml.cs | 40 ++++++++++ windows/WinUI/WinUI.csproj | 25 +++++- windows/WinUI/ZeroTierNetwork.cs | 26 +++++++ windows/WinUI/ZeroTierStatus.cs | 21 +++++ windows/WinUI/packages.config | 4 + windows/packages/.gitignore | 3 + windows/packages/repositories.config | 4 + 14 files changed, 329 insertions(+), 58 deletions(-) create mode 100644 windows/WinUI/APIHandler.cs create mode 100644 windows/WinUI/NetworksPage.xaml create mode 100644 windows/WinUI/NetworksPage.xaml.cs create mode 100644 windows/WinUI/ZeroTierNetwork.cs create mode 100644 windows/WinUI/ZeroTierStatus.cs create mode 100644 windows/WinUI/packages.config create mode 100644 windows/packages/.gitignore create mode 100644 windows/packages/repositories.config diff --git a/.gitignore b/.gitignore index f008e76c1..d9654839e 100755 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ java/build_win32/ /java/mac32_64/ windows/WinUI/obj/ windows/WinUI/bin/ +windows/ZeroTierOne/Debug/ diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs new file mode 100644 index 000000000..c13bca538 --- /dev/null +++ b/windows/WinUI/APIHandler.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Net; +using System.IO; +using Newtonsoft.Json; + +namespace WinUI +{ + + + public class APIHandler + { + static string authtoken = "p3ptrzds5jkr2hbx5ipbyf04"; // delete me! + + private string url = null; + + public APIHandler() + { + url = "http://127.0.0.1:9993"; + } + + public APIHandler(string host, int port) + { + url = "http://" + host + ":" + port; + } + + public ZeroTierStatus getStatus() + { + var request = WebRequest.Create(url + "/status" + "?auth=" + authtoken) as HttpWebRequest; + if (request != null) + { + request.Method = "GET"; + request.ContentType = "application/json"; + } + + var httpResponse = (HttpWebResponse)request.GetResponse(); + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); + + ZeroTierStatus status = JsonConvert.DeserializeObject(responseText); + return status; + } + } + + public List getNetworks() + { + var request = WebRequest.Create(url + "/network" + "?auth=" + authtoken) as HttpWebRequest; + if (request != null) + { + request.Method = "GET"; + request.ContentType = "application/json"; + } + + var httpResponse = (HttpWebResponse)request.GetResponse(); + using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) + { + var responseText = streamReader.ReadToEnd(); + Console.WriteLine(responseText); + + List networkList = JsonConvert.DeserializeObject>(responseText); + return networkList; + } + } + } +} diff --git a/windows/WinUI/MainWindow.xaml b/windows/WinUI/MainWindow.xaml index 299d3676e..52a76ebb1 100644 --- a/windows/WinUI/MainWindow.xaml +++ b/windows/WinUI/MainWindow.xaml @@ -1,7 +1,10 @@  @@ -84,10 +87,12 @@ - - - - + + + + + + diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs index 589910f79..8e2d7993b 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/MainWindow.xaml.cs @@ -20,9 +20,30 @@ namespace WinUI /// public partial class MainWindow : Window { + APIHandler handler = new APIHandler(); + public MainWindow() { InitializeComponent(); + + updateStatus(); + updateNetworks(); + } + + private void updateStatus() + { + var status = handler.getStatus(); + + this.networkId.Content = status.address; + this.versionString.Content = status.version; + this.onlineStatus.Content = (status.online ? "ONLINE" : "OFFLINE"); + } + + private void updateNetworks() + { + var networks = handler.getNetworks(); + + networksPage.setNetworks(networks); } } } diff --git a/windows/WinUI/NetworkInfoView.xaml b/windows/WinUI/NetworkInfoView.xaml index e81b6ff2e..1e090381d 100644 --- a/windows/WinUI/NetworkInfoView.xaml +++ b/windows/WinUI/NetworkInfoView.xaml @@ -1,55 +1,62 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +