diff --git a/doc/user/content/release_notes/_index.md b/doc/user/content/release_notes/_index.md index 71d637fd7..db2b50254 100644 --- a/doc/user/content/release_notes/_index.md +++ b/doc/user/content/release_notes/_index.md @@ -4,6 +4,12 @@ weight = 3 sort_by = "weight" insert_anchor_links = "right" +++ +## 1.5.8 +### User Visible Changes + - Fixed a bug where it was possible to crash the UI by entering an order through the order ticket if Enter was used to dismiss the dialog. + - Fixed a spreader reporting bug which could cause the server to crash if an algo was used to control certain types of synthetics + - Improved user message when the UI fails to login + - Integrated stunnel into UI to make VPN setup unnecessary in unsecured environments. ## 1.5.7 ### User Visible Changes - New videos have been added to the manual describing the [Algo Studio](./bts_spark/Trading/index.md#algo-studio) and [Spreader](./bts_spark/Spreader/index.md) diff --git a/src/client/spark/App.xaml.cs b/src/client/spark/App.xaml.cs index d19652c96..25aecff08 100644 --- a/src/client/spark/App.xaml.cs +++ b/src/client/spark/App.xaml.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Diagnostics; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -72,13 +74,50 @@ namespace mbts.ui.shell base.OnExit(e); Environment.Exit(0); } + + Process _stunnel_process; + static internal string stunnel_job_error { get; private set;} + void init_stunnel(string[] argv) + { + try + { + var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\BTS\\stunnel\\"; + if (File.Exists(path + "config\\stunnel.conf")) + { + uint job_error = BTSUINativeMethods.setup_process_job_object(); + if(job_error == 0) + { + _stunnel_process = Process.Start(path + "bin\\stunnel.exe"); + string config_error; bool success = false; + if(_stunnel_process != null) + { + for(int i = 0; i < 10; i++) + { + if(success = mbts.config.Configuration.try_initialize(out config_error)) + break; + System.Threading.Thread.Sleep(500); + } + } + else + stunnel_job_error = "Stunnel Job Error code: " + job_error + " could not start stunnel"; + } + else + stunnel_job_error = "Stunnel Job Error code: " + job_error; + } + } + catch(Exception ex) + { + stunnel_job_error = "Error starting stunnel: " + ex.Message; + } + } public new int Run() { var argv = Environment.GetCommandLineArgs(); - try { - if (argv.Contains("-multiple") || - _mutex == null || - _mutex.WaitOne(TimeSpan.Zero, true)) { + try { + if (argv.Contains("-multiple") || _mutex == null || _mutex.WaitOne(TimeSpan.Zero, true)) + { + if(_mutex == null || _mutex.WaitOne(TimeSpan.Zero, true)) + init_stunnel(argv); return base.Run(); } else { diff --git a/src/client/spark/core/NativeMethods/BTSNativeMethods.cs b/src/client/spark/core/NativeMethods/BTSNativeMethods.cs index 539f0d411..baa11754c 100644 --- a/src/client/spark/core/NativeMethods/BTSNativeMethods.cs +++ b/src/client/spark/core/NativeMethods/BTSNativeMethods.cs @@ -11,6 +11,9 @@ namespace mbts.ui.native [DllImport("libspark")] public static extern void enable_limits(); + [DllImport("libspark")] + public static extern uint setup_process_job_object(); + [DllImport("libspark", CharSet = CharSet.Unicode)] public static extern void set_window_app_id(IntPtr hwnd, string stack_id); } diff --git a/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs b/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs index 45ad9e0d8..e29b10a90 100644 --- a/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs +++ b/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs @@ -103,10 +103,8 @@ namespace mbts.ui { } static void tb_keydown(object sender, KeyEventArgs e) { - if (e.Key == Key.Enter) { - var binding = BindingOperations.GetBindingExpression(sender as DependencyObject, TextBox.TextProperty); - binding.UpdateSource(); - } + if (e.Key == Key.Enter) + BindingOperations.GetBindingExpression(sender as DependencyObject, TextBox.TextProperty)?.UpdateSource(); } public static bool GetCommitOnEnter(DependencyObject obj) => (bool)obj.GetValue(CommitOnEnterProperty); diff --git a/src/client/spark/view/Shell/Login/LoginModel.cs b/src/client/spark/view/Shell/Login/LoginModel.cs index 20e770318..8f8095007 100644 --- a/src/client/spark/view/Shell/Login/LoginModel.cs +++ b/src/client/spark/view/Shell/Login/LoginModel.cs @@ -94,7 +94,7 @@ namespace mbts.ui.shell { Configuration.initialize(); } catch (ApplicationException e) { - ErrorMessage = e.Message; + ErrorMessage = (e.Message ?? string.Empty) + " " + (App.stunnel_job_error ?? string.Empty); HasFatalError = true; return; } @@ -106,7 +106,13 @@ namespace mbts.ui.shell { var auth = _ctx.locate(); var response = await auth.get_users_async(new GetUsersRequest()); if (response.success) { - Users = response.value.Users.Select(x => new User(x.Login,x.Id)).OrderBy(u => u.name).ToArray(); + if (!string.IsNullOrEmpty(response.value.Error)) { + ErrorMessage = response.value.Error; + HasFatalError = true; + } + else { + Users = response.value.Users.Select(x => new User(x.Login,x.Id)).OrderBy(u => u.name).ToArray(); + } } else { ErrorMessage = "Logon: " + response.error_message; diff --git a/src/client/spark_core/config/config.cs b/src/client/spark_core/config/config.cs index 287097bdd..abf97b268 100644 --- a/src/client/spark_core/config/config.cs +++ b/src/client/spark_core/config/config.cs @@ -51,6 +51,12 @@ namespace mbts.config reset(); initialize(); } + + public static bool try_initialize(out string error) + { + reset(); + return initialize(out error); + } //////////// /// private diff --git a/src/lib/os/os.cpp b/src/lib/os/os.cpp index d16966dcd..3c8560047 100755 --- a/src/lib/os/os.cpp +++ b/src/lib/os/os.cpp @@ -1000,6 +1000,31 @@ extern "C" BTS_EXPORT char *bts_data_path() { } extern "C" BTS_EXPORT void free_bts_data_path(char *dp) { delete[] dp; } + +extern "C" BTS_EXPORT unsigned int setup_process_job_object() +{ +#ifdef _WIN32 + if (IsDebuggerPresent()) + return 0; + HANDLE hjob = CreateJobObject(nullptr, nullptr); + if (hjob == nullptr) + return 100; //Failed to create JOB object. + + JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = {0}; + jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + + BOOL success = SetInformationJobObject(hjob, JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)); + DWORD error = GetLastError(); + if(!success) + return error; + success = AssignProcessToJobObject(hjob, GetCurrentProcess()); + error = GetLastError(); + if(!success) + return error; +#endif + return 0; +} + } } } // end namespaces