From db26924f7ec45439ff3fa394bb0b3c71adc5f88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20Jedlicska?= Date: Fri, 25 Aug 2023 19:39:49 +0200 Subject: [PATCH] minor cleanup --- AutomateFunction.cs | 12 ++++++++---- Program.cs | 9 ++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/AutomateFunction.cs b/AutomateFunction.cs index e2a72ce..1b91073 100644 --- a/AutomateFunction.cs +++ b/AutomateFunction.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Objects.Geometry; using Speckle.Core.Api; using Speckle.Core.Credentials; @@ -10,7 +10,7 @@ using Speckle.Core.Transports; /// /// This class is used to generate a JSON Schema to ensure that the user provided values /// are valid and match the required schema. -class FunctionInputs +struct FunctionInputs { [Required] public string SpeckleTypeToCount; @@ -18,7 +18,7 @@ class FunctionInputs class AutomateFunction { - public static async Task Run( + public static async Task Run( SpeckleProjectData speckleProjectData, FunctionInputs functionInputs, string speckleToken @@ -47,6 +47,10 @@ class AutomateFunction new MemoryTransport() ); - return rootObject.Flatten().Count( b => b.speckle_type == functionInputs.SpeckleTypeToCount); + var count = rootObject?.Flatten().Count( b => b.speckle_type == functionInputs.SpeckleTypeToCount); + + Console.WriteLine( + $"Found {count} elements that have the type {functionInputs.SpeckleTypeToCount}" + ); } } diff --git a/Program.cs b/Program.cs index 0c5dca6..3510330 100644 --- a/Program.cs +++ b/Program.cs @@ -57,17 +57,16 @@ internal static class Program var speckleProjectData = JsonConvert.DeserializeObject( rawSpeckleProjectData ); + // if (speckleProjectData is null) throw new ArgumentException("Invalid SpeckleProjectData received"); var functionInputs = JsonConvert.DeserializeObject( rawFunctionInputs ); - var count = await AutomateFunction.Run( + + await AutomateFunction.Run( speckleProjectData, functionInputs, speckleToken ); - Console.WriteLine( - $"Found {count} elements that have the type {functionInputs.SpeckleTypeToCount}" - ); } static string GenerateFunctionInputSchema() @@ -82,7 +81,7 @@ internal static class Program } -internal class SpeckleProjectData +internal struct SpeckleProjectData { public string ProjectId; public string ModelId;