Skip to content

Commit

Permalink
Merged PR 352: V3.1.9 Beta 9
Browse files Browse the repository at this point in the history
* Ensure that System.ValueTuple.dll gets deployed
* #59 - Double bond disappears when drawn vertically in the editor
* #65 - 1.5 bond is too dense
* #64 - Anticlockwise double bond drawing issue
* #23 - Variable ring mode does not indicate ring size on first drawing
* Improvements to EvaluateChemistryAllowed function
* Fix bug in MOLFile export of wavy (indeterminate) bond

Related work items: #71, #307, #686, #710, #717
  • Loading branch information
MikeWilliams-UK committed May 14, 2020
1 parent 82ebc92 commit b9fe955
Show file tree
Hide file tree
Showing 84 changed files with 2,236 additions and 38,805 deletions.
71 changes: 0 additions & 71 deletions src/Chem4Word.V3/AssemblyReflectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,6 @@

namespace Chem4Word
{
public class AssemblyReflectionProxy : MarshalByRefObject
{
private string _assemblyPath;

public void LoadAssembly(String assemblyPath)
{
try
{
_assemblyPath = assemblyPath;
Assembly.ReflectionOnlyLoadFrom(assemblyPath);
}
catch (FileNotFoundException)
{
// Continue loading assemblies even if an assembly can not be loaded in the new AppDomain.
}
}

public TResult Reflect<TResult>(Func<Assembly, TResult> func)
{
DirectoryInfo directory = new FileInfo(_assemblyPath).Directory;

// Extract filename as files will be loaded from a random dl3 cache location.
FileInfo fileInfo = new FileInfo(_assemblyPath);
string fileName = fileInfo.Name;

ResolveEventHandler resolveEventHandler =
(s, e) =>
{
return OnReflectionOnlyResolve(
e, directory);
};

AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += resolveEventHandler;

var assembly = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies().FirstOrDefault(a => a.Location.EndsWith(fileName));

var result = func(assembly);

AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= resolveEventHandler;

return result;
}

private Assembly OnReflectionOnlyResolve(ResolveEventArgs args, DirectoryInfo directory)
{
Assembly loadedAssembly =
AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()
.FirstOrDefault(
asm => string.Equals(asm.FullName, args.Name,
StringComparison.OrdinalIgnoreCase));

if (loadedAssembly != null)
{
return loadedAssembly;
}

AssemblyName assemblyName =
new AssemblyName(args.Name);
string dependentAssemblyFilename =
Path.Combine(directory.FullName,
assemblyName.Name + ".dll");

if (File.Exists(dependentAssemblyFilename))
{
return Assembly.ReflectionOnlyLoadFrom(
dependentAssemblyFilename);
}
return Assembly.ReflectionOnlyLoad(args.Name);
}
}

public class AssemblyReflectionManager : IDisposable
{
private Dictionary<string, AppDomain> _mapDomains = new Dictionary<string, AppDomain>();
Expand Down
81 changes: 81 additions & 0 deletions src/Chem4Word.V3/AssemblyReflectionProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// ---------------------------------------------------------------------------
// Copyright (c) 2020, The .NET Foundation.
// This software is released under the Apache License, Version 2.0.
// The license and further copyright text can be found in the file LICENSE.md
// at the root directory of the distribution.
// ---------------------------------------------------------------------------

using System;
using System.IO;
using System.Linq;
using System.Reflection;

namespace Chem4Word
{
public class AssemblyReflectionProxy : MarshalByRefObject
{
private string _assemblyPath;

public void LoadAssembly(String assemblyPath)
{
try
{
_assemblyPath = assemblyPath;
Assembly.ReflectionOnlyLoadFrom(assemblyPath);
}
catch (FileNotFoundException)
{
// Continue loading assemblies even if an assembly can not be loaded in the new AppDomain.
}
}

public TResult Reflect<TResult>(Func<Assembly, TResult> func)
{
DirectoryInfo directory = new FileInfo(_assemblyPath).Directory;

// Extract filename as files will be loaded from a random dl3 cache location.
FileInfo fileInfo = new FileInfo(_assemblyPath);
string fileName = fileInfo.Name;

ResolveEventHandler resolveEventHandler = (s, e) =>
{
return OnReflectionOnlyResolve(e, directory);
};

AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += resolveEventHandler;

var assembly = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies().FirstOrDefault(a => a.Location.EndsWith(fileName));

var result = func(assembly);

AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= resolveEventHandler;

return result;
}

private Assembly OnReflectionOnlyResolve(ResolveEventArgs args, DirectoryInfo directory)
{
Assembly loadedAssembly =
AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies()
.FirstOrDefault(
asm => string.Equals(asm.FullName, args.Name,
StringComparison.OrdinalIgnoreCase));

if (loadedAssembly != null)
{
return loadedAssembly;
}

AssemblyName assemblyName = new AssemblyName(args.Name);
string dependentAssemblyFilename = Path.Combine(directory.FullName, assemblyName.Name + ".dll");

if (File.Exists(dependentAssemblyFilename))
{
return Assembly.ReflectionOnlyLoadFrom(
dependentAssemblyFilename);
}

return Assembly.ReflectionOnlyLoad(args.Name);
}
}
}
1 change: 1 addition & 0 deletions src/Chem4Word.V3/Chem4Word.V3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<Link>Helpers\FolderHelper.cs</Link>
</Compile>
<Compile Include="AssemblyReflectionManager.cs" />
<Compile Include="AssemblyReflectionProxy.cs" />
<Compile Include="Database\ChemistryDTO.cs" />
<Compile Include="Database\ChemistryTagDTO.cs" />
<Compile Include="Database\Library.cs" />
Expand Down
Loading

0 comments on commit b9fe955

Please sign in to comment.