This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,55 @@
using System;
using System.ServiceModel;
using Kreta.Resources;
namespace Kreta.Client
{
public class ClientHelper
{
//TODO:Exceptionokat szétszedni
public T CallService<TService, T>(Func<TService, T> action) where TService : ICommunicationObject, new()
{
T res;
var client = default(TService);
try
{
client = new TService();
res = action(client);
client.Close();
}
catch (TimeoutException ex)
{
throw new TimeoutException(ErrorResource.AzAdatokLekerdezesereTullepteAMegadottIdokeretet, ex);
}
catch (FaultException ex)
{
throw new Exception(ErrorResource.AKirBejelentkezesiAdatokNemMegfeleloekKerjukProbaljaMegismetelniABejelentkezest, ex);
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
CloseClientCommunication(client);
}
return res;
}
private void CloseClientCommunication<TService>(TService client) where TService : ICommunicationObject, new()
{
if (client.State == CommunicationState.Faulted)
{
client.Abort();
}
else if (client.State != CommunicationState.Closed)
{
client.Close();
}
}
}
}