Skip to content

Commit

Permalink
Fix(Revit) : Use speckle newtonsoft instead of System.Text.Json for i…
Browse files Browse the repository at this point in the history
…n dll conflict management project (#3317)
  • Loading branch information
AlanRynne committed Apr 29, 2024
2 parents 607d327 + 9736d56 commit 612ff3f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.6.0" />
<PackageReference Include="Speckle.Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>

</Project>
16 changes: 14 additions & 2 deletions ConnectorCore/DllConflictManagement/DllConflictManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ public sealed class DllConflictManager
private readonly DllConflictManagmentOptionsLoader _optionsLoader;
private readonly DllConflictEventEmitter _eventEmitter;
private readonly string[] _assemblyPathFragmentsToIgnore;
private readonly string[] _exactAssemblyPathsToIgnore;

public ICollection<AssemblyConflictInfo> AllConflictInfo => _assemblyConflicts.Values;
public ICollection<AssemblyConflictInfoDto> AllConflictInfoAsDtos => _assemblyConflicts.Values.ToDtos().ToList();

public DllConflictManager(
DllConflictManagmentOptionsLoader optionsLoader,
DllConflictEventEmitter eventEmitter,
params string[] assemblyPathFragmentsToIgnore
string[]? assemblyPathFragmentsToIgnore = null,
string[]? exactAssemblyPathsToIgnore = null
)
{
_optionsLoader = optionsLoader;
_eventEmitter = eventEmitter;
_assemblyPathFragmentsToIgnore = assemblyPathFragmentsToIgnore;
_assemblyPathFragmentsToIgnore = assemblyPathFragmentsToIgnore ?? Array.Empty<string>();
_exactAssemblyPathsToIgnore = exactAssemblyPathsToIgnore ?? Array.Empty<string>();
}

/// <summary>
Expand Down Expand Up @@ -99,6 +103,14 @@ HashSet<string> visitedAssemblies

private bool ShouldSkipCheckingConflictBecauseOfAssemblyLocation(Assembly loadedAssembly)
{
foreach (var exactPath in _exactAssemblyPathsToIgnore)
{
if (Path.GetDirectoryName(loadedAssembly.Location) == exactPath)
{
return true;
}
}

foreach (var pathFragment in _assemblyPathFragmentsToIgnore)
{
if (loadedAssembly.Location.Contains(pathFragment))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Speckle.Newtonsoft.Json;

namespace Speckle.DllConflictManagement.Serialization;

public class SpeckleNewtonsoftSerializer : ISerializer
{
public string Serialize<T>(T obj) => JsonConvert.SerializeObject(obj);

public T Deserialize<T>(string serialized) =>
JsonConvert.DeserializeObject<T>(serialized)
?? throw new InvalidOperationException(
$"Unable to deserialize the provided JSON into an object of type {typeof(T)}"
);
}

This file was deleted.

14 changes: 12 additions & 2 deletions ConnectorRevit/ConnectorRevit/Entry/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class App : IExternalApplication
public static UIControlledApplication UICtrlApp { get; set; }

private bool _initialized;
private static readonly string[] s_assemblyPathFragmentsToIgnore = new string[]
{
"Microsoft.Net\\assembly\\GAC_MSIL\\"
};

public Result OnStartup(UIControlledApplication application)
{
Expand All @@ -44,13 +48,19 @@ public Result OnStartup(UIControlledApplication application)
UICtrlApp.ControlledApplication.DocumentOpening += ControlledApplication_DocumentOpening;

DllConflictEventEmitter eventEmitter = new();
ISerializer serializer = new SystemTextJsonSerializer();
ISerializer serializer = new SpeckleNewtonsoftSerializer();
AnalyticsWithoutDependencies analytics = new(eventEmitter, serializer, "Revit", GetRevitVersion());
eventEmitter.OnAction += analytics.TrackEvent;

DllConflictManagmentOptionsLoader optionsLoader = new(serializer, "Revit", GetRevitVersion());
// ignore dll conflicts when dll lives in GAC because they are noisy and not an issue (at least in revit)
DllConflictManager conflictManager = new(optionsLoader, eventEmitter, "Microsoft.Net\\assembly\\GAC_MSIL\\");
DllConflictManager conflictManager =
new(
optionsLoader,
eventEmitter,
s_assemblyPathFragmentsToIgnore,
new string[] { $"C:\\Program Files\\Autodesk\\Revit {GetRevitVersion()}" }
);
RevitDllConflictUserNotifier conflictNotifier = new(conflictManager, eventEmitter);

try
Expand Down

0 comments on commit 612ff3f

Please sign in to comment.