67 lines
2.4 KiB
C#
67 lines
2.4 KiB
C#
using C4IT.FASD.Base;
|
|
using C4IT.FASD.Cockpit.Communication;
|
|
using FasdDesktopUi.Basics.Services.RelationService;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using static C4IT.Logging.cLogManager;
|
|
|
|
namespace FasdDesktopUi.Basics.Services.SupportCaseSearchService
|
|
{
|
|
public class SupportCaseSearchService
|
|
{
|
|
private readonly IRelationService _relationService;
|
|
|
|
public SupportCaseSearchService(IRelationService relationService)
|
|
{
|
|
_relationService = relationService;
|
|
_relationService.RelationsFound += HandleRelationsFound;
|
|
}
|
|
|
|
~SupportCaseSearchService()
|
|
{
|
|
_relationService.RelationsFound -= HandleRelationsFound;
|
|
}
|
|
|
|
public static async Task<cFasdApiSearchResultCollection> GetSearchResultsAsync(string searchQuery, CancellationToken token = default)
|
|
{
|
|
Guid? searchId = null;
|
|
try
|
|
{
|
|
searchId = await cFasdCockpitCommunicationBase.Instance.GetSearchResultsStart(searchQuery, token);
|
|
|
|
if (searchId is null)
|
|
return new cFasdApiSearchResultCollection();
|
|
|
|
return await cFasdCockpitCommunicationBase.Instance.GetSearchResultsResult(searchId.Value, token);
|
|
}
|
|
catch (TaskCanceledException)
|
|
{
|
|
if (searchId != null)
|
|
await cFasdCockpitCommunicationBase.Instance.GetSearchResultsStop(searchId.Value, CancellationToken.None);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogException(ex);
|
|
}
|
|
|
|
return new cFasdApiSearchResultCollection();
|
|
}
|
|
|
|
public async Task<cF4sdStagedSearchResultRelationTaskId> LoadRelationsAsync(IEnumerable<cFasdApiSearchResultEntry> relatedTo, CancellationToken token = default)
|
|
=> await _relationService.LoadRelationsAsync(relatedTo, token);
|
|
|
|
private void HandleRelationsFound(object sender, StagedSearchResultRelationsEventArgs e)
|
|
{
|
|
e.RelationService = _relationService;
|
|
RelationsFound.Invoke(this, e);
|
|
}
|
|
|
|
public event EventHandler<StagedSearchResultRelationsEventArgs> RelationsFound;
|
|
}
|
|
}
|