From ab602c7fdf4be21106bcdb36a3b2b6d5b66cba6a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 6 Nov 2024 19:31:20 +0000 Subject: [PATCH 1/4] follow pattern from receive for async --- .../Operations/Send/RevitRootObjectBuilder.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs b/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs index b519628d5..74a22f8b3 100644 --- a/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs +++ b/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs @@ -56,9 +56,18 @@ public async Task Build( SendInfo sendInfo, IProgress onOperationProgressed, CancellationToken ct = default + ) => + await RevitTask.RunAsync(() => BuildSync(objects, sendInfo, onOperationProgressed, ct)).ConfigureAwait(false); + + private RootObjectBuilderResult BuildSync( + IReadOnlyList objects, + SendInfo sendInfo, + IProgress onOperationProgressed, + CancellationToken ct = default ) { - var doc = _converterSettings.Current.Document; + + var doc = _converterSettings.Current.Document; if (doc.IsFamilyDocument) { @@ -110,7 +119,7 @@ public async Task Build( } else { - converted = await RevitTask.RunAsync(() => _converter.Convert(revitElement)).ConfigureAwait(false); // Could we run these batched? Is there maybe a performance penalty for running these to speckle conversions individually in revittask.runasync? + converted = _converter.Convert(revitElement); converted.applicationId = applicationId; } From 309f9679dc5688f78509d968ac65afbcb1cdb61a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 6 Nov 2024 19:31:46 +0000 Subject: [PATCH 2/4] category can be null --- .../ToSpeckle/Raw/MaterialQuantitiesToSpeckle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/MaterialQuantitiesToSpeckle.cs b/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/MaterialQuantitiesToSpeckle.cs index 04cf03bb3..421fd7d14 100644 --- a/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/MaterialQuantitiesToSpeckle.cs +++ b/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Raw/MaterialQuantitiesToSpeckle.cs @@ -31,7 +31,7 @@ IConverterSettingsStore converterSettings public Dictionary Convert(DB.Element target) { Dictionary quantities = new(); - if (target.Category.HasMaterialQuantities) + if (target.Category?.HasMaterialQuantities ?? false) //category can be null { foreach (DB.ElementId matId in target.GetMaterialIds(false)) { From d57b13953e06c026f1ccab0770243a1b40727e07 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 6 Nov 2024 19:08:10 +0000 Subject: [PATCH 3/4] optimization for try get --- .../ToSpeckle/Parameters/ParameterDefinitionHandler.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Parameters/ParameterDefinitionHandler.cs b/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Parameters/ParameterDefinitionHandler.cs index 19eacbace..c399c025b 100644 --- a/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Parameters/ParameterDefinitionHandler.cs +++ b/Converters/Revit/Speckle.Converters.RevitShared/ToSpeckle/Parameters/ParameterDefinitionHandler.cs @@ -37,11 +37,8 @@ definition is DB.InternalDefinition internalDefinition internalDefinitionName = internalDefinition.BuiltInParameter.ToString(); } -#pragma warning disable CA1854 // swapping leads to nullability errors; should be resolved once we type this more strongly. - if (Definitions.ContainsKey(internalDefinitionName)) -#pragma warning restore CA1854 + if (Definitions.TryGetValue(internalDefinitionName, out var def)) { - var def = Definitions[internalDefinitionName]; return ( internalDefinitionName, humanReadableName, From a81dfd6f62031480cc65f0a1dd6fcda65966132b Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 6 Nov 2024 19:39:37 +0000 Subject: [PATCH 4/4] fmt --- .../Operations/Send/RevitRootObjectBuilder.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs b/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs index 74a22f8b3..7c1be7b8c 100644 --- a/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs +++ b/Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs @@ -56,8 +56,7 @@ public async Task Build( SendInfo sendInfo, IProgress onOperationProgressed, CancellationToken ct = default - ) => - await RevitTask.RunAsync(() => BuildSync(objects, sendInfo, onOperationProgressed, ct)).ConfigureAwait(false); + ) => await RevitTask.RunAsync(() => BuildSync(objects, sendInfo, onOperationProgressed, ct)).ConfigureAwait(false); private RootObjectBuilderResult BuildSync( IReadOnlyList objects, @@ -66,8 +65,7 @@ private RootObjectBuilderResult BuildSync( CancellationToken ct = default ) { - - var doc = _converterSettings.Current.Document; + var doc = _converterSettings.Current.Document; if (doc.IsFamilyDocument) {