Skip to content

Commit 897b1fd

Browse files
committed
Version 0.9.3.0
1 parent 8fc1793 commit 897b1fd

File tree

19 files changed

+274
-322
lines changed

19 files changed

+274
-322
lines changed
Binary file not shown.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
namespace JavaScriptEngineSwitcher.V8
2+
{
3+
using System;
4+
using System.IO;
5+
using System.Reflection;
6+
using System.Web;
7+
8+
using Resources;
9+
10+
/// <summary>
11+
/// Assembly resolver
12+
/// </summary>
13+
internal static class AssemblyResolver
14+
{
15+
/// <summary>
16+
/// Name of directory, that contains the Noesis Javascript .NET assemblies
17+
/// </summary>
18+
private const string ASSEMBLY_DIRECTORY_NAME = "Noesis.Javascript";
19+
20+
/// <summary>
21+
/// Name of the Noesis Javascript .NET assembly
22+
/// </summary>
23+
private const string ASSEMBLY_NAME = "Noesis.Javascript";
24+
25+
26+
/// <summary>
27+
/// Initialize a assembly resolver
28+
/// </summary>
29+
public static void Initialize()
30+
{
31+
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolveHandler;
32+
}
33+
34+
private static Assembly AssemblyResolveHandler(object sender, ResolveEventArgs args)
35+
{
36+
if (args.Name.StartsWith(ASSEMBLY_NAME, StringComparison.OrdinalIgnoreCase))
37+
{
38+
var currentDomain = (AppDomain)sender;
39+
string platform = Environment.Is64BitProcess ? "x64" : "x86";
40+
41+
string binDirectoryPath = currentDomain.SetupInformation.PrivateBinPath;
42+
if (string.IsNullOrEmpty(binDirectoryPath))
43+
{
44+
// `PrivateBinPath` property is empty in test scenarios, so
45+
// need to use the `BaseDirectory` property
46+
binDirectoryPath = currentDomain.BaseDirectory;
47+
}
48+
49+
string assemblyDirectoryPath = Path.Combine(binDirectoryPath, ASSEMBLY_DIRECTORY_NAME);
50+
string assemblyFileName = string.Format("{0}.{1}.dll", ASSEMBLY_NAME, platform);
51+
string assemblyFilePath = Path.Combine(assemblyDirectoryPath, assemblyFileName);
52+
53+
if (!Directory.Exists(assemblyDirectoryPath))
54+
{
55+
if (HttpContext.Current != null)
56+
{
57+
// Fix for WebMatrix
58+
string applicationRootPath = HttpContext.Current.Server.MapPath("~");
59+
assemblyDirectoryPath = Path.Combine(applicationRootPath, ASSEMBLY_DIRECTORY_NAME);
60+
61+
if (!Directory.Exists(assemblyDirectoryPath))
62+
{
63+
throw new DirectoryNotFoundException(
64+
string.Format(Strings.Engines_NoesisJavascriptAssembliesDirectoryNotFound, assemblyDirectoryPath));
65+
}
66+
67+
assemblyFilePath = Path.Combine(assemblyDirectoryPath, assemblyFileName);
68+
}
69+
else
70+
{
71+
throw new DirectoryNotFoundException(
72+
string.Format(Strings.Engines_NoesisJavascriptAssembliesDirectoryNotFound, assemblyDirectoryPath));
73+
}
74+
}
75+
76+
if (!File.Exists(assemblyFilePath))
77+
{
78+
throw new FileNotFoundException(
79+
string.Format(Strings.Engines_NoesisJavascriptAssemblyFileNotFound, assemblyFilePath));
80+
}
81+
82+
return Assembly.LoadFile(assemblyFilePath);
83+
}
84+
85+
return null;
86+
}
87+
}
88+
}

JavaScriptEngineSwitcher.V8/Configuration/V8Configuration.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

JavaScriptEngineSwitcher.V8/JavaScriptEngineSwitcher.V8.csproj

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@
3636
<AssemblyOriginatorKeyFile>..\JavaScriptEngineSwitcher.snk</AssemblyOriginatorKeyFile>
3737
</PropertyGroup>
3838
<ItemGroup>
39+
<Reference Include="Noesis.Javascript">
40+
<HintPath>..\Binaries\Noesis.Javascript\x86\Noesis.Javascript.dll</HintPath>
41+
</Reference>
3942
<Reference Include="System" />
4043
<Reference Include="System.configuration" />
4144
<Reference Include="System.Core" />
45+
<Reference Include="System.Web" />
4246
<Reference Include="System.Web.Extensions" />
4347
<Reference Include="System.Xml.Linq" />
4448
<Reference Include="System.Data.DataSetExtensions" />
@@ -47,8 +51,7 @@
4751
<Reference Include="System.Xml" />
4852
</ItemGroup>
4953
<ItemGroup>
50-
<Compile Include="Configuration\V8Configuration.cs" />
51-
<Compile Include="JsEngineSwitcherExtensions.cs" />
54+
<Compile Include="AssemblyResolver.cs" />
5255
<Compile Include="Properties\AssemblyInfo.cs" />
5356
<Compile Include="Resources\Strings.Designer.cs">
5457
<AutoGen>True</AutoGen>
@@ -68,10 +71,6 @@
6871
<Name>JavaScriptEngineSwitcher.Core</Name>
6972
</ProjectReference>
7073
</ItemGroup>
71-
<ItemGroup>
72-
<Content Include="Noesis.Javascript\x64\Noesis.Javascript.dll" />
73-
<Content Include="Noesis.Javascript\x86\Noesis.Javascript.dll" />
74-
</ItemGroup>
7574
<ItemGroup>
7675
<None Include="..\JavaScriptEngineSwitcher.snk">
7776
<Link>JavaScriptEngineSwitcher.snk</Link>
@@ -87,7 +86,30 @@
8786
<LastGenOutput>Strings.ru-ru.Designer.cs</LastGenOutput>
8887
</EmbeddedResource>
8988
</ItemGroup>
89+
<ItemGroup />
90+
<ItemGroup>
91+
<None Include="..\Binaries\Noesis.Javascript\Output\Noesis.Javascript.x64.dll">
92+
<Link>Noesis.Javascript\Noesis.Javascript.x64.dll</Link>
93+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
94+
</None>
95+
<None Include="..\Binaries\Noesis.Javascript\Output\Noesis.Javascript.x86.dll">
96+
<Link>Noesis.Javascript\Noesis.Javascript.x86.dll</Link>
97+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
98+
</None>
99+
</ItemGroup>
90100
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
101+
<PropertyGroup>
102+
<PostBuildEvent>del "Noesis.JavaScript.dll"
103+
104+
cd "$(ProjectDir)..\Binaries\Noesis.Javascript\"
105+
106+
set outputDirectoryPath=Output
107+
if exist %25outputDirectoryPath%25 rmdir /s /q %25outputDirectoryPath%25
108+
mkdir %25outputDirectoryPath%25
109+
110+
copy /y "x86\Noesis.Javascript.dll" "%25outputDirectoryPath%25\Noesis.Javascript.x86.dll"
111+
copy /y "x64\Noesis.Javascript.dll" "%25outputDirectoryPath%25\Noesis.Javascript.x64.dll"</PostBuildEvent>
112+
</PropertyGroup>
91113
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
92114
Other similar extension points exist, see Microsoft.Common.targets.
93115
<Target Name="BeforeBuild">

JavaScriptEngineSwitcher.V8/JsEngineSwitcherExtensions.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.
Binary file not shown.

JavaScriptEngineSwitcher.V8/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
[assembly: ComVisible(false)]
1414
[assembly: Guid("684edd94-43fe-4486-a4f3-6b9197d10ebf")]
1515

16-
[assembly: AssemblyVersion("0.9.2.0")]
17-
[assembly: AssemblyFileVersion("0.9.2.0")]
16+
[assembly: AssemblyVersion("0.9.3.0")]
17+
[assembly: AssemblyFileVersion("0.9.3.0")]

JavaScriptEngineSwitcher.V8/Resources/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaScriptEngineSwitcher.V8/Resources/Strings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="Engines_NoesisJavascriptAssembliesDirectoryNotFound" xml:space="preserve">
121-
<value>The specified directory '{0}', that contains the Noesis Javascript .NET assemblies, is not found.</value>
121+
<value>Failed to load the Noesis Javascript .NET assembly, because the directory '{0}' does not exist.</value>
122+
</data>
123+
<data name="Engines_NoesisJavascriptAssemblyFileNotFound" xml:space="preserve">
124+
<value>Failed to load the Noesis Javascript .NET assembly, because the file '{0}' does not exist.</value>
122125
</data>
123126
</root>

0 commit comments

Comments
 (0)