Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Dec 18, 2024
1 parent 01c5f8e commit ef609b6
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ CancellationToken cancellationToken
var result = _converter.Convert(obj);
if (!result.IsSuccess)
{
conversionResults.Add(new(Status.ERROR, obj, result.Message.NotNull()));
conversionResults.Add(new(Status.ERROR, obj, result.Message.NotNull()));
convertActivity?.SetStatus(SdkActivityStatusCode.Error);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ string projectId
}
else
{
var result = _rootToSpeckleConverter.Convert(rhinoObject);
var result = _rootToSpeckleConverter.Convert(rhinoObject);
if (result.IsSuccess)
{
converted = result.Base.NotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected RhinoObjectToSpeckleTopLevelConverter(ITypedConverter<TInRaw, TOutRaw>
// POC: IIndex would fix this as I would just request the type from `RhinoObject.Geometry` directly.
protected abstract TInRaw GetTypedGeometry(TTopLevelIn input);

public BaseResult Convert(object target)
public BaseResult Convert(object target)
{
var typedTarget = (TTopLevelIn)target;
var typedGeometry = GetTypedGeometry(typedTarget);
Expand All @@ -34,6 +34,6 @@ public BaseResult Convert(object target)
result["name"] = typedTarget.Attributes.Name;
}

return BaseResult.Success( result);
return BaseResult.Success(result);
}
}
8 changes: 2 additions & 6 deletions Sdk/Speckle.Connectors.Common/Conversion/ReportResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ public ReceiveConversionResult(
ResultType = resultType;
Error = FormatError(exception);
}

public ReceiveConversionResult(
Status status,
Base source,
string exception
)

public ReceiveConversionResult(Status status, Base source, string exception)
{
Status = status;
SourceId = source.id.NotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ string objectType

logger.Log(logLevel, ex, "Conversion of object {objectType} was not successful", objectType);
}

public static void LogSendConversionError<T>(
this ILogger<IRootObjectBuilder<T>> logger,
string objectType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ namespace Speckle.Converters.Common.Extensions;

public static class ToHostTopLevelConverterExtension
{
public static HostResult ConvertAndLog(this ConverterResult<IToHostTopLevelConverter> converter, Base target, ILogger logger)
public static HostResult ConvertAndLog(
this ConverterResult<IToHostTopLevelConverter> converter,
Base target,
ILogger logger
)
{
try
{
Expand Down Expand Up @@ -45,9 +49,12 @@ public static HostResult ConvertAndLog(this ConverterResult<IToHostTopLevelConve
converter.GetType()
);

return HostResult.NoConversion($"Conversion of object {target} using {converter} was not successful: " + ex.Message);
return HostResult.NoConversion(
$"Conversion of object {target} using {converter} was not successful: " + ex.Message
);
}
}

public static HostResult ConvertAndLog(this IToHostTopLevelConverter converter, Base target, ILogger logger)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Speckle.Converters.Common.Registration;


public class ConverterManager<T>(ConcurrentDictionary<string, Type> converterTypes, IServiceProvider serviceProvider)
: IConverterManager<T>
{
Expand All @@ -23,7 +22,10 @@ public ConverterResult<T> ResolveConverter(Type type, bool recursive = true)

if (currentType == null)
{
return new ConverterResult<T>(ConversionStatus.NoConverter, Message: $"No conversion found for {type.Name} or any of its base types");
return new ConverterResult<T>(
ConversionStatus.NoConverter,
Message: $"No conversion found for {type.Name} or any of its base types"
);
}
}
else if (converter is null)
Expand All @@ -32,7 +34,6 @@ public ConverterResult<T> ResolveConverter(Type type, bool recursive = true)
}
else
{

return new ConverterResult<T>(ConversionStatus.Success, converter);
}
}
Expand Down
19 changes: 14 additions & 5 deletions Sdk/Speckle.Converters.Common/Registration/IConversionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,33 @@ public enum ConversionStatus
NoConversion
}

public readonly record struct ConverterResult<T>(ConversionStatus ConversionStatus, T? Converter = default, string? Message = null) : IConversionResult
public readonly record struct ConverterResult<T>(
ConversionStatus ConversionStatus,
T? Converter = default,
string? Message = null
) : IConversionResult
{
public bool IsSuccess => ConversionStatus == ConversionStatus.Success;
}

public readonly record struct BaseResult(ConversionStatus ConversionStatus, Base? Base = null, string? Message = null) : IConversionResult
public readonly record struct BaseResult(ConversionStatus ConversionStatus, Base? Base = null, string? Message = null)
: IConversionResult
{
public bool IsSuccess => ConversionStatus == ConversionStatus.Success;

public static BaseResult Success(Base baseObject) => new(ConversionStatus.Success, baseObject);

public static BaseResult NoConverter(string? message) => new(ConversionStatus.NoConverter, Message: message);
}

public readonly record struct HostResult(ConversionStatus ConversionStatus, object? Host = null, string? Message = null) : IConversionResult
public readonly record struct HostResult(ConversionStatus ConversionStatus, object? Host = null, string? Message = null)
: IConversionResult
{
public bool IsSuccess => ConversionStatus == ConversionStatus.Success;

public static HostResult Success(object obj) => new(ConversionStatus.Success, obj);

public static HostResult NoConverter(string? message) => new(ConversionStatus.NoConverter, Message: message);

public static HostResult NoConversion(string? message) => new(ConversionStatus.NoConversion, Message: message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Speckle.Converters.Common.ToHost;


public sealed class ConverterWithFallback(ConverterWithoutFallback baseConverter, ILogger<ConverterWithFallback> logger)
: IRootToHostConverter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Speckle.Converters.Common.ToHost;

public sealed class ConverterWithoutFallback(
IConverterManager<IToHostTopLevelConverter> converterResolver,
ILogger<ConverterWithoutFallback> logger)
: IRootToHostConverter
ILogger<ConverterWithoutFallback> logger
) : IRootToHostConverter
{
private readonly ILogger _logger = logger;

Expand Down

0 comments on commit ef609b6

Please sign in to comment.