using System; using System.Diagnostics; using System.Linq; using System.Windows; using System.Windows.Interop; using H.Formatters; using H.Pipes; using H.Pipes.Extensions; using InABox.Logikal; using Newtonsoft.Json; namespace PRSLogikal { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow { private LogikalServer _logikal; private LogikalListener _listener; private void Log(string msg) { Dispatcher.BeginInvoke(new Func(() => _Log.Text += $"{msg}\n")); } public MainWindow() { InitializeComponent(); _logikal = new LogikalServer(); _logikal.Log += (o, e) => Log(e.Message); _listener = new LogikalListener() { Server = _logikal }; _listener.Disconnecting += (sender, args) => Dispatcher.Invoke(() => Close()); _listener.Log += (o, e) => Log(e.Message); _listener.Start(); } private void MainWindow_OnClosed(object sender, EventArgs e) { _listener.Stop(); _logikal.Disconnect(); } private void _connect_OnClick(object sender, RoutedEventArgs e) { if (_logikal.Connect(_path.Text) == LogikalStatus.Ok) { _connect.IsEnabled = false; _path.IsEnabled = false; _disconnect.IsEnabled = true; _login.IsEnabled = true; _userid.IsEnabled = true; _password.IsEnabled = true; _logout.IsEnabled = false; _projects.IsEnabled = false; } } private void _login_OnClick(object sender, RoutedEventArgs e) { if (_logikal.Login( new WindowInteropHelper(this).Handle /*_userid.Text, _password.Text */ ) == LogikalStatus.Ok) { _disconnect.IsEnabled = false; _login.IsEnabled = false; _userid.IsEnabled = false; _password.IsEnabled = false; _logout.IsEnabled = true; _projects.IsEnabled = true; } } private void _logout_OnClick(object sender, RoutedEventArgs e) { if (_logikal.Logout() == LogikalStatus.Ok) { _disconnect.IsEnabled = true; _login.IsEnabled = true; _userid.IsEnabled = true; _password.IsEnabled = true; _logout.IsEnabled = false; _projects.IsEnabled = false; } } private void _disconnect_OnClick(object sender, RoutedEventArgs e) { if (_logikal.Disconnect() == LogikalStatus.Ok) { _connect.IsEnabled = true; _path.IsEnabled = true; _disconnect.IsEnabled = false; _login.IsEnabled = false; _userid.IsEnabled = false; _password.IsEnabled = false; _projects.IsEnabled = false; } } private void _projects_OnClick(object sender, RoutedEventArgs e) { var projects = _logikal.GetProjects(); foreach (var _project in projects) { Log($"Project: {_project.Name}: {_project.Path}"); } } } }