86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using System;
|
|
using C4IT.FASD.Base;
|
|
using C4IT.Logging;
|
|
using FasdDesktopUi.Basics;
|
|
using static C4IT.Logging.cLogManager;
|
|
|
|
namespace FasdDesktopUi.Basics.Helper
|
|
{
|
|
internal static class TicketDeepLinkHelper
|
|
{
|
|
internal static bool TryOpenTicketRelationExternally(cF4sdApiSearchResultRelation relation)
|
|
{
|
|
try
|
|
{
|
|
if (relation == null || relation.Type != enumF4sdSearchResultClass.Ticket)
|
|
return false;
|
|
|
|
var ticketConfig = cFasdCockpitConfig.Instance?.Global?.TicketConfiguration;
|
|
if (ticketConfig == null)
|
|
return false;
|
|
|
|
var isIncident = IsIncidentRelation(relation, out var activityType);
|
|
var openExternally = isIncident
|
|
? ticketConfig.OpenIncidentsExternally
|
|
: ticketConfig.OpenTicketsExternally;
|
|
|
|
if (!openExternally)
|
|
return false;
|
|
|
|
var url = BuildTicketDeepLink(relation.id, activityType);
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
return false;
|
|
|
|
new cBrowsers().Start("default", url);
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogException(ex);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
internal static bool IsIncidentRelation(cF4sdApiSearchResultRelation relation, out string activityType)
|
|
{
|
|
activityType = null;
|
|
|
|
if (relation?.Infos != null && relation.Infos.TryGetValue("ActivityType", out var activityTypeValue))
|
|
activityType = activityTypeValue;
|
|
|
|
if (string.IsNullOrWhiteSpace(activityType))
|
|
return false;
|
|
|
|
return activityType.IndexOf("Incident", StringComparison.OrdinalIgnoreCase) >= 0;
|
|
}
|
|
|
|
internal static string BuildTicketDeepLink(Guid ticketId, string activityType)
|
|
{
|
|
if (ticketId == Guid.Empty)
|
|
return null;
|
|
|
|
var server = cCockpitConfiguration.Instance?.m42ServerConfiguration?.Server;
|
|
if (string.IsNullOrWhiteSpace(server))
|
|
return null;
|
|
|
|
var baseUrl = server.TrimEnd('/');
|
|
if (!baseUrl.StartsWith("http://", StringComparison.OrdinalIgnoreCase) &&
|
|
!baseUrl.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
baseUrl = "https://" + baseUrl;
|
|
}
|
|
if (!baseUrl.EndsWith("/wm", StringComparison.OrdinalIgnoreCase))
|
|
baseUrl += "/wm";
|
|
|
|
if (string.IsNullOrWhiteSpace(activityType))
|
|
return null;
|
|
|
|
var viewOptionsJson = $"{{\"embedded\":false,\"objectId\":\"{ticketId}\",\"type\":\"{activityType}\",\"viewType\":\"preview\",\"archived\":0}}";
|
|
var viewOptionsEncoded = Uri.EscapeDataString(viewOptionsJson);
|
|
|
|
return $"{baseUrl}/app-ServiceDesk/?view-options={viewOptionsEncoded}";
|
|
}
|
|
}
|
|
}
|