Skip to content

Commit

Permalink
Merge branch 'dui3/alpha' into jrm/non-controversial-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan authored Jun 17, 2024
2 parents f1e1737 + d2afa7a commit ae936df
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ArcGISConverterModule : ISpeckleModule
public void Load(SpeckleContainerBuilder builder)
{
//don't need a host specific RootToSpeckleConverter
builder.AddConverterCommon<RootToSpeckleConverter, ArcGISToSpeckleUnitConverter, Unit>();
builder.AddConverterCommon<LegacyRootToSpeckleConverter, ArcGISToSpeckleUnitConverter, Unit>();
// most things should be InstancePerLifetimeScope so we get one per operation
builder.AddScoped<IFeatureClassUtils, FeatureClassUtils>();
builder.AddScoped<IArcGISFieldUtils, ArcGISFieldUtils>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class RhinoConverterModule : ISpeckleModule
{
public void Load(SpeckleContainerBuilder builder)
{
builder.AddConverterCommon<RootToSpeckleConverter, RhinoToSpeckleUnitConverter, UnitSystem>();
builder.AddConverterCommon<LegacyRootToSpeckleConverter, RhinoToSpeckleUnitConverter, UnitSystem>();
// single stack per conversion
builder.AddScoped<IConversionContextStack<RhinoDoc, UnitSystem>, RhinoConversionContextStack>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Speckle.Autofac.DependencyInjection;
using Speckle.Converters.Common.Objects;
using Speckle.Core.Models;

namespace Speckle.Converters.Common;

public class LegacyRootToSpeckleConverter : IRootToSpeckleConverter
{
private readonly IFactory<IToSpeckleTopLevelConverter> _toSpeckle;

public LegacyRootToSpeckleConverter(IFactory<IToSpeckleTopLevelConverter> toSpeckle)
{
_toSpeckle = toSpeckle;
}

public Base Convert(object target)
{
Type type = target.GetType();
try
{
var objectConverter = _toSpeckle.ResolveInstance(type.Name); //poc: would be nice to have supertypes resolve

if (objectConverter == null)
{
throw new NotSupportedException($"No conversion found for {type.Name}");
}
var convertedObject = objectConverter.Convert(target);

return convertedObject;
}
catch (SpeckleConversionException e)
{
Console.WriteLine(e);
throw; // Just rethrowing for now, Logs may be needed here.
}
}
}

0 comments on commit ae936df

Please sign in to comment.