MainWindow.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Interop;
  6. using H.Formatters;
  7. using H.Pipes;
  8. using H.Pipes.Extensions;
  9. using InABox.Logikal;
  10. using Newtonsoft.Json;
  11. namespace PRSLogikal
  12. {
  13. /// <summary>
  14. /// Interaction logic for MainWindow.xaml
  15. /// </summary>
  16. public partial class MainWindow
  17. {
  18. private LogikalServer _logikal;
  19. private LogikalListener _listener;
  20. private void Log(string msg)
  21. {
  22. Dispatcher.BeginInvoke(new Func<object>(() => _Log.Text += $"{msg}\n"));
  23. }
  24. public MainWindow()
  25. {
  26. InitializeComponent();
  27. _logikal = new LogikalServer();
  28. _logikal.Log += (o, e) => Log(e.Message);
  29. _listener = new LogikalListener()
  30. {
  31. Server = _logikal
  32. };
  33. _listener.Disconnecting += (sender, args) => Dispatcher.Invoke(() => Close());
  34. _listener.Log += (o, e) => Log(e.Message);
  35. _listener.Start();
  36. }
  37. private void MainWindow_OnClosed(object sender, EventArgs e)
  38. {
  39. _listener.Stop();
  40. _logikal.Disconnect();
  41. }
  42. private void _connect_OnClick(object sender, RoutedEventArgs e)
  43. {
  44. if (_logikal.Connect(_path.Text) == LogikalStatus.Ok)
  45. {
  46. _connect.IsEnabled = false;
  47. _path.IsEnabled = false;
  48. _disconnect.IsEnabled = true;
  49. _login.IsEnabled = true;
  50. _userid.IsEnabled = true;
  51. _password.IsEnabled = true;
  52. _logout.IsEnabled = false;
  53. _projects.IsEnabled = false;
  54. }
  55. }
  56. private void _login_OnClick(object sender, RoutedEventArgs e)
  57. {
  58. if (_logikal.Login( new WindowInteropHelper(this).Handle /*_userid.Text, _password.Text */ ) == LogikalStatus.Ok)
  59. {
  60. _disconnect.IsEnabled = false;
  61. _login.IsEnabled = false;
  62. _userid.IsEnabled = false;
  63. _password.IsEnabled = false;
  64. _logout.IsEnabled = true;
  65. _projects.IsEnabled = true;
  66. }
  67. }
  68. private void _logout_OnClick(object sender, RoutedEventArgs e)
  69. {
  70. if (_logikal.Logout() == LogikalStatus.Ok)
  71. {
  72. _disconnect.IsEnabled = true;
  73. _login.IsEnabled = true;
  74. _userid.IsEnabled = true;
  75. _password.IsEnabled = true;
  76. _logout.IsEnabled = false;
  77. _projects.IsEnabled = false;
  78. }
  79. }
  80. private void _disconnect_OnClick(object sender, RoutedEventArgs e)
  81. {
  82. if (_logikal.Disconnect() == LogikalStatus.Ok)
  83. {
  84. _connect.IsEnabled = true;
  85. _path.IsEnabled = true;
  86. _disconnect.IsEnabled = false;
  87. _login.IsEnabled = false;
  88. _userid.IsEnabled = false;
  89. _password.IsEnabled = false;
  90. _projects.IsEnabled = false;
  91. }
  92. }
  93. private void _projects_OnClick(object sender, RoutedEventArgs e)
  94. {
  95. var projects = _logikal.GetProjects();
  96. foreach (var _project in projects)
  97. {
  98. Log($"Project: {_project.Name}: {_project.Path}");
  99. }
  100. }
  101. }
  102. }