Files
Jedd Morgan b6be7a351f feat(automate): Add automate SDK (#313)
* First pass

* First pass adding service registraiton

* Finished up service registration

* Json exception

* Moved to the right place

* Fixed tests

* Added some missing docs strings

* Reflecting Gergo's specklepy changes

* Correct the DI registration

* Readme

* No warn beta packages

* Format

* renamed misleading variable

* Fixed lock files

* Disable SQLite for automate
2025-05-30 13:05:14 +01:00

47 lines
1.2 KiB
C#

using System.ComponentModel.DataAnnotations;
using Speckle.Sdk.Models;
namespace Speckle.Automate.Sdk.Integration;
public struct TestFunctionInputs
{
[Required]
public string ForbiddenSpeckleType { get; set; }
}
public static class TestAutomateFunction
{
public static async Task Run(IAutomationContext automateContext, TestFunctionInputs testFunctionInputs)
{
Base versionRootObject = await automateContext.ReceiveVersion();
int count = 0;
if (versionRootObject.speckle_type == testFunctionInputs.ForbiddenSpeckleType)
{
if (versionRootObject.id is null)
{
throw new InvalidOperationException("Cannot operate on objects without their ids");
}
automateContext.AttachErrorToObjects(
"",
new[] { versionRootObject },
$"This project should not contain the type: {testFunctionInputs.ForbiddenSpeckleType} "
);
count += 1;
}
if (count > 0)
{
automateContext.MarkRunFailed(
"Automation failed: "
+ $"Found {count} object that have a forbidden speckle type: {testFunctionInputs.ForbiddenSpeckleType}"
);
}
else
{
automateContext.MarkRunSuccess("No forbidden types found.");
}
}
}