From d4c5a422b96a87d8963ad8437f1829df821acdbf Mon Sep 17 00:00:00 2001 From: jaredbroad Date: Tue, 19 Apr 2016 18:41:48 -0400 Subject: [PATCH] Test fix with Mono Web Browser replacing Gecko --- Launcher/Program.cs | 9 +- QuantConnect.Lean.sln | 6 +- UserInterface/Browser.cs | 191 ++++++++++++++++++++++++ UserInterface/QuantConnect.Views.csproj | 19 +-- UserInterface/WinForms/LeanWinForm.cs | 113 ++++++++------ UserInterface/packages.config | 4 - 6 files changed, 269 insertions(+), 73 deletions(-) create mode 100644 UserInterface/Browser.cs diff --git a/Launcher/Program.cs b/Launcher/Program.cs index d2753274379f..e695e7f56a04 100644 --- a/Launcher/Program.cs +++ b/Launcher/Program.cs @@ -19,6 +19,7 @@ using System.Threading; using System.Windows.Forms; using QuantConnect.Configuration; +using QuantConnect.Interfaces; using QuantConnect.Lean.Engine; using QuantConnect.Logging; using QuantConnect.Packets; @@ -87,7 +88,8 @@ static void Main(string[] args) if (environment == "backtesting-desktop") { Application.EnableVisualStyles(); - var thread = new Thread(() => LaunchUX(leanEngineSystemHandlers, leanEngineAlgorithmHandlers, job)); + var messagingHandler = leanEngineSystemHandlers.Notify; + var thread = new Thread(() => LaunchUX(messagingHandler, job)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } @@ -138,10 +140,11 @@ static void Main(string[] args) /// /// Form launcher method for thread. /// - static void LaunchUX(LeanEngineSystemHandlers system, LeanEngineAlgorithmHandlers algorithm, AlgorithmNodePacket job) + static void LaunchUX(IMessagingHandler messaging, AlgorithmNodePacket job) { //Launch the UX - var form = new Views.WinForms.LeanWinForm(system, algorithm, job); + //var form = Composer.Instance.GetExportedValueByTypeName
("desktop-ux-classname"); + var form = new Views.WinForms.LeanWinForm(messaging, job); Application.Run(form); } } diff --git a/QuantConnect.Lean.sln b/QuantConnect.Lean.sln index 426dd9c442f3..58e3c13e7278 100644 --- a/QuantConnect.Lean.sln +++ b/QuantConnect.Lean.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuantConnect.Lean.Launcher", "Launcher\QuantConnect.Lean.Launcher.csproj", "{09E7B916-E58B-4021-BD8B-C10B4446E226}" EndProject @@ -86,7 +86,7 @@ Global {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.Release|Any CPU.Build.0 = Release|Any CPU {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.Release|x64.ActiveCfg = Release|x64 {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.Release|x64.Build.0 = Release|x64 - {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.TravisCI|Any CPU.ActiveCfg = TravisCI|x86 + {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.TravisCI|Any CPU.ActiveCfg = TravisCI|Any CPU {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.TravisCI|Any CPU.Build.0 = TravisCI|Any CPU {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.TravisCI|x64.ActiveCfg = TravisCI|x64 {12156F46-D07E-4E3D-AD2B-7409E82AB62F}.TravisCI|x64.Build.0 = TravisCI|x64 @@ -219,12 +219,14 @@ Global {C5D44209-49A0-4505-A870-043C5EF5FDDF}.TravisCI|x64.ActiveCfg = TravisCI|x64 {C5D44209-49A0-4505-A870-043C5EF5FDDF}.TravisCI|x64.Build.0 = TravisCI|x64 {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Debug|Any CPU.Build.0 = Debug|Any CPU {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Debug|x64.ActiveCfg = Debug|x64 {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Debug|x64.Build.0 = Debug|x64 {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Release|x64.ActiveCfg = Release|x64 {C68BEEED-B0C0-4002-94D4-1E871133D02A}.Release|x64.Build.0 = Release|x64 {C68BEEED-B0C0-4002-94D4-1E871133D02A}.TravisCI|Any CPU.ActiveCfg = TravisCI|Any CPU + {C68BEEED-B0C0-4002-94D4-1E871133D02A}.TravisCI|Any CPU.Build.0 = TravisCI|Any CPU {C68BEEED-B0C0-4002-94D4-1E871133D02A}.TravisCI|x64.ActiveCfg = TravisCI|x64 {7702711A-0C09-40D4-B151-E308D1520738}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7702711A-0C09-40D4-B151-E308D1520738}.Debug|Any CPU.Build.0 = Debug|Any CPU diff --git a/UserInterface/Browser.cs b/UserInterface/Browser.cs new file mode 100644 index 000000000000..d6ae973a9383 --- /dev/null +++ b/UserInterface/Browser.cs @@ -0,0 +1,191 @@ +/* + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. + * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +using System; +using System.IO; +using System.Security; +using Microsoft.Win32; + +namespace QuantConnect.Views +{ + public enum BrowserEmulationVersion + { + Default = 0, + Version7 = 7000, + Version8 = 8000, + Version8Standards = 8888, + Version9 = 9000, + Version9Standards = 9999, + Version10 = 10000, + Version10Standards = 10001, + Version11 = 11000, + Version11Edge = 11001 + } + + /// + /// Helper class for setting registry configuration for the web browser control + /// + public static class WBEmulator + { + private const string InternetExplorerRootKey = @"Software\Microsoft\Internet Explorer"; + private const string BrowserEmulationKey = InternetExplorerRootKey + @"\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; + + /// + /// Get the version of internet explorer from the registry + /// + /// int version of IE. + public static int GetInternetExplorerMajorVersion() + { + var result = 0; + try + { + var key = Registry.LocalMachine.OpenSubKey(InternetExplorerRootKey); + + if (key != null) + { + var value = key.GetValue("svcVersion", null) ?? key.GetValue("Version", null); + + if (value != null) + { + var version = value.ToString(); + var separator = version.IndexOf('.'); + if (separator != -1) + { + int.TryParse(version.Substring(0, separator), out result); + } + } + } + } + catch (SecurityException) + { + // The user does not have the permissions required to read from the registry key. + } + catch (UnauthorizedAccessException) + { + // The user does not have the necessary registry rights. + } + return result; + } + + + public static BrowserEmulationVersion GetBrowserEmulationVersion() + { + var result = BrowserEmulationVersion.Default; + try + { + var key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true); + if (key != null) + { + var programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]); + var value = key.GetValue(programName, null); + + if (value != null) + { + result = (BrowserEmulationVersion)Convert.ToInt32(value); + } + } + } + catch (SecurityException) + { + // The user does not have the permissions required to read from the registry key. + } + catch (UnauthorizedAccessException) + { + // The user does not have the necessary registry rights. + } + return result; + } + + /// + /// Set the browser's IE version in registry + /// + /// + /// + public static bool SetBrowserEmulationVersion(BrowserEmulationVersion browserEmulationVersion) + { + var result = false; + try + { + var key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, true); + if (key != null) + { + var programName = Path.GetFileName(Environment.GetCommandLineArgs()[0]); + if (browserEmulationVersion != BrowserEmulationVersion.Default) + { + // if it's a valid value, update or create the value + key.SetValue(programName, (int)browserEmulationVersion, RegistryValueKind.DWord); + } + else + { + // otherwise, remove the existing value + key.DeleteValue(programName, false); + } + + result = true; + } + } + catch (SecurityException) + { + // The user does not have the permissions required to read from the registry key. + } + catch (UnauthorizedAccessException) + { + // The user does not have the necessary registry rights. + } + return result; + } + + /// + /// Set the enumulation version for the web browser control + /// + public static bool SetBrowserEmulationVersion() + { + BrowserEmulationVersion emulationCode; + var ieVersion = GetInternetExplorerMajorVersion(); + + if (ieVersion >= 11) + { + emulationCode = BrowserEmulationVersion.Version11; + } + else + { + switch (ieVersion) + { + case 10: + emulationCode = BrowserEmulationVersion.Version10; + break; + case 9: + emulationCode = BrowserEmulationVersion.Version9; + break; + case 8: + emulationCode = BrowserEmulationVersion.Version8; + break; + default: + emulationCode = BrowserEmulationVersion.Version7; + break; + } + } + return SetBrowserEmulationVersion(emulationCode); + } + + /// + /// Helper to confirm if the browser + /// + /// Bool check if its set + public static bool IsBrowserEmulationSet() + { + return GetBrowserEmulationVersion() != BrowserEmulationVersion.Default; + } + } +} diff --git a/UserInterface/QuantConnect.Views.csproj b/UserInterface/QuantConnect.Views.csproj index b4d3d54b2d4a..4c580fba72cb 100644 --- a/UserInterface/QuantConnect.Views.csproj +++ b/UserInterface/QuantConnect.Views.csproj @@ -12,7 +12,8 @@ v4.5 512 5 - 17cd51ad + + true @@ -80,14 +81,6 @@ true - - ..\packages\GeckoFX.1.0.5\lib\Geckofx-Core.dll - True - - - ..\packages\GeckoFX.1.0.5\lib\Geckofx-Winforms.dll - True - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll True @@ -103,6 +96,7 @@ + True True @@ -206,13 +200,6 @@ - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - -