Skip to content

Commit e02a141

Browse files
authored
Merge pull request #84 from g4-api/development
Add file-based automation endpoints and rename env settings
2 parents b17dcf4 + ad5a36f commit e02a141

7 files changed

Lines changed: 114 additions & 38 deletions

File tree

‎src/G4.Services.Domain.V4/G4.Services.Domain.V4.csproj‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="G4.Api" Version="2026.4.30.45" />
20-
<PackageReference Include="G4.Plugins" Version="2026.4.29.65" />
21-
<PackageReference Include="G4.Plugins.Common" Version="2026.4.30.128" />
22-
<PackageReference Include="G4.Plugins.Ui" Version="2026.4.30.128" />
23-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.8" />
19+
<PackageReference Include="G4.Api" Version="2026.6.16.46" />
20+
<PackageReference Include="G4.Plugins" Version="2026.6.15.66" />
21+
<PackageReference Include="G4.Plugins.Common" Version="2026.6.16.129" />
22+
<PackageReference Include="G4.Plugins.Ui" Version="2026.6.16.129" />
23+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.9" />
2424
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="10.2.1" />
2525
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.2.1" />
2626
</ItemGroup>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace G4.Services.Domain.V4.Models
2+
{
3+
/// <summary>
4+
/// Represents a file invocation request.
5+
/// </summary>
6+
public class FileInvokeModel
7+
{
8+
/// <summary>
9+
/// Gets or sets the full or relative path of the file to invoke.
10+
/// </summary>
11+
public string Path { get; set; }
12+
}
13+
}

‎src/G4.Services.Hub.Api.V4/Controllers/AutomationAsyncController.cs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using G4.Models;
22
using G4.Services.Domain.V4;
3+
using G4.Services.Domain.V4.Models;
34

45
using Microsoft.AspNetCore.Http;
56
using Microsoft.AspNetCore.Mvc;
67

78
using Swashbuckle.AspNetCore.Annotations;
89

910
using System.Net.Mime;
11+
using System.Text.Json;
1012

1113
namespace G4.Services.Hub.Api.V4.Controllers
1214
{
@@ -56,5 +58,35 @@ public IActionResult Start([FromBody] G4AutomationModel automation)
5658
// Return an HTTP 202 Accepted response indicating that the automation task has been accepted.
5759
return Accepted();
5860
}
61+
62+
[HttpPost]
63+
[Route("file/start")]
64+
[SwaggerOperation(
65+
Summary = "Enqueue a new automation task from a file.",
66+
Description = "Reads a G4 automation model from the provided file path, deserializes the file content into a G4AutomationModel, and enqueues it into the pending queue. The automation task will be picked up by any available automation worker for asynchronous processing.",
67+
Tags = ["Automation", "AutomationAsync"])]
68+
[SwaggerResponse(StatusCodes.Status202Accepted,
69+
Description = "The automation task has been accepted and enqueued. The response is empty as processing is performed asynchronously.",
70+
Type = typeof(void),
71+
ContentTypes = [MediaTypeNames.Application.Json])]
72+
public IActionResult Start(
73+
[FromBody]
74+
[SwaggerRequestBody(
75+
Description = "The file invocation model containing the path to the automation JSON file.",
76+
Required = true)]
77+
FileInvokeModel invokeModel)
78+
{
79+
// Read the automation file content from the provided file path.
80+
var content = System.IO.File.ReadAllText(invokeModel.Path);
81+
82+
// Deserialize the file content into a G4 automation model using the domain JSON options.
83+
var automation = JsonSerializer.Deserialize<G4AutomationModel>(content, _domain.Asp.JsonOptions);
84+
85+
// Enqueue the automation model into the pending queue for asynchronous processing by an available worker.
86+
_domain.G4.Client.AutomationAsync.AddPendingAutomation(automation);
87+
88+
// Return an HTTP 202 Accepted response indicating that the automation task has been accepted.
89+
return Accepted();
90+
}
5991
}
6092
}

‎src/G4.Services.Hub.Api.V4/Controllers/AutomationController.cs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using G4.Extensions;
22
using G4.Models;
33
using G4.Services.Domain.V4;
4+
using G4.Services.Domain.V4.Models;
45

56
using Microsoft.AspNetCore.Http;
67
using Microsoft.AspNetCore.Mvc;
@@ -22,6 +23,36 @@ public class AutomationController(IDomain domain) : ControllerBase
2223
// The domain service for the G4™ engine.
2324
private readonly IDomain _domain = domain;
2425

26+
[HttpPost]
27+
[Route("file/invoke")]
28+
[SwaggerOperation(
29+
summary: "Invokes an automation session from a file.",
30+
description: "Reads a G4 automation model from the provided file path, deserializes the file content into a `G4AutomationModel`, and invokes the automation session. The result includes detailed information about the automation run, returned in JSON format.",
31+
Tags = ["Automation"])]
32+
[SwaggerResponse(StatusCodes.Status200OK,
33+
description: "Successfully invoked the automation session from the provided file. Returns a dictionary containing detailed information about the automation run.",
34+
type: typeof(IDictionary<string, G4AutomationResponseModel>),
35+
contentTypes: MediaTypeNames.Application.Json)]
36+
public IActionResult Invoke(
37+
[FromBody]
38+
[SwaggerRequestBody(
39+
description: "The file invocation model containing the path to the automation JSON file.",
40+
Required = true)]
41+
FileInvokeModel invokeModel)
42+
{
43+
// Read the content of the file specified in the invokeModel.Path.
44+
var content = System.IO.File.ReadAllText(invokeModel.Path);
45+
46+
// Deserialize the file content into a G4AutomationModel using the domain's JSON options.
47+
var automation = JsonSerializer.Deserialize<G4AutomationModel>(content, _domain.Asp.JsonOptions);
48+
49+
// Invoke the automation session using the provided automation model.
50+
var response = _domain.G4.Client.Automation.Invoke(automation);
51+
52+
// Return a 200 OK response with the detailed automation session results.
53+
return Ok(response);
54+
}
55+
2556
[HttpPost]
2657
[Route("invoke")]
2758
[SwaggerOperation(

‎src/G4.Services.Hub/wwwroot/js/canvas.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ function newStartDefinition(sequence) {
730730
returnStructuredResponse: false,
731731
searchTimeout: 15000,
732732
},
733-
environmentSettings: {
733+
environmentsSettings: {
734734
defaultEnvironment: "SystemParameters",
735735
returnEnvironment: false
736736
},
@@ -925,23 +925,23 @@ function rootEditorProvider(definition, editorContext, isReadonly) {
925925
);
926926

927927
// Add an environment settings field for configuring the G4 environment settings.
928-
CustomG4Fields.newEnvironmentSettingsField(
928+
CustomG4Fields.newEnvironmentsSettingsField(
929929
{
930930
container: container,
931-
label: "G4™ Environment Settings",
931+
label: "G4™ Environments Settings",
932932
title: "Provide G4™ environment settings to configure the automation.",
933-
initialValue: definition.properties.settings?.environmentSettings
933+
initialValue: definition.properties.settings?.environmentsSettings
934934
},
935935
(value) => {
936936
// Ensure the "settings" property exists in the definition.
937937
definition.properties.settings = definition.properties.settings || {};
938938

939-
// Ensure the "environmentSettings" property exists in the definition.
940-
definition.properties.settings.environmentSettings = definition.properties.settings.environmentSettings || {};
939+
// Ensure the "environmentsSettings" property exists in the definition.
940+
definition.properties.settings.environmentsSettings = definition.properties.settings.environmentsSettings || {};
941941

942942
// Update the "authentication" property with the new values from the input.
943943
for (const key of Object.keys(value)) {
944-
definition.properties.settings.environmentSettings[key] = value[key];
944+
definition.properties.settings.environmentsSettings[key] = value[key];
945945
}
946946

947947
// Notify the editor of the updated properties.

‎src/G4.Services.Hub/wwwroot/js/custom-fields.js‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,24 +1343,24 @@ class CustomG4Fields {
13431343
}
13441344

13451345
/**
1346-
* Creates and configures a new Environment Settings field that allows users to:
1346+
* Creates and configures a new Environments Settings field that allows users to:
13471347
* 1. Specify a default environment for automation requests.
13481348
* 2. Toggle whether the environment should be returned in the response.
13491349
* 3. Define key-value pairs for environment variables.
13501350
*
1351-
* @param {Object} options - Configuration options for the Environment Settings field.
1352-
* @param {HTMLElement} [options.container] - The DOM element to which the Environment Settings field will be appended.
1353-
* @param {string} options.label - The label identifier for the Environment Settings field.
1351+
* @param {Object} options - Configuration options for the Environments Settings field.
1352+
* @param {HTMLElement} [options.container] - The DOM element to which the Environments Settings field will be appended.
1353+
* @param {string} options.label - The label identifier for the Environments Settings field.
13541354
* @param {string} [options.title] - The title attribute for the field container, often used for tooltips.
13551355
* @param {Object} [options.initialValue] - The initial settings values for environment configuration.
13561356
* @param {string} [options.initialValue.defaultEnvironment='SystemParameters'] - Specifies the default environment.
13571357
* @param {boolean} [options.initialValue.returnEnvironment=false] - Indicates whether the environment should be returned in the response.
13581358
* @param {Object} [options.initialValue.environmentVariables={}] - A collection of static environment variables.
1359-
* @param {Function} setCallback - A callback function invoked whenever the Environment Settings field data changes.
1359+
* @param {Function} setCallback - A callback function invoked whenever the Environments Settings field data changes.
13601360
*
1361-
* @returns {HTMLElement} The container element that includes the newly created Environment Settings field.
1361+
* @returns {HTMLElement} The container element that includes the newly created Environments Settings field.
13621362
*/
1363-
static newEnvironmentSettingsField(options, setCallback) {
1363+
static newEnvironmentsSettingsField(options, setCallback) {
13641364
// Generate a unique identifier for the environment settings fields.
13651365
const inputId = Utilities.newUid();
13661366

@@ -1388,11 +1388,11 @@ class CustomG4Fields {
13881388
},
13891389
(value) => {
13901390
// Build an object containing the updated default environment value
1391-
const environmentSettings = {
1391+
const environmentsSettings = {
13921392
defaultEnvironment: value
13931393
};
13941394
// Invoke the main callback function with updated settings
1395-
setCallback(environmentSettings);
1395+
setCallback(environmentsSettings);
13961396
}
13971397
);
13981398

@@ -1406,11 +1406,11 @@ class CustomG4Fields {
14061406
},
14071407
(value) => {
14081408
// Convert the string value ('true'/'false') to a boolean
1409-
const environmentSettings = {
1409+
const environmentsSettings = {
14101410
returnEnvironment: Utilities.convertStringToBool(value)
14111411
};
14121412
// Invoke the main callback function with updated settings
1413-
setCallback(environmentSettings);
1413+
setCallback(environmentsSettings);
14141414
}
14151415
);
14161416

@@ -1424,11 +1424,11 @@ class CustomG4Fields {
14241424
},
14251425
(value) => {
14261426
// Build an object containing the updated environment variables
1427-
const environmentSettings = {
1427+
const environmentsSettings = {
14281428
environmentVariables: value
14291429
};
14301430
// Invoke the main callback function with updated settings
1431-
setCallback(environmentSettings);
1431+
setCallback(environmentsSettings);
14321432
}
14331433
);
14341434

@@ -2028,11 +2028,11 @@ class CustomG4Fields {
20282028
},
20292029
(value) => {
20302030
// Build an object containing the updated output folder value
2031-
const environmentSettings = {
2031+
const environmentsSettings = {
20322032
outputFolder: value
20332033
};
20342034
// Invoke the main callback function with updated settings
2035-
setCallback(environmentSettings);
2035+
setCallback(environmentsSettings);
20362036
}
20372037
);
20382038

‎src/G4.Settings/G4.Settings.csproj‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232
<!-- Please refrain from upgrading LiteDB until the locking bug is addressed.
3333
The latest known version without this issue is version 5.0.17.
3434
https://github.com/mbdavid/LiteDB/issues/1976#issuecomment-1968006775 -->
35-
<PackageReference Include="G4.Converters" Version="2026.4.29.65" />
35+
<PackageReference Include="G4.Converters" Version="2026.6.15.66" />
3636
<PackageReference Include="LiteDB" Version="5.0.17" />
37-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.8" />
38-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.8" />
39-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.8" />
40-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.8" />
41-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="10.0.8" />
42-
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="10.0.8" />
43-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.8" />
44-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.8" />
45-
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="10.0.8" />
46-
<PackageReference Include="Microsoft.Extensions.Primitives" Version="10.0.8" />
37+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.9" />
38+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.9" />
39+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.9" />
40+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.9" />
41+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="10.0.9" />
42+
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="10.0.9" />
43+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.9" />
44+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.9" />
45+
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="10.0.9" />
46+
<PackageReference Include="Microsoft.Extensions.Primitives" Version="10.0.9" />
4747
</ItemGroup>
4848

4949
</Project>

0 commit comments

Comments
 (0)