Skip to content

Commit

Permalink
Test fix with Mono Web Browser replacing Gecko
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredbroad committed Apr 19, 2016
1 parent e93006b commit d4c5a42
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 73 deletions.
9 changes: 6 additions & 3 deletions Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -138,10 +140,11 @@ static void Main(string[] args)
/// <summary>
/// Form launcher method for thread.
/// </summary>
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<Form>("desktop-ux-classname");
var form = new Views.WinForms.LeanWinForm(messaging, job);
Application.Run(form);
}
}
Expand Down
6 changes: 4 additions & 2 deletions QuantConnect.Lean.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
191 changes: 191 additions & 0 deletions UserInterface/Browser.cs
Original file line number Diff line number Diff line change
@@ -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
}

/// <summary>
/// Helper class for setting registry configuration for the web browser control
/// </summary>
public static class WBEmulator
{
private const string InternetExplorerRootKey = @"Software\Microsoft\Internet Explorer";
private const string BrowserEmulationKey = InternetExplorerRootKey + @"\Main\FeatureControl\FEATURE_BROWSER_EMULATION";

/// <summary>
/// Get the version of internet explorer from the registry
/// </summary>
/// <returns>int version of IE.</returns>
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;
}

/// <summary>
/// Set the browser's IE version in registry
/// </summary>
/// <param name="browserEmulationVersion"></param>
/// <returns></returns>
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;
}

/// <summary>
/// Set the enumulation version for the web browser control
/// </summary>
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);
}

/// <summary>
/// Helper to confirm if the browser
/// </summary>
/// <returns>Bool check if its set</returns>
public static bool IsBrowserEmulationSet()
{
return GetBrowserEmulationVersion() != BrowserEmulationVersion.Default;
}
}
}
19 changes: 3 additions & 16 deletions UserInterface/QuantConnect.Views.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>5</LangVersion>
<NuGetPackageImportStamp>17cd51ad</NuGetPackageImportStamp>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -80,14 +81,6 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Geckofx-Core">
<HintPath>..\packages\GeckoFX.1.0.5\lib\Geckofx-Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Geckofx-Winforms">
<HintPath>..\packages\GeckoFX.1.0.5\lib\Geckofx-Winforms.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand All @@ -103,6 +96,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Browser.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -206,13 +200,6 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets'))" />
</Target>
<Import Project="..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets" Condition="Exists('..\packages\Baseclass.Contrib.Nuget.Output.2.1.0\build\net40\Baseclass.Contrib.Nuget.Output.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Loading

0 comments on commit d4c5a42

Please sign in to comment.