MainWindow.xaml.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace WinUI
  17. {
  18. /// <summary>
  19. /// Interaction logic for MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. APIHandler handler = new APIHandler();
  24. public MainWindow()
  25. {
  26. InitializeComponent();
  27. updateStatus();
  28. updateNetworks();
  29. }
  30. private void updateStatus()
  31. {
  32. var status = handler.GetStatus();
  33. this.networkId.Content = status.Address;
  34. this.versionString.Content = status.Version;
  35. this.onlineStatus.Content = (status.Online ? "ONLINE" : "OFFLINE");
  36. }
  37. private void updateNetworks()
  38. {
  39. var networks = handler.GetNetworks();
  40. networksPage.setNetworks(networks);
  41. }
  42. private void joinButton_Click(object sender, RoutedEventArgs e)
  43. {
  44. if (joinNetworkID.Text.Length < 16)
  45. {
  46. MessageBox.Show("Invalid Network ID");
  47. }
  48. else
  49. {
  50. handler.JoinNetwork(joinNetworkID.Text);
  51. }
  52. }
  53. private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
  54. {
  55. Regex regex = new Regex("[0-9a-fxA-FX]");
  56. e.Handled = !regex.IsMatch(e.Text);
  57. }
  58. }
  59. }