Add event-driven quick action dispatch
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using C4IT.FASD.Base;
|
||||
using F4SD.ActionConnector.Execution;
|
||||
using F4SD.ActionConnector.Models;
|
||||
using F4SD.ActionConnector.Payloads;
|
||||
using FasdDesktopUi.Basics.Models;
|
||||
using FasdDesktopUi.Basics.Services.SupportCase.Controllers;
|
||||
using FasdDesktopUi.Basics.Services.SupportCase.Processors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace FasdDesktopUi.Basics.UiActions.NativeActions
|
||||
{
|
||||
internal static class QuickActionExecutor
|
||||
{
|
||||
private static ISupportCaseProcessor _supportCaseProcessor;
|
||||
|
||||
internal static void SetSupportCaseProcessor(ISupportCaseProcessor supportCaseProcessor)
|
||||
{
|
||||
_supportCaseProcessor = supportCaseProcessor ?? throw new ArgumentNullException(nameof(supportCaseProcessor));
|
||||
}
|
||||
|
||||
internal static async Task<ActionResult> RunAction(QuickActionRequest quickActionRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_supportCaseProcessor is null)
|
||||
return ActionResult.Fail(quickActionRequest.ActionId, "No valid SupportCase processor was found.");
|
||||
|
||||
if (!(quickActionRequest.Context.Payload is CaseClosedPayload payload))
|
||||
return ActionResult.Fail(quickActionRequest.ActionId, $"Payload is not of type '{typeof(CaseClosedPayload)}'. It is of type '{quickActionRequest.Context.Payload.GetType()}'");
|
||||
|
||||
cMenuDataBase menuData = MenuDataFactory.GetByName(quickActionRequest.QuickActionRef, _supportCaseProcessor.SupportCaseDataProviderArtifact.NamedParameterEntries, _supportCaseProcessor.SupportCaseDataProviderArtifact.CaseRelations.Select(r => r.Key));
|
||||
|
||||
// Till there is a clear picture of what object belongs to a case and what doesn't
|
||||
// we do not want to make remote Quick Actions available
|
||||
if (menuData is null || !(menuData.UiAction is cUiLocalQuickAction quickAction))
|
||||
{
|
||||
LogEntry($"'{quickActionRequest.QuickActionRef}' is no valid Local QuickAction and was therefore skipped.", C4IT.Logging.LogLevels.Error);
|
||||
return ActionResult.Skip(quickActionRequest.ActionId);
|
||||
}
|
||||
|
||||
await quickAction.RunUiActionAsync(null, null, false, _supportCaseProcessor.SupportCaseDataProviderArtifact);
|
||||
await quickAction.ProcessActionAsync(CancellationToken.None, GetParameterDictionaryFrom(quickActionRequest.Parameters));
|
||||
|
||||
return ActionResult.Ok(quickActionRequest.ActionId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
return ActionResult.Fail(quickActionRequest.ActionId, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<cAdjustableParameter, object> GetParameterDictionaryFrom(IDictionary<string, object> requestParameters)
|
||||
{
|
||||
try
|
||||
{
|
||||
return requestParameters.ToDictionary(p => new cAdjustableParameterString() { ParameterName = p.Key } as cAdjustableParameter, p => p.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
return new Dictionary<cAdjustableParameter, object>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user