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,19 @@
using System.Configuration;
namespace Kreta.Client.GlobalApi.Configuration
{
public class GlobalApiConfiguration : ConfigurationSection, IGlobalApiConfiguration
{
[ConfigurationProperty(nameof(GlobalApiUrl), IsRequired = true)]
public string GlobalApiUrl => (string)this[nameof(GlobalApiUrl)];
[ConfigurationProperty(nameof(TokenUrl), IsRequired = true)]
public string TokenUrl => (string)this[nameof(TokenUrl)];
[ConfigurationProperty(nameof(ClientId), IsRequired = true)]
public string ClientId => (string)this[nameof(ClientId)];
[ConfigurationProperty(nameof(ClientSecret), IsRequired = true)]
public string ClientSecret => (string)this[nameof(ClientSecret)];
}
}

View file

@ -0,0 +1,10 @@
namespace Kreta.Client.GlobalApi.Configuration
{
public interface IGlobalApiConfiguration
{
string GlobalApiUrl { get; }
string TokenUrl { get; }
string ClientId { get; }
string ClientSecret { get; }
}
}

View file

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Net;
using Kreta.Client.ClientBase;
using Kreta.Client.ClientBase.Extension;
using Kreta.Client.ClientBase.Response;
using Kreta.Client.GlobalApi.Configuration;
using Kreta.Client.GlobalApi.Models;
using Kreta.Core;
using Kreta.Framework;
using Kreta.Framework.Exceptions;
using Kreta.Resources;
using Newtonsoft.Json;
namespace Kreta.Client.GlobalApi
{
internal class GlobalApiClient : RestSharpClientBase, IGlobalApiClient
{
private readonly GlobalApiConfiguration configuration;
public GlobalApiClient()
{
configuration = (GlobalApiConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.GlobalApiConfiguration);
}
public GetTokenResponse GetPrivateToken()
{
return GetToken(new Dictionary<string, string> {
{ "client_id", configuration.ClientId },
{ "client_secret", configuration.ClientSecret },
{ "grant_type", "client_credentials" }
});
}
public List<AdatbaziselerhetosegResponseModel> GetKretaAdatbaziselerhetosegek(string privateToken, SystemType systemType)
{
return ExceptionLogger(() =>
{
BaseUrl = configuration.GlobalApiUrl;
var relativeUri = $"/adatbaziselerhetosegek/kreta/{systemType}";
var header = privateToken.GetAuthorizationHeaderWithJson();
var response = Get(relativeUri, header);
if (response.StatusCode == HttpStatusCode.OK)
{
return JsonConvert.DeserializeObject<List<AdatbaziselerhetosegResponseModel>>(response.Result,
new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore });
}
else
{
throw new Exception(ErrorResource.HibasIdpKeres);
}
});
}
private GetTokenResponse GetToken(Dictionary<string, string> tokenRequestParameters)
{
return ExceptionLogger(() =>
{
BaseUrl = configuration.TokenUrl;
var relativeUri = "/connect/token";
var response = Post(relativeUri, HeaderExtension.GetFormUrlEncodedHeader(), tokenRequestParameters);
if (response.StatusCode == HttpStatusCode.OK)
{
var successResponse = JsonConvert.DeserializeObject<GetTokenSuccessResponse>(response.Result);
return new GetTokenResponse(successResponse.AccessToken, successResponse.ExpiresIn);
}
var failureResponse = JsonConvert.DeserializeObject<GetTokenFailureResponse>(response.Result);
return new GetTokenResponse(failureResponse.Error);
});
}
private T ExceptionLogger<T>(Func<T> action)
{
try
{
return action();
}
catch (Exception ex)
{
SDAServer.Instance.Logger.ExceptionThrown(ex);
return (T)Activator.CreateInstance(typeof(T), ExceptionUtil.ExceptionToString(ex));
}
}
}
public class GlobalApiClientFactory
{
public static IGlobalApiClient Build()
{
return new GlobalApiClient();
}
}
}

View file

@ -0,0 +1,13 @@
using System.Collections.Generic;
using Kreta.Client.ClientBase.Response;
using Kreta.Client.GlobalApi.Models;
using Kreta.Framework;
namespace Kreta.Client.GlobalApi
{
public interface IGlobalApiClient
{
GetTokenResponse GetPrivateToken();
List<AdatbaziselerhetosegResponseModel> GetKretaAdatbaziselerhetosegek(string privateToken, SystemType systemType);
}
}

View file

@ -0,0 +1,19 @@
using System;
namespace Kreta.Client.GlobalApi.Models
{
public partial class AdatbaziselerhetosegResponseModel
{
public Guid IntezmenyId { get; set; }
public string IntezmenyAzonosito { get; set; }
public int KretaIntezmenyId { get; set; }
public string IntezmenyNev { get; set; }
public int GlobalIntezmenyId { get; set; }
public string OmKod { get; set; }
public string SqlInstanceName { get; set; }
public string DatabaseName { get; set; }
public int KornyezetId { get; set; }
public string KornyezetNev { get; set; }
public string KornyezetTeljesNev { get; set; }
}
}