Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (47 loc) · 2.04 KB
/
Copy pathProgram.cs
File metadata and controls
58 lines (47 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using BiExcellence.OpenBi.Server.License.Abstractions;
using Ibssolution.biox.Repositoryserver;
using Microsoft.Extensions.Logging;
using System.Text.Json.Nodes;
namespace CustomCommandHandlerExample;
// Adds a command to the legacy command API (/openbi/xmlprovider/mobile.biex).
// New functionality should be added as a REST endpoint instead, see the CustomHttpHandler example.
public sealed class CustomCommandHandler : ICommandApiHandler
{
private readonly ILicense _license;
private readonly ILogger<CustomCommandHandler> _logger;
// Services are injected through the constructor
public CustomCommandHandler(ILicense license, ILogger<CustomCommandHandler> logger)
{
_license = license;
_logger = logger;
}
public Task<bool> ProcessCommandAsync(JsonObject responseObj, sxRequest request, OpenBiSession session, CancellationToken cancellationToken)
{
// Every handler is asked for every command, so return false for all other commands
if (request.Command != "MY_CUSTOM_COMMAND")
{
return Task.FromResult(false);
}
_logger.LogInformation("Processing {Command}", request.Command);
// Read a parameter sent by the client
if (request.Parameters.TryGetValue("PARAMETER", out var nameValue))
{
responseObj["RETURN"] = nameValue.Value;
}
// Check whether the session is authenticated
if (session.User is not null)
{
responseObj["USERNAME"] = session.User.Username;
}
responseObj["LICENSE_NAME"] = _license.Name;
// Nested objects and arrays are written with JsonObject / JsonArray
responseObj["VALUES"] = new JsonArray("first", "second");
// Throw an OpenbiMobileCommandException to answer with a specific return code
if (request.Parameters.ContainsKey("FAIL"))
{
throw new OpenbiMobileCommandException("Something went wrong", -100);
}
// Mark the command as handled
return Task.FromResult(true);
}
}