Implement worker advise commands

This commit is contained in:
Joseph Doherty
2026-04-26 18:41:10 -04:00
parent 0fd954d94c
commit a871f2f2e5
11 changed files with 734 additions and 1 deletions
@@ -215,6 +215,127 @@ public sealed class MxAccessLiveComCreationTests
}
}
[Fact]
public async Task AdviseAndUnAdvise_WhenOptedIn_RoundTripsInstalledMxAccessSubscription()
{
if (!RunLiveMxAccessTests())
{
return;
}
using MxAccessStaSession session = new();
await session.StartAsync(workerProcessId: 1234);
MxCommandReply registerReply = await RegisterLiveSessionAsync(session, "live-advise-register");
int serverHandle = registerReply.Register.ServerHandle;
int itemHandle = 0;
bool advised = false;
try
{
MxCommandReply addItemReply = await session.DispatchAsync(new StaCommand(
"session-1",
"live-advise-add-item",
new MxCommand
{
Kind = MxCommandKind.AddItem,
AddItem = new AddItemCommand
{
ServerHandle = serverHandle,
ItemDefinition = GetLiveAddItemReference(),
},
}));
Assert.Equal(ProtocolStatusCode.Ok, addItemReply.ProtocolStatus.Code);
Assert.True(addItemReply.AddItem.ItemHandle > 0);
itemHandle = addItemReply.AddItem.ItemHandle;
MxCommandReply adviseReply = await session.DispatchAsync(new StaCommand(
"session-1",
"live-advise",
new MxCommand
{
Kind = MxCommandKind.Advise,
Advise = new AdviseCommand
{
ServerHandle = serverHandle,
ItemHandle = itemHandle,
},
}));
Assert.Equal(ProtocolStatusCode.Ok, adviseReply.ProtocolStatus.Code);
advised = true;
MxCommandReply unAdviseReply = await session.DispatchAsync(new StaCommand(
"session-1",
"live-unadvise",
new MxCommand
{
Kind = MxCommandKind.UnAdvise,
UnAdvise = new UnAdviseCommand
{
ServerHandle = serverHandle,
ItemHandle = itemHandle,
},
}));
Assert.Equal(ProtocolStatusCode.Ok, unAdviseReply.ProtocolStatus.Code);
advised = false;
MxCommandReply removeItemReply = await session.DispatchAsync(new StaCommand(
"session-1",
"live-advise-remove-item",
new MxCommand
{
Kind = MxCommandKind.RemoveItem,
RemoveItem = new RemoveItemCommand
{
ServerHandle = serverHandle,
ItemHandle = itemHandle,
},
}));
Assert.Equal(ProtocolStatusCode.Ok, removeItemReply.ProtocolStatus.Code);
itemHandle = 0;
}
finally
{
if (advised && itemHandle > 0)
{
await session.DispatchAsync(new StaCommand(
"session-1",
"live-unadvise-cleanup",
new MxCommand
{
Kind = MxCommandKind.UnAdvise,
UnAdvise = new UnAdviseCommand
{
ServerHandle = serverHandle,
ItemHandle = itemHandle,
},
}));
}
if (itemHandle > 0)
{
await session.DispatchAsync(new StaCommand(
"session-1",
"live-advise-remove-item-cleanup",
new MxCommand
{
Kind = MxCommandKind.RemoveItem,
RemoveItem = new RemoveItemCommand
{
ServerHandle = serverHandle,
ItemHandle = itemHandle,
},
}));
}
await UnregisterLiveSessionAsync(session, serverHandle, "live-advise-unregister");
}
}
private static bool RunLiveMxAccessTests()
{
return string.Equals(