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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +