Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Use the latest version of IE in WebBrowser control
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Feb 5, 2016
1 parent 4e62ceb commit 18495fe
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static string FormatTSql(this string tSql, string sqlHash)
return formattedTSql;
}

var sqlFragment = SqlFragmentProvider.GetSqlFragment(tSql, sqlHash);
var sqlFragment = SqlFragmentProvider.GetSqlFragment(tSql, sqlHash, readFromCache: false);
if (sqlFragment == null)
{
return tSql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public static class SqlFragmentProvider
private static readonly ConcurrentDictionary<string, TSqlScript> _sqlFragments =
new ConcurrentDictionary<string, TSqlScript>();

public static TSqlScript GetSqlFragment(string tSql, string sqlHash, int timeoutSeconds = 7)
public static TSqlScript GetSqlFragment(string tSql, string sqlHash, int timeoutSeconds = 7, bool readFromCache = true)
{
var runner = TimedRunner.RunWithTimeout(() =>
{
try
{
return getSqlFragment(tSql, sqlHash);
return getSqlFragment(tSql, sqlHash, readFromCache);
}
catch (Exception ex)
{
Expand All @@ -42,10 +42,10 @@ public static TSqlScript GetSqlFragment(string tSql, string sqlHash, int timeout
return runner.Result;
}

private static TSqlScript getSqlFragment(string tSql, string sqlHash)
private static TSqlScript getSqlFragment(string tSql, string sqlHash, bool readFromCache)
{
TSqlScript sqlFragment;
if (_sqlFragments.TryGetValue(sqlHash, out sqlFragment))
if (readFromCache && _sqlFragments.TryGetValue(sqlHash, out sqlFragment))
{
return sqlFragment;
}
Expand All @@ -59,7 +59,10 @@ private static TSqlScript getSqlFragment(string tSql, string sqlHash)

if (errors == null || !errors.Any())
{
_sqlFragments.TryAdd(sqlHash, sqlFragment);
if (!readFromCache)
{
_sqlFragments.TryAdd(sqlHash, sqlFragment);
}
return sqlFragment;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Diagnostics;
using Microsoft.Win32;
using System.Windows.Forms;
using DNTProfiler.Common.Logger;
using DNTProfiler.Common.Mvvm;

namespace DNTProfiler.ApplicationAnnouncements.Core
{
public static class UseLatestVersionOfIE
{
/// <summary>
/// Use the latest version of IE in WebBrowser control
/// </summary>
public static void SetWebBrowserVersion()
{
RegistryKey regkey = null;
try
{
regkey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", writable: true);
if (regkey == null)
{
return;
}

var regVal = getInstalledIEVersion();
var appName = string.Format("{0}.exe", Process.GetCurrentProcess().ProcessName);
regkey.SetValue(appName, regVal, RegistryValueKind.DWord);
}
catch (Exception ex)
{
new ExceptionLogger().LogExceptionToFile(ex, AppMessenger.LogFile);
AppMessenger.Messenger.NotifyColleagues("ShowException", ex);
}
finally
{
if (regkey != null)
{
regkey.Close();
}
}
}

private static int getInstalledIEVersion()
{
int browserVer;
using (var wb = new WebBrowser())
{
browserVer = wb.Version.Major;
}

int regVal;
if (browserVer >= 11)
regVal = 11001;
else
switch (browserVer)
{
case 10:
regVal = 10001;
break;
case 9:
regVal = 9999;
break;
case 8:
regVal = 8888;
break;
default:
regVal = 7000;
break;
}
return regVal;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand All @@ -54,6 +55,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationAnnouncementsPlugin.cs" />
<Compile Include="Core\UseLatestVersionOfIE.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Page Include="Main.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
10 changes: 5 additions & 5 deletions Plugins/DNTProfiler.ApplicationAnnouncements/Main.xaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<UserControl x:Class="DNTProfiler.ApplicationAnnouncements.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:converters="clr-namespace:DNTProfiler.Common.Converters;assembly=DNTProfiler.Common"
xmlns:behaviors="clr-namespace:DNTProfiler.Common.Behaviors;assembly=DNTProfiler.Common"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
mc:Ignorable="d"
d:DesignHeight="1300" d:DesignWidth="1300">
<UserControl.Resources>
<converters:FormatSizeConverter x:Key="FormatSizeConverter"/>
</UserControl.Resources>
<Grid x:Name="ThisGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="570"/>
<RowDefinition Height="400"/>
</Grid.RowDefinitions>
<ListView
Grid.Row="0"
ItemsSource="{Binding ThisGuiModelData.ReleaseInfo}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
SelectedItem="{Binding ThisGuiModelData.SelectedRelease}" MinHeight="200"
SelectedItem="{Binding ThisGuiModelData.SelectedRelease}" MinHeight="100"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="True"
VirtualizingStackPanel.IsVirtualizing="True"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DNTProfiler.ApplicationAnnouncements.Core;
using DNTProfiler.ApplicationAnnouncements.Models;
using DNTProfiler.Common.Mvvm;
Expand Down Expand Up @@ -47,6 +49,11 @@ private void setActions()
}
return stringBuilder.ToString();
};

Task.Factory.StartNew(() => UseLatestVersionOfIE.SetWebBrowserVersion()
, CancellationToken.None
, TaskCreationOptions.None
, TaskScheduler.FromCurrentSynchronizationContext());
}
}
}

0 comments on commit 18495fe

Please sign in to comment.