Skip to content

Commit

Permalink
OperationReceiver returns Task Result based on handle id
Browse files Browse the repository at this point in the history
  • Loading branch information
Raoul Zebisch committed Sep 12, 2024
1 parent 1b4d033 commit 2d795eb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 39 deletions.
1 change: 1 addition & 0 deletions src/AasxCsharpLibrary/IOperationReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface IOperationReceiver
{
OperationResult OnOperationInvoke(IOperation operation, string submodelId, int? timestamp, string requestId);
Task<OperationResult> OnOperationInvokeAsync(string handleId, IOperation operation, string submodelId, int? timestamp, string requestId);
OperationResult GetResult(string handleId);
}
}
26 changes: 0 additions & 26 deletions src/AasxServerStandardBib/OperationInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using AdminShellNS.Models;
using AdminShellNS;
using System.Threading.Tasks;
Expand All @@ -8,8 +7,6 @@ namespace AasOperationInvocation
public class OperationInvoker : IOperationInvoker
{
public IOperationCommand Command { get; init; }

private static readonly Dictionary<string, OperationHandle> _asyncHandles = [];
private static long _asyncHandleCounter = 0;

public OperationInvoker(IOperationCommand command)
Expand All @@ -29,30 +26,7 @@ public Task<OperationResult> InvokeAsync(out OperationHandle operationHandle)
ExecutionState = ExecutionState.InitiatedEnum,
Task = Command.ExecuteAsync("" + _asyncHandleCounter++)
};
_asyncHandles.Add(operationHandle.HandleId, operationHandle);
return operationHandle.Task;
}

public static OperationResult GetAsyncResult(string handleId)
{
OperationHandle operationHandle = _asyncHandles[handleId];

// Remove if terminated
if ((int) operationHandle.ExecutionState > 1) {
_asyncHandles.Remove(handleId);
return operationHandle.Task.Result;
}

return new OperationResult() {
RequestId = operationHandle.RequestId,
ExecutionState = operationHandle.ExecutionState,
Message = ""
};
}

public static void UpdateExecutionState(string handleId, ExecutionState executionState)
{
_asyncHandles[handleId].ExecutionState = executionState;
}
}
}
17 changes: 5 additions & 12 deletions src/AasxServerStandardBib/OperationReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,18 @@ namespace AasOperationInvocation
{
public class OperationReceiver : IOperationReceiver
{
public OperationResult GetResult(string handleId)
{
throw new NotImplementedException("invoking operations not yet supported");
}

public OperationResult OnOperationInvoke(IOperation operation, string submodelId, int? timestamp, string requestId)
{
throw new NotImplementedException("invoking operations not yet supported");
}

public Task<OperationResult> OnOperationInvokeAsync(string handleId, IOperation operation, string submodelId, int? timestamp, string requestId)
{
// Console.WriteLine("Task initiated...");
// OperationInvoker.UpdateExecutionState(handleId, ExecutionState.InitiatedEnum);

// Console.WriteLine("Task running...");
// OperationInvoker.UpdateExecutionState(handleId, ExecutionState.RunningEnum);
// await Task.Delay(5000);

// Console.WriteLine("Task done...");
// OperationInvoker.UpdateExecutionState(handleId, ExecutionState.CompletedEnum);

// return new OperationResult() { ExecutionState = ExecutionState.CompletedEnum };

throw new NotImplementedException("invoking operations not yet supported");
}

Expand Down
2 changes: 1 addition & 1 deletion src/AasxServerStandardBib/Services/SubmodelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ public OperationHandle InvokeOperationAsync(string submodelIdentifier, string id

public OperationResult GetOperationAsyncResult(string handleId)
{
return OperationInvoker.GetAsyncResult(handleId);
return _operationReceiver.GetResult(handleId);
}
}
}

0 comments on commit 2d795eb

Please sign in to comment.