From 3142d73ae36e42e5155bb544b79fa6ef592b8f12 Mon Sep 17 00:00:00 2001 From: Martijn van Dijk Date: Wed, 8 Mar 2023 12:19:18 +0100 Subject: [PATCH] Cleanup warnings --- Directory.Build.props | 10 +++++----- SampleLibrary/SampleLibrary.csproj | 7 ++++--- SampleLibrary/SampleTest.cs | 26 +++++++++++------------- SampleLibrary/TestWithFixture.cs | 6 +++--- xUnitRevit/App.cs | 6 +++--- xUnitRevit/Command.cs | 4 +--- xUnitRevit/Configuration.cs | 2 +- xUnitRevit/Runner.cs | 14 +++++++------ xUnitRevitUtilsShared/xru.cs | 32 +++++++++++++++--------------- 9 files changed, 53 insertions(+), 54 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index cfd1aeb..fa41c70 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ https://github.com/Speckle-Next/xunit-Revit Speckle Speckle - xunit revit runner + xunit revit runner https://github.com/Speckle-Next/xunit-Revit/releases false readme.md @@ -18,10 +18,10 @@ $(AssemblyName) ($(TargetFramework)) 1.0.5 - xUnitRevitUtils - xUnitRevitUtils + xUnitRevitUtils + xUnitRevitUtils - + enable latest $(NoWarn);1591;1701;1702;1705;VSX1000;CS0109;CS0108;CS0618;CS0114;NU1603 @@ -35,7 +35,7 @@ - true + true false diff --git a/SampleLibrary/SampleLibrary.csproj b/SampleLibrary/SampleLibrary.csproj index 8c4618f..561dc08 100644 --- a/SampleLibrary/SampleLibrary.csproj +++ b/SampleLibrary/SampleLibrary.csproj @@ -73,9 +73,10 @@ - - 1.0.4 - + + {977e0b63-5706-4c2b-9c01-3c02d9ebe377} + xUnitRevitUtils2021 + \ No newline at end of file diff --git a/SampleLibrary/SampleTest.cs b/SampleLibrary/SampleTest.cs index ded38ab..5929b23 100644 --- a/SampleLibrary/SampleTest.cs +++ b/SampleLibrary/SampleTest.cs @@ -15,13 +15,13 @@ namespace SampleLibrary public void WallsHaveVolume() { var testModel = Utils.GetTestModel("walls.rvt"); - var doc = xru.OpenDoc(testModel); + using var doc = xru.OpenDoc(testModel); var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements(); foreach (var wall in walls) { - var volumeParam = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED); + using var volumeParam = wall.get_Parameter(BuiltInParameter.HOST_VOLUME_COMPUTED); Assert.NotNull(volumeParam); Assert.True(volumeParam.AsDouble() > 0); } @@ -42,7 +42,7 @@ namespace SampleLibrary public void GetWallGrossAreaAndRollBack() { var testModel = Utils.GetTestModel("walls.rvt"); - var doc = xru.OpenDoc(testModel); + using var doc = xru.OpenDoc(testModel); var walls = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Walls).ToElements(); var wall = walls[0] as Wall; double grossArea = 0; @@ -50,17 +50,15 @@ namespace SampleLibrary var inserts = wall.FindInserts(true, true, true, true); xru.Run(() => { - using (Transaction transaction = new Transaction(doc, "Temporary - only to get gross area")) - { - transaction.Start(); - foreach (ElementId insertId in inserts) { doc.Delete(insertId); } - doc.Regenerate(); - var wallFaceReference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior); - var face = doc.GetElement(wallFaceReference.First()).GetGeometryObjectFromReference(wallFaceReference.First()) as PlanarFace; - var wallFaceEdges = face.GetEdgesAsCurveLoops(); - grossArea = ExporterIFCUtils.ComputeAreaOfCurveLoops(wallFaceEdges); - transaction.RollBack(); - } + using var transaction = new Transaction(doc, "Temporary - only to get gross area"); + transaction.Start(); + foreach (ElementId insertId in inserts) { doc.Delete(insertId); } + doc.Regenerate(); + var wallFaceReference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Exterior); + using var face = doc.GetElement(wallFaceReference[0]).GetGeometryObjectFromReference(wallFaceReference[0]) as PlanarFace; + var wallFaceEdges = face.GetEdgesAsCurveLoops(); + grossArea = ExporterIFCUtils.ComputeAreaOfCurveLoops(wallFaceEdges); + transaction.RollBack(); }, doc).Wait(); Assert.True(grossArea > 0); } diff --git a/SampleLibrary/TestWithFixture.cs b/SampleLibrary/TestWithFixture.cs index e32691c..a54efad 100644 --- a/SampleLibrary/TestWithFixture.cs +++ b/SampleLibrary/TestWithFixture.cs @@ -22,8 +22,8 @@ namespace SampleLibrary [Fact] public void WallOffset() { - var wall = fixture.Doc.GetElement(new ElementId(346573)); - var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); + using var wall = fixture.Doc.GetElement(new ElementId(346573)); + using var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); #if pre2021 var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType); @@ -57,7 +57,7 @@ namespace SampleLibrary foreach (var wall in walls) { - var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); + using var param = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); #if pre2021 var baseOffset = UnitUtils.ConvertFromInternalUnits(param.AsDouble(), param.DisplayUnitType); #else diff --git a/xUnitRevit/App.cs b/xUnitRevit/App.cs index 62428eb..1e570ce 100644 --- a/xUnitRevit/App.cs +++ b/xUnitRevit/App.cs @@ -16,12 +16,12 @@ namespace xUnitRevit private void ControlledApplication_ApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e) { - Application app = sender as Application; - UIApplication uiapp = new UIApplication(app); + var app = sender as Application; + using var uiapp = new UIApplication(app); Runner.ReadConfig(); - if (Runner.Config.autoStart) + if (Runner.Config.AutoStart) Runner.Launch(uiapp); } diff --git a/xUnitRevit/Command.cs b/xUnitRevit/Command.cs index 19a8465..6378a6d 100644 --- a/xUnitRevit/Command.cs +++ b/xUnitRevit/Command.cs @@ -19,11 +19,9 @@ namespace xUnitRevit ref string message, ElementSet elements) { - UIApplication uiapp = commandData.Application; + var uiapp = commandData.Application; Runner.Launch(uiapp); return Result.Succeeded; } } - - } diff --git a/xUnitRevit/Configuration.cs b/xUnitRevit/Configuration.cs index fbd3a59..6e0449a 100644 --- a/xUnitRevit/Configuration.cs +++ b/xUnitRevit/Configuration.cs @@ -8,6 +8,6 @@ namespace xUnitRevit public class Configuration { public IList StartupAssemblies { get; set; } = new List(); - public bool autoStart { get; set; } = false; + public bool AutoStart { get; set; } = false; } } diff --git a/xUnitRevit/Runner.cs b/xUnitRevit/Runner.cs index 815f9f3..8695b27 100644 --- a/xUnitRevit/Runner.cs +++ b/xUnitRevit/Runner.cs @@ -23,20 +23,22 @@ namespace xUnitRevit try { var queue = new List(); - var eventHandler = ExternalEvent.Create(new ExternalEventHandler(queue)); + using var eventHandler = ExternalEvent.Create(new ExternalEventHandler(queue)); xru.Initialize(uiapp, SynchronizationContext.Current, eventHandler, queue); - var main = new MainWindow(); - main.Title = "xUnit Revit by Speckle"; - main.MaxHeight = 800; + var main = new MainWindow + { + Title = "xUnit Revit by Speckle", + MaxHeight = 800 + }; //pre-load asssemblies, if you're a lazy developer if (main.DataContext is MainViewModel mainViewModel) mainViewModel.StartupAssemblies = Config.StartupAssemblies.ToList(); main.Show(); } - catch (Exception) + catch { //fail silently } @@ -48,7 +50,7 @@ namespace xUnitRevit { var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var path = Path.Combine(dir, "config.json"); - JavaScriptSerializer JavaScriptSerializer = new JavaScriptSerializer(); + var JavaScriptSerializer = new JavaScriptSerializer(); var json = File.ReadAllText(path); Config = JavaScriptSerializer.Deserialize(json); } diff --git a/xUnitRevitUtilsShared/xru.cs b/xUnitRevitUtilsShared/xru.cs index bc0de7a..719d723 100644 --- a/xUnitRevitUtilsShared/xru.cs +++ b/xUnitRevitUtilsShared/xru.cs @@ -44,7 +44,7 @@ namespace xUnitRevitUtils Assert.NotNull(Uiapp); Document doc = null; //OpenAndActivateDocument only works if run from the current context - UiContext.Send(x => { doc = Uiapp.OpenAndActivateDocument(filePath).Document; }, null); + UiContext.Send(x => doc = Uiapp.OpenAndActivateDocument(filePath).Document, null); Assert.NotNull(doc); return doc; } @@ -66,7 +66,9 @@ namespace xUnitRevitUtils if (overwrite && File.Exists(filePath)) File.Delete(filePath); } - catch { } + catch + { + } //OpenAndActivateDocument only works if run from the current context UiContext.Send(x => @@ -101,20 +103,18 @@ namespace xUnitRevitUtils { try { - using (Transaction transaction = new Transaction(doc, transactionName)) - { - transaction.Start(); - - if (ignoreWarnings) - { - var options = transaction.GetFailureHandlingOptions(); - options.SetFailuresPreprocessor(new IgnoreAllWarnings()); - transaction.SetFailureHandlingOptions(options); - } - - action.Invoke(); - transaction.Commit(); - } + using var transaction = new Transaction(doc, transactionName); + transaction.Start(); + + if (ignoreWarnings) + { + using var options = transaction.GetFailureHandlingOptions(); + options.SetFailuresPreprocessor(new IgnoreAllWarnings()); + transaction.SetFailureHandlingOptions(options); + } + + action.Invoke(); + transaction.Commit(); } catch (Exception e) {