init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
27
Kreta.Client/ClientBase/Extension/HeaderExtension.cs
Normal file
27
Kreta.Client/ClientBase/Extension/HeaderExtension.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.ClientBase.Extension
|
||||
{
|
||||
internal static class HeaderExtension
|
||||
{
|
||||
public static Dictionary<string, string> GetAuthorizationHeaderWithMulitpartFrom(this string token)
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "multipart/form-data" },
|
||||
{ "Authorization", $"Bearer {token}" },
|
||||
};
|
||||
|
||||
public static Dictionary<string, string> GetAuthorizationHeaderWithJson(this string token)
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Authorization", $"Bearer {token}" },
|
||||
};
|
||||
|
||||
public static Dictionary<string, string> GetFormUrlEncodedHeader()
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "application/x-www-form-urlencoded" },
|
||||
};
|
||||
}
|
||||
}
|
70
Kreta.Client/ClientBase/Interface/IClientBase.cs
Normal file
70
Kreta.Client/ClientBase/Interface/IClientBase.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net.Cache;
|
||||
using Kreta.Client.Jira.Model.Request;
|
||||
|
||||
namespace Kreta.Client.ClientBase.Interface
|
||||
{
|
||||
internal interface IClientBase
|
||||
{
|
||||
void CreateBasicAuthenticator(string username, string password);
|
||||
|
||||
IRestResult Delete(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore);
|
||||
|
||||
IRestResult Get(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore,
|
||||
int? requestTimeout = null);
|
||||
|
||||
IRestResult<TResponse> Get<TResponse>(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore,
|
||||
int? requestTimeout = null)
|
||||
where TResponse : new();
|
||||
|
||||
IRestResult Patch(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore);
|
||||
|
||||
IRestResult Post(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore);
|
||||
|
||||
IRestResult<TResponse> Post<TResponse>(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
where TResponse : new();
|
||||
}
|
||||
}
|
20
Kreta.Client/ClientBase/Interface/IRestResult.cs
Normal file
20
Kreta.Client/ClientBase/Interface/IRestResult.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Kreta.Client.ClientBase.Interface
|
||||
{
|
||||
internal interface IRestResult
|
||||
{
|
||||
string Result { get; set; }
|
||||
HttpStatusCode StatusCode { get; set; }
|
||||
string StatusDescription { get; set; }
|
||||
Exception Exception { get; set; }
|
||||
string ErrorMessage { get; set; }
|
||||
byte[] RawBytes { get; set; }
|
||||
}
|
||||
|
||||
internal interface IRestResult<TResponse> : IRestResult
|
||||
{
|
||||
TResponse Result { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.ClientBase.Response
|
||||
{
|
||||
internal class GetTokenFailureResponse
|
||||
{
|
||||
[JsonProperty("error")]
|
||||
public string Error { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.ClientBase.Response
|
||||
{
|
||||
public class GetTokenResponse : IResponse
|
||||
{
|
||||
public GetTokenResponse() { }
|
||||
|
||||
public GetTokenResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public GetTokenResponse(string accessToken, int expiresIn)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(accessToken));
|
||||
}
|
||||
|
||||
if (expiresIn < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(expiresIn));
|
||||
}
|
||||
|
||||
IsSuccess = true;
|
||||
AccessToken = accessToken;
|
||||
ExpiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public string AccessToken { get; }
|
||||
|
||||
public int ExpiresIn { get; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.ClientBase.Response
|
||||
{
|
||||
internal class GetTokenSuccessResponse
|
||||
{
|
||||
[JsonProperty(PropertyName = "access_token")]
|
||||
public string AccessToken { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "expires_in")]
|
||||
public int ExpiresIn { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "token_type")]
|
||||
public string TokenType { get; set; }
|
||||
}
|
||||
}
|
11
Kreta.Client/ClientBase/Response/IResponse.cs
Normal file
11
Kreta.Client/ClientBase/Response/IResponse.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace Kreta.Client.ClientBase.Response
|
||||
{
|
||||
internal interface IResponse
|
||||
{
|
||||
bool IsSuccess { get; }
|
||||
|
||||
string Error { get; }
|
||||
|
||||
bool TryAgain { get; }
|
||||
}
|
||||
}
|
42
Kreta.Client/ClientBase/RestResult.cs
Normal file
42
Kreta.Client/ClientBase/RestResult.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using Kreta.Client.ClientBase.Interface;
|
||||
using RestSharp;
|
||||
|
||||
namespace Kreta.Client.ClientBase
|
||||
{
|
||||
internal class RestResult : IRestResult
|
||||
{
|
||||
public string Result { get; set; }
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
public string StatusDescription { get; set; }
|
||||
public Exception Exception { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
public byte[] RawBytes { get; set; }
|
||||
|
||||
public static IRestResult Convert(IRestResponse restResponse) => new RestResult
|
||||
{
|
||||
Result = restResponse.Content,
|
||||
StatusCode = restResponse.StatusCode,
|
||||
StatusDescription = restResponse.StatusDescription,
|
||||
Exception = restResponse.ErrorException,
|
||||
ErrorMessage = restResponse.ErrorMessage,
|
||||
RawBytes = restResponse.RawBytes
|
||||
};
|
||||
}
|
||||
|
||||
internal class RestResult<TResponse> : RestResult, IRestResult<TResponse>
|
||||
{
|
||||
public TResponse Result { get; set; }
|
||||
|
||||
public static IRestResult<TResponse> Convert(IRestResponse<TResponse> restResponse) => new RestResult<TResponse>
|
||||
{
|
||||
Result = restResponse.Data,
|
||||
StatusCode = restResponse.StatusCode,
|
||||
StatusDescription = restResponse.StatusDescription,
|
||||
Exception = restResponse.ErrorException,
|
||||
ErrorMessage = restResponse.ErrorMessage,
|
||||
RawBytes = restResponse.RawBytes
|
||||
};
|
||||
}
|
||||
}
|
235
Kreta.Client/ClientBase/RestSharpClientBase.cs
Normal file
235
Kreta.Client/ClientBase/RestSharpClientBase.cs
Normal file
|
@ -0,0 +1,235 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net.Cache;
|
||||
using Kreta.Client.ClientBase.Interface;
|
||||
using Kreta.Client.Jira.Model.Request;
|
||||
using RestSharp;
|
||||
using RestSharp.Authenticators;
|
||||
|
||||
namespace Kreta.Client.ClientBase
|
||||
{
|
||||
internal abstract class RestSharpClientBase : IClientBase
|
||||
{
|
||||
private IAuthenticator Authenticator { get; set; }
|
||||
internal string BaseUrl { get; set; }
|
||||
|
||||
private IRestRequest CreateRestRequest(
|
||||
Method method,
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
int? requestTimeout = null)
|
||||
{
|
||||
var restRequest = new RestRequest(relativeUri, method);
|
||||
|
||||
if (method == Method.POST || method == Method.PUT || method == Method.PATCH) /*az alap serializáló post esetén nem tudja a property neveket másnak megfeleltetni*/
|
||||
{
|
||||
restRequest.RequestFormat = DataFormat.Json;
|
||||
restRequest.JsonSerializer = new RestSharp.Newtonsoft.Json.NewtonsoftJsonSerializer();
|
||||
/*frissebb RestSharp esetében lehetne ezt a nuget-et használni: RestSharp.Serializers.NewtonsoftJson. Ezzel viszont már a RestSharp-os kliensek lehet beállítani a NewtonsoftJson serializert.*/
|
||||
}
|
||||
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (var header in headers)
|
||||
{
|
||||
restRequest.AddHeader(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
restRequest.AddParameter(parameter.Key, parameter.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (urlSegments != null)
|
||||
{
|
||||
foreach (var urlSegment in urlSegments)
|
||||
{
|
||||
restRequest.AddUrlSegment(urlSegment.Key, urlSegment.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (queryStrings != null)
|
||||
{
|
||||
foreach (var queryString in queryStrings)
|
||||
{
|
||||
restRequest.AddQueryParameter(queryString.Key, queryString.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (body != null)
|
||||
{
|
||||
restRequest.AddJsonBody(body);
|
||||
}
|
||||
|
||||
if (fileList != null && fileList.Count > 0)
|
||||
{
|
||||
fileList.ForEach(file =>
|
||||
{
|
||||
restRequest.AddFileBytes(file.Name, file.Content, file.FileName, file.ContentType);
|
||||
});
|
||||
}
|
||||
|
||||
if (requestTimeout.HasValue)
|
||||
{
|
||||
restRequest.Timeout = requestTimeout.Value;
|
||||
}
|
||||
|
||||
return restRequest;
|
||||
}
|
||||
|
||||
private IRestClient CreateRestClient(string baseUrl, RequestCacheLevel cachePolicyLevel)
|
||||
{
|
||||
var restClient = new RestClient(string.Format(baseUrl))
|
||||
{
|
||||
Authenticator = Authenticator,
|
||||
CachePolicy = new RequestCachePolicy(cachePolicyLevel)
|
||||
};
|
||||
|
||||
return restClient;
|
||||
}
|
||||
|
||||
public void CreateBasicAuthenticator(string username, string password)
|
||||
{
|
||||
if (Authenticator == null && !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
|
||||
{
|
||||
Authenticator = new HttpBasicAuthenticator(username, password);
|
||||
}
|
||||
}
|
||||
|
||||
public IRestResult Post(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.POST, relativeUri, headers, parameters, urlSegments, queryStrings, body, fileList);
|
||||
|
||||
return RestResult.Convert(client.Execute(request));
|
||||
}
|
||||
|
||||
public IRestResult<TResponse> Post<TResponse>(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
where TResponse : new()
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.POST, relativeUri, headers, parameters, urlSegments, queryStrings, body, fileList);
|
||||
|
||||
return RestResult<TResponse>.Convert(client.Execute<TResponse>(request));
|
||||
}
|
||||
|
||||
public IRestResult Put(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.PUT, relativeUri, headers, parameters, urlSegments, queryStrings, body, fileList);
|
||||
|
||||
return RestResult.Convert(client.Execute(request));
|
||||
}
|
||||
|
||||
public IRestResult<TResponse> Put<TResponse>(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
where TResponse : new()
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.PUT, relativeUri, headers, parameters, urlSegments, queryStrings, body, fileList);
|
||||
|
||||
return RestResult<TResponse>.Convert(client.Execute<TResponse>(request));
|
||||
}
|
||||
|
||||
public IRestResult<TResponse> Get<TResponse>(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore,
|
||||
int? requestTimeout = null)
|
||||
where TResponse : new()
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.GET, relativeUri, headers, parameters, urlSegments, queryStrings, requestTimeout: requestTimeout);
|
||||
|
||||
return RestResult<TResponse>.Convert(client.Execute<TResponse>(request));
|
||||
}
|
||||
|
||||
public IRestResult Get(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore,
|
||||
int? requestTimeout = null)
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.GET, relativeUri, headers, parameters, urlSegments, queryStrings, requestTimeout: requestTimeout);
|
||||
|
||||
return RestResult.Convert(client.Execute(request));
|
||||
}
|
||||
|
||||
public IRestResult Patch(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.PATCH, relativeUri, headers, parameters, urlSegments, queryStrings, body);
|
||||
|
||||
return RestResult.Convert(client.Execute(request));
|
||||
}
|
||||
|
||||
public IRestResult Delete(
|
||||
string relativeUri,
|
||||
Dictionary<string, string> headers = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, string> urlSegments = null,
|
||||
Dictionary<string, string> queryStrings = null,
|
||||
object body = null,
|
||||
List<File> fileList = null,
|
||||
RequestCacheLevel cachePolicyLevel = RequestCacheLevel.NoCacheNoStore)
|
||||
{
|
||||
IRestClient client = CreateRestClient(BaseUrl, cachePolicyLevel);
|
||||
IRestRequest request = CreateRestRequest(Method.DELETE, relativeUri, headers, parameters, urlSegments, queryStrings, body, fileList);
|
||||
|
||||
return RestResult.Convert(client.Execute(request));
|
||||
}
|
||||
}
|
||||
}
|
20
Kreta.Client/ClientException.cs
Normal file
20
Kreta.Client/ClientException.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Kreta.Client
|
||||
{
|
||||
public class ClientException : Exception
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
|
||||
public ClientException(string message)
|
||||
: base(message)
|
||||
{ }
|
||||
|
||||
public ClientException(string message, HttpStatusCode statusCode)
|
||||
: base(message)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
}
|
||||
}
|
||||
}
|
55
Kreta.Client/ClientHelper.cs
Normal file
55
Kreta.Client/ClientHelper.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using System.Configuration;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Configuration
|
||||
{
|
||||
public class CoreApiClientConfiguration : ConfigurationSection, ICoreApiClientConfiguration
|
||||
{
|
||||
[ConfigurationProperty(nameof(IDPUrl), IsRequired = true)]
|
||||
public string IDPUrl => (string)base[nameof(IDPUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(DKTUrl), IsRequired = true)]
|
||||
public string DKTUrl => (string)base[nameof(DKTUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(PrivateClientId), IsRequired = true)]
|
||||
public string PrivateClientId => (string)base[nameof(PrivateClientId)];
|
||||
|
||||
[ConfigurationProperty(nameof(PrivateClientSecret), IsRequired = true)]
|
||||
public string PrivateClientSecret => (string)base[nameof(PrivateClientSecret)];
|
||||
|
||||
[ConfigurationProperty(nameof(Scope), IsRequired = true)]
|
||||
public string Scope => (string)base[nameof(Scope)];
|
||||
|
||||
[ConfigurationProperty(nameof(CoreApiIDPUrl), IsRequired = true)]
|
||||
public string CoreApiIDPUrl => (string)base[nameof(CoreApiIDPUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(CoreApiUrl), IsRequired = true)]
|
||||
public string CoreApiUrl => (string)base[nameof(CoreApiUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(CoreApiPrivateClientId), IsRequired = true)]
|
||||
public string CoreApiPrivateClientId => (string)base[nameof(CoreApiPrivateClientId)];
|
||||
|
||||
[ConfigurationProperty(nameof(CoreApiPrivateClientSecret), IsRequired = true)]
|
||||
public string CoreApiPrivateClientSecret => (string)base[nameof(CoreApiPrivateClientSecret)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
namespace Kreta.Client.CoreApi.Configuration
|
||||
{
|
||||
public interface ICoreApiClientConfiguration
|
||||
{
|
||||
string IDPUrl { get; }
|
||||
string DKTUrl { get; }
|
||||
string PrivateClientId { get; }
|
||||
string PrivateClientSecret { get; }
|
||||
string Scope { get; }
|
||||
string CoreApiIDPUrl { get; }
|
||||
string CoreApiUrl { get; }
|
||||
string CoreApiPrivateClientId { get; }
|
||||
string CoreApiPrivateClientSecret { get; }
|
||||
}
|
||||
}
|
7
Kreta.Client/CoreApi/Constant/GrantType.cs
Normal file
7
Kreta.Client/CoreApi/Constant/GrantType.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.CoreApi.Constant
|
||||
{
|
||||
internal static class GrantType
|
||||
{
|
||||
public const string ClientCredentials = "client_credentials";
|
||||
}
|
||||
}
|
7
Kreta.Client/CoreApi/Constant/Scope.cs
Normal file
7
Kreta.Client/CoreApi/Constant/Scope.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.CoreApi.Constant
|
||||
{
|
||||
internal static class Scope
|
||||
{
|
||||
public const string Private = "kreta-core-webapi.public";
|
||||
}
|
||||
}
|
10
Kreta.Client/CoreApi/Constant/TokenRequest.cs
Normal file
10
Kreta.Client/CoreApi/Constant/TokenRequest.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Kreta.Client.CoreApi.Constant
|
||||
{
|
||||
internal static class TokenRequest
|
||||
{
|
||||
public const string GrantType = "grant_type";
|
||||
public const string ClientId = "client_id";
|
||||
public const string ClientSecret = "client_secret";
|
||||
public const string Scope = "scope";
|
||||
}
|
||||
}
|
366
Kreta.Client/CoreApi/CoreApiClient.cs
Normal file
366
Kreta.Client/CoreApi/CoreApiClient.cs
Normal file
|
@ -0,0 +1,366 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Kreta.Client.ClientBase;
|
||||
using Kreta.Client.ClientBase.Interface;
|
||||
using Kreta.Client.CoreApi.Configuration;
|
||||
using Kreta.Client.CoreApi.Extension;
|
||||
using Kreta.Client.CoreApi.Request;
|
||||
using Kreta.Client.CoreApi.Response;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Exceptions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.CoreApi
|
||||
{
|
||||
internal class CoreApiClient : RestSharpClientBase, ICoreApiClient
|
||||
{
|
||||
private readonly ICoreApiClientConfiguration coreApiClientConfiguration;
|
||||
|
||||
public CoreApiClient(ICoreApiClientConfiguration coreApiClientConfiguration)
|
||||
{
|
||||
this.coreApiClientConfiguration = coreApiClientConfiguration ?? throw new ArgumentNullException(nameof(coreApiClientConfiguration));
|
||||
}
|
||||
|
||||
public DKTFeladatInsertResponse DKTFeladatInsert(DKTFeladatInsertRequest request, int alkalmazottId)
|
||||
{
|
||||
GetTokenResponse token = GetToken();
|
||||
if (token.IsSuccess)
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.DKTUrl;
|
||||
|
||||
string relativeUri = $"/kreta/intezmenyek/alkalmazottak/{alkalmazottId}/orak/hazifeladatok";
|
||||
Dictionary<string, string> headers = token.AccessToken.GetAuthorizationHeaderWithJson(request.IntezmenyGuid, request.TanevSorszam);
|
||||
IRestResult response = Post(relativeUri, headers, body: request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return new DKTFeladatInsertResponse
|
||||
{
|
||||
NewHazifeladatId = int.Parse(response.Result)
|
||||
};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<DKTFeladatInsertResponse>(response.Result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return new DKTFeladatInsertResponse
|
||||
{
|
||||
Exception = new DKTExceptionItem
|
||||
{
|
||||
Message = "Kapcsolódási probléma, kérjük a mentést próbálja meg újra!"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return new DKTFeladatInsertResponse
|
||||
{
|
||||
Exception = new DKTExceptionItem
|
||||
{
|
||||
Message = "Nem sikerült a kapcsolat felépítése DKT-val!"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public DKTFeladatResponse DKTFeladatUpdate(DKTFeladatUpdateRequest request, int alkalmazottId)
|
||||
{
|
||||
GetTokenResponse token = GetToken();
|
||||
if (token.IsSuccess)
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.DKTUrl;
|
||||
|
||||
string relativeUri = $"/kreta/intezmenyek/alkalmazottak/{alkalmazottId}/orak/hazifeladatok/{request.Id}";
|
||||
Dictionary<string, string> headers = token.AccessToken.GetAuthorizationHeaderWithJson(request.IntezmenyGuid, request.TanevSorszam);
|
||||
IRestResult response = Put(relativeUri, headers, body: request);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return new DKTFeladatResponse();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<DKTFeladatResponse>(response.Result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return new DKTFeladatResponse
|
||||
{
|
||||
Exception = new DKTExceptionItem
|
||||
{
|
||||
Message = "Kapcsolódási probléma, kérjük a mentést próbálja meg újra!"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return new DKTFeladatResponse
|
||||
{
|
||||
Exception = new DKTExceptionItem
|
||||
{
|
||||
Message = "Nem sikerült a kapcsolat felépítése DKT-val!"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public DKTFeladatResponse DKTFeladatDelete(DKTFeladatDeleteRequest request)
|
||||
{
|
||||
GetTokenResponse token = GetToken();
|
||||
if (token.IsSuccess)
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.DKTUrl;
|
||||
|
||||
string relativeUri = $"/kreta/intezmenyek/alkalmazottak/{request.AlkalmazottId}/orak/hazifeladatok/{request.Id}";
|
||||
Dictionary<string, string> headers = token.AccessToken.GetAuthorizationHeaderWithJson(request.IntezmenyGuid, request.TanevSorszam);
|
||||
IRestResult response = Delete(relativeUri, headers);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return new DKTFeladatResponse();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<DKTFeladatResponse>(response.Result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return new DKTFeladatResponse
|
||||
{
|
||||
Exception = new DKTExceptionItem
|
||||
{
|
||||
Message = "Kapcsolódási probléma, kérjük a törlést próbálja meg újra!"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return new DKTFeladatResponse
|
||||
{
|
||||
Exception = new DKTExceptionItem
|
||||
{
|
||||
Message = "Nem sikerült a kapcsolat felépítése DKT-val!"
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public EszkozIgenylesCreateResponse EszkozIgenylesInsert(EszkozIgenylesCreateDto request, string intezmenyGuid, int tanevSorszam)
|
||||
{
|
||||
GetTokenResponse token = GetCoreApiToken();
|
||||
if (token.IsSuccess)
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.CoreApiUrl;
|
||||
|
||||
string relativeUri = $"/intezmenyek/EszkozIgenyles";
|
||||
Dictionary<string, string> headers = token.AccessToken.GetAuthorizationHeaderWithJson(intezmenyGuid, tanevSorszam);
|
||||
headers.Add("setting", "true");
|
||||
IRestResult response = Post(relativeUri, headers, body: request);
|
||||
|
||||
try
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return new EszkozIgenylesCreateResponse
|
||||
{
|
||||
NewId = int.Parse(response.Result)
|
||||
};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<EszkozIgenylesCreateResponse>(response.Result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return new EszkozIgenylesCreateResponse
|
||||
{
|
||||
Exception = new CoreApiExceptionItem
|
||||
{
|
||||
Message = "Nem megfelelő response model!"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("IDP nem elérhető!");
|
||||
}
|
||||
|
||||
public CoreApiResponse EszkozIgenylesUpdate(EszkozIgenylesUpdateDto request, string intezmenyGuid, int tanevSorszam)
|
||||
{
|
||||
GetTokenResponse token = GetCoreApiToken();
|
||||
if (token.IsSuccess)
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.CoreApiUrl;
|
||||
|
||||
string relativeUri = $"/intezmenyek/EszkozIgenyles/" + request.Id.ToString();
|
||||
Dictionary<string, string> headers = token.AccessToken.GetAuthorizationHeaderWithJson(intezmenyGuid, tanevSorszam);
|
||||
headers.Add("setting", "true");
|
||||
IRestResult response = Put(relativeUri, headers, body: request);
|
||||
|
||||
try
|
||||
{
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return new CoreApiResponse();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<CoreApiResponse>(response.Result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return new CoreApiResponse
|
||||
{
|
||||
Exception = new CoreApiExceptionItem
|
||||
{
|
||||
Message = "Nem megfelelő response model!"
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("IDP nem elérhető!");
|
||||
}
|
||||
|
||||
public List<EszkozIgenylesDto> EszkozIgenylesGet(string intezmenyGuid, int tanevSorszam)
|
||||
{
|
||||
GetTokenResponse token = GetCoreApiToken();
|
||||
if (token.IsSuccess)
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.CoreApiUrl;
|
||||
|
||||
string relativeUri = $"/intezmenyek/EszkozIgenyles";
|
||||
Dictionary<string, string> headers = token.AccessToken.GetAuthorizationHeaderWithJson(intezmenyGuid, tanevSorszam);
|
||||
IRestResult response = Get(relativeUri, headers);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<EszkozIgenylesDto>>(response.Result,
|
||||
new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
var ex = new Exception(response.Result, e);
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Szolgáltatás nem elérhető!");
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("IDP nem elérhető!");
|
||||
}
|
||||
|
||||
public GetTokenResponse GetToken()
|
||||
{
|
||||
GetTokenResponse result = GetToken(coreApiClientConfiguration.GetPrivateTokenRequestParameters());
|
||||
return result;
|
||||
}
|
||||
|
||||
private GetTokenResponse GetToken(Dictionary<string, string> tokenRequestParameters)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.IDPUrl;
|
||||
|
||||
string relativeUri = "/connect/token";
|
||||
Dictionary<string, string> headers = HeaderExtension.GetFormUrlEncodedHeader();
|
||||
IRestResult response = Post(relativeUri, headers, tokenRequestParameters);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
GetTokenSuccessResponse successResponse = JsonConvert.DeserializeObject<GetTokenSuccessResponse>(response.Result);
|
||||
return new GetTokenResponse(successResponse.AccessToken, successResponse.ExpiresIn);
|
||||
}
|
||||
|
||||
GetTokenFailureResponse failureResponse = JsonConvert.DeserializeObject<GetTokenFailureResponse>(response.Result);
|
||||
return new GetTokenResponse(failureResponse.Error);
|
||||
});
|
||||
}
|
||||
|
||||
public GetTokenResponse GetCoreApiToken()
|
||||
{
|
||||
GetTokenResponse result = GetCoreApiToken(coreApiClientConfiguration.GetCoreApiPrivateTokenRequestParameters());
|
||||
return result;
|
||||
}
|
||||
|
||||
private GetTokenResponse GetCoreApiToken(Dictionary<string, string> tokenRequestParameters)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = coreApiClientConfiguration.CoreApiIDPUrl;
|
||||
|
||||
string relativeUri = "/connect/token";
|
||||
Dictionary<string, string> headers = HeaderExtension.GetFormUrlEncodedHeader();
|
||||
IRestResult response = Post(relativeUri, headers, tokenRequestParameters);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
GetTokenSuccessResponse successResponse = JsonConvert.DeserializeObject<GetTokenSuccessResponse>(response.Result);
|
||||
return new GetTokenResponse(successResponse.AccessToken, successResponse.ExpiresIn);
|
||||
}
|
||||
|
||||
GetTokenFailureResponse failureResponse = JsonConvert.DeserializeObject<GetTokenFailureResponse>(response.Result);
|
||||
return new GetTokenResponse(failureResponse.Error);
|
||||
});
|
||||
}
|
||||
|
||||
private T ExceptionLogger<T>(Func<T> action) where T : IResponse, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return action();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return (T)Activator.CreateInstance(typeof(T), ExceptionUtil.ExceptionToString(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Client.CoreApi.Configuration;
|
||||
using Kreta.Client.CoreApi.Constant;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Extension
|
||||
{
|
||||
internal static class CoreApiClientConfigurationExtension
|
||||
{
|
||||
public static Dictionary<string, string> GetPrivateTokenRequestParameters(this ICoreApiClientConfiguration coreApiClientConfiguration)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ TokenRequest.GrantType, GrantType.ClientCredentials },
|
||||
{ TokenRequest.ClientId, coreApiClientConfiguration.PrivateClientId },
|
||||
{ TokenRequest.ClientSecret, coreApiClientConfiguration.PrivateClientSecret },
|
||||
{ TokenRequest.Scope, coreApiClientConfiguration.Scope },
|
||||
};
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetCoreApiPrivateTokenRequestParameters(this ICoreApiClientConfiguration coreApiClientConfiguration)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ TokenRequest.GrantType, GrantType.ClientCredentials },
|
||||
{ TokenRequest.ClientId, coreApiClientConfiguration.CoreApiPrivateClientId },
|
||||
{ TokenRequest.ClientSecret, coreApiClientConfiguration.CoreApiPrivateClientSecret }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
29
Kreta.Client/CoreApi/Extension/HeaderExtension.cs
Normal file
29
Kreta.Client/CoreApi/Extension/HeaderExtension.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Extension
|
||||
{
|
||||
internal static class HeaderExtension
|
||||
{
|
||||
public static Dictionary<string, string> GetAuthorizationHeaderWithMulitpartFrom(this string token)
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "multipart/form-data" },
|
||||
{ "Authorization", $"Bearer {token}" },
|
||||
};
|
||||
|
||||
public static Dictionary<string, string> GetAuthorizationHeaderWithJson(this string token, string intezmenyGuid, int tanevId)
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Authorization", $"Bearer {token}" },
|
||||
{ "IntezmenyId", $"{intezmenyGuid}" },
|
||||
{ "TanevId", $"{tanevId}" },
|
||||
};
|
||||
|
||||
public static Dictionary<string, string> GetFormUrlEncodedHeader()
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "application/x-www-form-urlencoded" },
|
||||
};
|
||||
}
|
||||
}
|
16
Kreta.Client/CoreApi/ICoreApiClient.cs
Normal file
16
Kreta.Client/CoreApi/ICoreApiClient.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Client.CoreApi.Request;
|
||||
using Kreta.Client.CoreApi.Response;
|
||||
|
||||
namespace Kreta.Client.CoreApi
|
||||
{
|
||||
public interface ICoreApiClient
|
||||
{
|
||||
DKTFeladatInsertResponse DKTFeladatInsert(DKTFeladatInsertRequest dktFeladatDeleteRequest, int alkalmazottId);
|
||||
DKTFeladatResponse DKTFeladatUpdate(DKTFeladatUpdateRequest dktFeladatDeleteRequest, int alkalmazottId);
|
||||
DKTFeladatResponse DKTFeladatDelete(DKTFeladatDeleteRequest dktFeladatDeleteRequest);
|
||||
EszkozIgenylesCreateResponse EszkozIgenylesInsert(EszkozIgenylesCreateDto request, string intezmenyGuid, int tanevSorszam);
|
||||
CoreApiResponse EszkozIgenylesUpdate(EszkozIgenylesUpdateDto request, string intezmenyGuid, int tanevSorszam);
|
||||
List<EszkozIgenylesDto> EszkozIgenylesGet(string intezmenyGuid, int tanevSorszam);
|
||||
}
|
||||
}
|
13
Kreta.Client/CoreApi/Request/DKTFeladatDeleteRequest.cs
Normal file
13
Kreta.Client/CoreApi/Request/DKTFeladatDeleteRequest.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Kreta.Client.CoreApi.Request
|
||||
{
|
||||
public class DKTFeladatDeleteRequest
|
||||
{
|
||||
public string IntezmenyGuid { get; set; }
|
||||
|
||||
public int TanevSorszam { get; set; }
|
||||
|
||||
public int AlkalmazottId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
29
Kreta.Client/CoreApi/Request/DKTFeladatInsertRequest.cs
Normal file
29
Kreta.Client/CoreApi/Request/DKTFeladatInsertRequest.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Request
|
||||
{
|
||||
public class DKTFeladatInsertRequest
|
||||
{
|
||||
public string IntezmenyGuid { get; set; }
|
||||
|
||||
public int TanevSorszam { get; set; }
|
||||
|
||||
public int AlkalmazottId { get; set; }
|
||||
|
||||
public int TantargyId { get; set; }
|
||||
|
||||
public int? OsztalyId { get; set; }
|
||||
|
||||
public int? CsoportId { get; set; }
|
||||
|
||||
public DateTime OraDatum { get; set; }
|
||||
|
||||
public int? Oraszam { get; set; }
|
||||
|
||||
public DateTime? OraIdopont { get; set; }
|
||||
|
||||
public DateTime BeadasHatarido { get; set; }
|
||||
|
||||
public string Szoveg { get; set; }
|
||||
}
|
||||
}
|
19
Kreta.Client/CoreApi/Request/DKTFeladatUpdateRequest.cs
Normal file
19
Kreta.Client/CoreApi/Request/DKTFeladatUpdateRequest.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Request
|
||||
{
|
||||
public class DKTFeladatUpdateRequest
|
||||
{
|
||||
public string IntezmenyGuid { get; set; }
|
||||
|
||||
public int TanevSorszam { get; set; }
|
||||
|
||||
public int AlkalmazottId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime BeadasHatarido { get; set; }
|
||||
|
||||
public string Szoveg { get; set; }
|
||||
}
|
||||
}
|
34
Kreta.Client/CoreApi/Response/CoreApiResponse.cs
Normal file
34
Kreta.Client/CoreApi/Response/CoreApiResponse.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class CoreApiResponse
|
||||
{
|
||||
public CoreApiExceptionItem Exception { get; set; }
|
||||
public CoreApiValidationResult ValidationResult { get; set; }
|
||||
|
||||
public string CorrelationId { get; set; }
|
||||
}
|
||||
|
||||
public class CoreApiValidationResult
|
||||
{
|
||||
public List<CoreApiValidationItem> Errors { get; set; } = new List<CoreApiValidationItem>();
|
||||
public List<CoreApiValidationItem> Warnings { get; set; } = new List<CoreApiValidationItem>();
|
||||
public List<CoreApiValidationItem> Successes { get; set; } = new List<CoreApiValidationItem>();
|
||||
}
|
||||
|
||||
public class CoreApiExceptionItem
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string StackTrace { get; set; }
|
||||
}
|
||||
|
||||
public class CoreApiValidationItem
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string PropertyName { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string TextValue { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class DKTFeladatInsertResponse : DKTFeladatResponse
|
||||
{
|
||||
public int NewHazifeladatId { get; set; }
|
||||
}
|
||||
}
|
35
Kreta.Client/CoreApi/Response/DKTFeladatResponse.cs
Normal file
35
Kreta.Client/CoreApi/Response/DKTFeladatResponse.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class DKTFeladatResponse
|
||||
{
|
||||
public string CorrelationId { get; set; }
|
||||
public DKTExceptionItem Exception { get; set; }
|
||||
public DKTValidationResult ValidationResult { get; set; }
|
||||
public int Status { get; set; }
|
||||
public Dictionary<string, string[]> Errors { get; set; }
|
||||
public string Instance { get; set; }
|
||||
}
|
||||
|
||||
public class DKTValidationResult
|
||||
{
|
||||
public List<DKTValidationItem> Tiltasok { get; set; } = new List<DKTValidationItem>();
|
||||
public List<DKTValidationItem> Figyelmeztetesek { get; set; } = new List<DKTValidationItem>();
|
||||
public List<DKTValidationItem> Engedelyezettek { get; set; } = new List<DKTValidationItem>();
|
||||
}
|
||||
|
||||
public class DKTExceptionItem
|
||||
{
|
||||
public string Type { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string StackTrace { get; set; }
|
||||
}
|
||||
|
||||
public class DKTValidationItem
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Nev { get; set; }
|
||||
public string Uzenet { get; set; }
|
||||
}
|
||||
}
|
19
Kreta.Client/CoreApi/Response/EszkozIgenylesCreateDto.cs
Normal file
19
Kreta.Client/CoreApi/Response/EszkozIgenylesCreateDto.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class EszkozIgenylesCreateDto
|
||||
{
|
||||
public int? AlkalmazottId { get; set; }
|
||||
|
||||
public int? TanuloId { get; set; }
|
||||
|
||||
public int? GondviseloId { get; set; }
|
||||
|
||||
public bool EszkozKiosztva { get; set; }
|
||||
|
||||
public bool ElfogadottAszf { get; set; }
|
||||
|
||||
public DateTime? AszfElfogadasIdeje { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class EszkozIgenylesCreateResponse : CoreApiResponse
|
||||
{
|
||||
public int NewId { get; set; }
|
||||
}
|
||||
}
|
19
Kreta.Client/CoreApi/Response/EszkozIgenylesDto.cs
Normal file
19
Kreta.Client/CoreApi/Response/EszkozIgenylesDto.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class EszkozIgenylesDto
|
||||
{
|
||||
public int? AlkalmazottId { get; set; }
|
||||
|
||||
public int? TanuloId { get; set; }
|
||||
|
||||
public int? GondviseloId { get; set; }
|
||||
|
||||
public bool EszkozKiosztva { get; set; }
|
||||
|
||||
public bool ElfogadottAszf { get; set; }
|
||||
|
||||
public DateTime? AszfElfogadasIdeje { get; set; }
|
||||
}
|
||||
}
|
21
Kreta.Client/CoreApi/Response/EszkozIgenylesUpdateDto.cs
Normal file
21
Kreta.Client/CoreApi/Response/EszkozIgenylesUpdateDto.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class EszkozIgenylesUpdateDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int? AlkalmazottId { get; set; }
|
||||
|
||||
public int? TanuloId { get; set; }
|
||||
|
||||
public int? GondviseloId { get; set; }
|
||||
|
||||
public bool EszkozKiosztva { get; set; }
|
||||
|
||||
public bool ElfogadottAszf { get; set; }
|
||||
|
||||
public DateTime? AszfElfogadasIdeje { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
internal class GetTokenFailureResponse
|
||||
{
|
||||
[JsonProperty("error")]
|
||||
public string Error { get; set; }
|
||||
}
|
||||
}
|
46
Kreta.Client/CoreApi/Response/GetToken/GetTokenResponse.cs
Normal file
46
Kreta.Client/CoreApi/Response/GetToken/GetTokenResponse.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
public class GetTokenResponse : IResponse
|
||||
{
|
||||
public GetTokenResponse() { }
|
||||
|
||||
public GetTokenResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public GetTokenResponse(string accessToken, int expiresIn)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(accessToken));
|
||||
}
|
||||
|
||||
if (expiresIn < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(expiresIn));
|
||||
}
|
||||
|
||||
IsSuccess = true;
|
||||
AccessToken = accessToken;
|
||||
ExpiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public string AccessToken { get; }
|
||||
|
||||
public int ExpiresIn { get; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
internal class GetTokenSuccessResponse
|
||||
{
|
||||
[JsonProperty(PropertyName = "access_token")]
|
||||
public string AccessToken { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "expires_in")]
|
||||
public int ExpiresIn { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "token_type")]
|
||||
public string TokenType { get; set; }
|
||||
}
|
||||
}
|
9
Kreta.Client/CoreApi/Response/IResponse.cs
Normal file
9
Kreta.Client/CoreApi/Response/IResponse.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace Kreta.Client.CoreApi.Response
|
||||
{
|
||||
internal interface IResponse
|
||||
{
|
||||
bool IsSuccess { get; }
|
||||
|
||||
string Error { get; }
|
||||
}
|
||||
}
|
57
Kreta.Client/DependencyInjection.cs
Normal file
57
Kreta.Client/DependencyInjection.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System.Configuration;
|
||||
using Kreta.Client.CoreApi;
|
||||
using Kreta.Client.CoreApi.Configuration;
|
||||
using Kreta.Client.FileService;
|
||||
using Kreta.Client.FileService.Configuration;
|
||||
using Kreta.Client.Jira;
|
||||
using Kreta.Client.Jira.Interface;
|
||||
using Kreta.Client.KGR;
|
||||
using Kreta.Client.KozpontiKreta;
|
||||
using Kreta.Client.KozpontiKreta.Interface;
|
||||
using Kreta.Client.Leltar;
|
||||
using Kreta.Client.SzirApi;
|
||||
using Kreta.Core;
|
||||
using Kreta.Core.Configuratiaton;
|
||||
using Kreta.Core.Configuratiaton.Interface;
|
||||
using SimpleInjector;
|
||||
|
||||
namespace Kreta.Client
|
||||
{
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static void InjectClient(this Container container)
|
||||
{
|
||||
container.Register<IUgyfelszolgalatConfig>(() => (UgyfelszolgalatConfig)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.UgyfelszolgalatConfig), Lifestyle.Singleton);
|
||||
container.Register<IKozpontiKretaConfiguration>(() => (KozpontiKretaConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.KozpontiKretaConfig), Lifestyle.Singleton);
|
||||
container.Register<IFileServiceClientConfiguration>(() => (FileServiceClientConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.FileServiceClientConfiguration), Lifestyle.Singleton);
|
||||
|
||||
container.Register<IJiraClient, JiraClient>(Lifestyle.Scoped);
|
||||
container.Register<IKozpontiKretaClient, KozpontiKretaClient>(Lifestyle.Scoped);
|
||||
container.Register<IFileServiceClient, FileServiceClient>(Lifestyle.Scoped);
|
||||
container.Register<IFileServiceClientV3, FileServiceClientV3>(Lifestyle.Scoped);
|
||||
container.Register<ICoreApiClient, CoreApiClient>(Lifestyle.Scoped);
|
||||
container.Register<IKGRClient, KGRClient>(Lifestyle.Scoped);
|
||||
container.Register<ILeltarClient, LeltarClient>(Lifestyle.Scoped);
|
||||
container.Register<ISzirApiClient, SzirApiClient>(Lifestyle.Scoped);
|
||||
}
|
||||
|
||||
public static void InjectMobileClient(this Container container)
|
||||
{
|
||||
container.Register<IFileServiceClientConfiguration>(() => (FileServiceClientConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.FileServiceClientConfiguration), Lifestyle.Singleton);
|
||||
container.Register<IFileServiceClient, FileServiceClient>(Lifestyle.Scoped);
|
||||
container.Register<IFileServiceClientV3, FileServiceClientV3>(Lifestyle.Scoped);
|
||||
container.Register<ILepConfiguration>(()
|
||||
=> (LepConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.LEPKozpontiKretaConfig), Lifestyle.Singleton);
|
||||
}
|
||||
|
||||
public static void InjectNaploMobileClient(this Container container)
|
||||
{
|
||||
container.Register<ICoreApiClientConfiguration>(() => (CoreApiClientConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.CoreApiClientConfiguration), Lifestyle.Singleton);
|
||||
container.Register<IFileServiceClientConfiguration>(() => (FileServiceClientConfiguration)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.FileServiceClientConfiguration), Lifestyle.Singleton);
|
||||
|
||||
container.Register<IFileServiceClient, FileServiceClient>(Lifestyle.Scoped);
|
||||
container.Register<IFileServiceClientV3, FileServiceClientV3>(Lifestyle.Scoped);
|
||||
container.Register<ICoreApiClient, CoreApiClient>(Lifestyle.Scoped);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System.Configuration;
|
||||
|
||||
namespace Kreta.Client.Eugyintezes.Configuration
|
||||
{
|
||||
public class EugyintezesClientConfiguration : ConfigurationSection, IEugyintezesClientConfiguration
|
||||
{
|
||||
[ConfigurationProperty(nameof(BaseUrl), IsRequired = true)]
|
||||
public string BaseUrl => (string)base[nameof(BaseUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(ApiKey), IsRequired = true)]
|
||||
public string ApiKey => (string)base[nameof(ApiKey)];
|
||||
|
||||
[ConfigurationProperty(nameof(IsUzenetekEnable), IsRequired = true)]
|
||||
public bool IsUzenetekEnable => (bool)base[nameof(IsUzenetekEnable)];
|
||||
|
||||
[ConfigurationProperty(nameof(UzenetekFrequencyRate), IsRequired = true)]
|
||||
public int UzenetekFrequencyRate => (int)base[nameof(UzenetekFrequencyRate)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
namespace Kreta.Client.Eugyintezes.Configuration
|
||||
{
|
||||
public interface IEugyintezesClientConfiguration
|
||||
{
|
||||
string BaseUrl { get; }
|
||||
|
||||
string ApiKey { get; }
|
||||
|
||||
bool IsUzenetekEnable { get; }
|
||||
|
||||
int UzenetekFrequencyRate { get; }
|
||||
}
|
||||
}
|
206
Kreta.Client/Eugyintezes/EugyintezesClient.cs
Normal file
206
Kreta.Client/Eugyintezes/EugyintezesClient.cs
Normal file
|
@ -0,0 +1,206 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Cache;
|
||||
using Kreta.Client.Eugyintezes.Configuration;
|
||||
using RestSharp;
|
||||
|
||||
namespace Kreta.Client.Eugyintezes
|
||||
{
|
||||
public class EugyintezesClient : IEugyintezesClient
|
||||
{
|
||||
private IEugyintezesClientConfiguration EugyintezesClientConfiguration { get; }
|
||||
|
||||
public EugyintezesClient(IEugyintezesClientConfiguration EugyintezesClientConfiguration)
|
||||
{
|
||||
this.EugyintezesClientConfiguration = EugyintezesClientConfiguration ?? throw new ArgumentNullException(nameof(EugyintezesClientConfiguration));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(EugyintezesClientConfiguration.BaseUrl))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(EugyintezesClientConfiguration.BaseUrl));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(EugyintezesClientConfiguration.ApiKey))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(EugyintezesClientConfiguration.ApiKey));
|
||||
}
|
||||
}
|
||||
|
||||
public IRestResponse RestSharpPostBody(string url, string jsonData)
|
||||
{
|
||||
var client = new RestClient(url)
|
||||
{
|
||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
|
||||
};
|
||||
|
||||
var request = new RestRequest(Method.POST);
|
||||
|
||||
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.AddHeader("X-API-Key", EugyintezesClientConfiguration.ApiKey);
|
||||
request.AddParameter("application/json", jsonData, ParameterType.RequestBody);
|
||||
|
||||
return client.Execute(request);
|
||||
}
|
||||
|
||||
public IRestResponse RestSharpGetQueryString(string url, Dictionary<string, string> queryParams = null)
|
||||
{
|
||||
var client = new RestClient(url)
|
||||
{
|
||||
CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
|
||||
};
|
||||
|
||||
var request = new RestRequest(Method.GET);
|
||||
|
||||
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
request.AddHeader("X-API-Key", EugyintezesClientConfiguration.ApiKey);
|
||||
|
||||
if (queryParams != null)
|
||||
{
|
||||
foreach (var item in queryParams)
|
||||
{
|
||||
request.AddQueryParameter(item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return client.Execute(request);
|
||||
}
|
||||
|
||||
public string GetBAIPreCheck(string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + "/integration-kreta-api/v1/ugy/statuszok2";
|
||||
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult.Content;
|
||||
}
|
||||
|
||||
public string PostBAIHatarozatok(string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + "/integration-kreta-api/v1/ugy/sendbaihatarozatadatok";
|
||||
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult.Content;
|
||||
}
|
||||
|
||||
public int GetOlvasatlanPostaladaElemekSzama(string intezmenyAzonosito, Guid felhasznaloIdpEgyediAzonosito)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/intezmenyek/{intezmenyAzonosito}/uzenetek/olvasatlanokszama";
|
||||
var queryParams = new Dictionary<string, string>
|
||||
{
|
||||
{ nameof(felhasznaloIdpEgyediAzonosito), felhasznaloIdpEgyediAzonosito.ToString() }
|
||||
};
|
||||
|
||||
var apiResult = RestSharpGetQueryString(url, queryParams);
|
||||
if (apiResult.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
int.TryParse(apiResult.Content, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch { return result; }
|
||||
}
|
||||
|
||||
public bool GetUzenetkezelesElerheto(string intezmenyAzonosito)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/intezmenyek/{intezmenyAzonosito}/uzenetkezelesElerheto";
|
||||
|
||||
var apiResult = RestSharpGetQueryString(url);
|
||||
if (apiResult.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
bool.TryParse(apiResult.Content, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch { return result; }
|
||||
}
|
||||
|
||||
public string PostTeremBerbeadhatoStatuszValtozas(string postData, string intezmenyAzonosito)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/intezmenyek/{intezmenyAzonosito}/foglalhatotermek/statuszvaltozas";
|
||||
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult.Content;
|
||||
}
|
||||
|
||||
public string PostTanuloOsztalyBesorolasStatuszValtozas(string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + "/integration-kreta-api/v1/tanulok/osztalyvaltozas";
|
||||
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult.Content;
|
||||
}
|
||||
|
||||
public string GetUzenetek(string intezmenyAzonosito, Guid felhasznaloIdpEgyediAzonosito, int sorokSzamaMax)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/intezmenyek/{intezmenyAzonosito}/uzenetek";
|
||||
var queryParams = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(felhasznaloIdpEgyediAzonosito), felhasznaloIdpEgyediAzonosito.ToString() },
|
||||
{ nameof(sorokSzamaMax), sorokSzamaMax.ToString() }
|
||||
};
|
||||
|
||||
var apiResult = RestSharpGetQueryString(url, queryParams);
|
||||
|
||||
if (apiResult.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return apiResult.Content;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetUgyek(string intezmenyAzonosito, Guid felhasznaloIdpEgyediAzonosito, int sorokSzamaMax)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/intezmenyek/{intezmenyAzonosito}/felhasznalougyek";
|
||||
var queryParams = new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(felhasznaloIdpEgyediAzonosito), felhasznaloIdpEgyediAzonosito.ToString() },
|
||||
{ nameof(sorokSzamaMax), sorokSzamaMax.ToString() }
|
||||
};
|
||||
|
||||
var apiResult = RestSharpGetQueryString(url, queryParams);
|
||||
|
||||
if (apiResult.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return apiResult.Content;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public IRestResponse NebuloInsert(string kretaIntezmenyAzonosito, string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/ugy/bai/{kretaIntezmenyAzonosito}/nebulok";
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public IRestResponse NebuloStatuszUpdate(string kretaIntezmenyAzonosito, string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/ugy/bai/{kretaIntezmenyAzonosito}/nebulok/statuszmodositas";
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public IRestResponse NebuloDataUpdate(string kretaIntezmenyAzonosito, string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/ugy/bai/{kretaIntezmenyAzonosito}/nebulok/modositas";
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
public IRestResponse NebuloDelete(string kretaIntezmenyAzonosito, string postData)
|
||||
{
|
||||
var url = EugyintezesClientConfiguration.BaseUrl + $"/integration-kreta-api/v1/ugy/bai/{kretaIntezmenyAzonosito}/nebulok/torles";
|
||||
var apiResult = RestSharpPostBody(url, postData);
|
||||
return apiResult;
|
||||
}
|
||||
}
|
||||
}
|
7
Kreta.Client/Eugyintezes/IEugyintezesClient.cs
Normal file
7
Kreta.Client/Eugyintezes/IEugyintezesClient.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.Eugyintezes
|
||||
{
|
||||
public interface IEugyintezesClient
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using System.Configuration;
|
||||
|
||||
namespace Kreta.Client.FileService.Configuration
|
||||
{
|
||||
public class FileServiceClientConfiguration : ConfigurationSection, IFileServiceClientConfiguration
|
||||
{
|
||||
[ConfigurationProperty(nameof(IDPUrl), IsRequired = true)]
|
||||
public string IDPUrl => (string)base[nameof(IDPUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(FileUploadUrl), IsRequired = true)]
|
||||
public string FileUploadUrl => (string)base[nameof(FileUploadUrl)];
|
||||
|
||||
[ConfigurationProperty(nameof(PublicClientId), IsRequired = true)]
|
||||
public string PublicClientId => (string)base[nameof(PublicClientId)];
|
||||
|
||||
[ConfigurationProperty(nameof(PublicClientSecret), IsRequired = true)]
|
||||
public string PublicClientSecret => (string)base[nameof(PublicClientSecret)];
|
||||
|
||||
[ConfigurationProperty(nameof(PrivateClientId), IsRequired = true)]
|
||||
public string PrivateClientId => (string)base[nameof(PrivateClientId)];
|
||||
|
||||
[ConfigurationProperty(nameof(PrivateClientSecret), IsRequired = true)]
|
||||
public string PrivateClientSecret => (string)base[nameof(PrivateClientSecret)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
namespace Kreta.Client.FileService.Configuration
|
||||
{
|
||||
public interface IFileServiceClientConfiguration
|
||||
{
|
||||
string IDPUrl { get; }
|
||||
|
||||
string FileUploadUrl { get; }
|
||||
|
||||
string PublicClientId { get; }
|
||||
|
||||
string PublicClientSecret { get; }
|
||||
|
||||
string PrivateClientId { get; }
|
||||
|
||||
string PrivateClientSecret { get; }
|
||||
}
|
||||
}
|
16
Kreta.Client/FileService/Constant/DownloadRequest.cs
Normal file
16
Kreta.Client/FileService/Constant/DownloadRequest.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
namespace Kreta.Client.FileService.Constant
|
||||
{
|
||||
internal static class DownloadRequest
|
||||
{
|
||||
public const string Konyvtar = "konyvtar";
|
||||
|
||||
public const string FajlAzonosito = "fajlAzonosito";
|
||||
|
||||
public const string FajlId = "FajlId";
|
||||
public const string UtvonalV3 = "Utvonal";
|
||||
|
||||
public const string Utvonal = "utvonal";
|
||||
|
||||
public const string FajlNev = "fajlNev";
|
||||
}
|
||||
}
|
7
Kreta.Client/FileService/Constant/Folder.cs
Normal file
7
Kreta.Client/FileService/Constant/Folder.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.FileService.Constant
|
||||
{
|
||||
internal static class Folder
|
||||
{
|
||||
public const string HaziFeladatok = "HaziFeladatok";
|
||||
}
|
||||
}
|
7
Kreta.Client/FileService/Constant/GrantType.cs
Normal file
7
Kreta.Client/FileService/Constant/GrantType.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Kreta.Client.FileService.Constant
|
||||
{
|
||||
internal static class GrantType
|
||||
{
|
||||
public const string ClientCredentials = "client_credentials";
|
||||
}
|
||||
}
|
9
Kreta.Client/FileService/Constant/Scope.cs
Normal file
9
Kreta.Client/FileService/Constant/Scope.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace Kreta.Client.FileService.Constant
|
||||
{
|
||||
internal static class Scope
|
||||
{
|
||||
public const string Public = "kreta-fileservice-webapi.public";
|
||||
|
||||
public const string Private = "kreta-fileservice-webapi.private";
|
||||
}
|
||||
}
|
13
Kreta.Client/FileService/Constant/TokenRequest.cs
Normal file
13
Kreta.Client/FileService/Constant/TokenRequest.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Kreta.Client.FileService.Constant
|
||||
{
|
||||
internal static class TokenRequest
|
||||
{
|
||||
public const string GrantType = "grant_type";
|
||||
|
||||
public const string ClientId = "client_id";
|
||||
|
||||
public const string ClientSecret = "client_secret";
|
||||
|
||||
public const string Scope = "scope";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Client.FileService.Configuration;
|
||||
using Kreta.Client.FileService.Constant;
|
||||
|
||||
namespace Kreta.Client.FileService.Extension
|
||||
{
|
||||
internal static class FileServiceClientConfigurationExtension
|
||||
{
|
||||
public static Dictionary<string, string> GetPublicTokenRequestParameters(this IFileServiceClientConfiguration fileServiceClientConfiguration)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ TokenRequest.GrantType, GrantType.ClientCredentials },
|
||||
{ TokenRequest.ClientId, fileServiceClientConfiguration.PublicClientId },
|
||||
{ TokenRequest.ClientSecret, fileServiceClientConfiguration.PublicClientSecret },
|
||||
{ TokenRequest.Scope, Scope.Public },
|
||||
};
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetPrivateTokenRequestParameters(this IFileServiceClientConfiguration fileServiceClientConfiguration)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ TokenRequest.GrantType, GrantType.ClientCredentials },
|
||||
{ TokenRequest.ClientId, fileServiceClientConfiguration.PrivateClientId },
|
||||
{ TokenRequest.ClientSecret, fileServiceClientConfiguration.PrivateClientSecret },
|
||||
{ TokenRequest.Scope, Scope.Private },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
29
Kreta.Client/FileService/Extension/GetUrlRequestExtension.cs
Normal file
29
Kreta.Client/FileService/Extension/GetUrlRequestExtension.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Client.FileService.Constant;
|
||||
using Kreta.Client.FileService.Request;
|
||||
|
||||
namespace Kreta.Client.FileService.Extension
|
||||
{
|
||||
internal static class GetUrlRequestExtension
|
||||
{
|
||||
public static Dictionary<string, string> GetUrlRequestParameters(this GetUrlRequest getUrlRequest)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ DownloadRequest.Konyvtar, getUrlRequest.Konyvtar },
|
||||
{ DownloadRequest.FajlAzonosito, getUrlRequest.FajlAzonosito.ToString() },
|
||||
{ DownloadRequest.Utvonal, getUrlRequest.Utvonal },
|
||||
{ DownloadRequest.FajlNev, getUrlRequest.FajlNev }
|
||||
};
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetUrlRequestParametersV3(this GetUrlRequest getUrlRequest)
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ DownloadRequest.FajlId, getUrlRequest.FajlAzonosito.ToString() },
|
||||
{ DownloadRequest.UtvonalV3, getUrlRequest.Utvonal }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
27
Kreta.Client/FileService/Extension/HeaderExtension.cs
Normal file
27
Kreta.Client/FileService/Extension/HeaderExtension.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.FileService.Extension
|
||||
{
|
||||
internal static class HeaderExtension
|
||||
{
|
||||
public static Dictionary<string, string> GetAuthorizationHeaderWithMulitpartFrom(this string token)
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "multipart/form-data" },
|
||||
{ "Authorization", $"Bearer {token}" },
|
||||
};
|
||||
|
||||
public static Dictionary<string, string> GetAuthorizationHeaderWithJson(this string token)
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Authorization", $"Bearer {token}" },
|
||||
};
|
||||
|
||||
public static Dictionary<string, string> GetFormUrlEncodedHeader()
|
||||
=> new Dictionary<string, string>
|
||||
{
|
||||
{ "Content-Type", "application/x-www-form-urlencoded" },
|
||||
};
|
||||
}
|
||||
}
|
197
Kreta.Client/FileService/FileServiceClient.cs
Normal file
197
Kreta.Client/FileService/FileServiceClient.cs
Normal file
|
@ -0,0 +1,197 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Kreta.Client.ClientBase;
|
||||
using Kreta.Client.FileService.Configuration;
|
||||
using Kreta.Client.FileService.Extension;
|
||||
using Kreta.Client.FileService.Request;
|
||||
using Kreta.Client.FileService.Response;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Exceptions;
|
||||
using Kreta.Resources;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService
|
||||
{
|
||||
internal class FileServiceClient : RestSharpClientBase, IFileServiceClient
|
||||
{
|
||||
private readonly IFileServiceClientConfiguration fileServiceClientConfiguration;
|
||||
|
||||
public FileServiceClient(IFileServiceClientConfiguration fileServiceClientConfiguration)
|
||||
{
|
||||
this.fileServiceClientConfiguration = fileServiceClientConfiguration ?? throw new ArgumentNullException(nameof(fileServiceClientConfiguration));
|
||||
}
|
||||
|
||||
public GetTokenResponse GetPublicToken()
|
||||
{
|
||||
return GetToken(fileServiceClientConfiguration.GetPublicTokenRequestParameters());
|
||||
}
|
||||
|
||||
public GetTokenResponse GetPrivateToken()
|
||||
{
|
||||
return GetToken(fileServiceClientConfiguration.GetPrivateTokenRequestParameters());
|
||||
}
|
||||
|
||||
public FileUploadResponse Upload(string publicToken, IFileUploadRequest fileUploadRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var relativeUri = "/ideiglenesfajlok";
|
||||
|
||||
var response = Post(relativeUri, publicToken.GetAuthorizationHeaderWithMulitpartFrom(), fileList: new List<Jira.Model.Request.File>
|
||||
{
|
||||
new Jira.Model.Request.File
|
||||
{
|
||||
Name = "fajl",
|
||||
FileName = fileUploadRequest.FileName,
|
||||
Content = fileUploadRequest.Content,
|
||||
ContentType = fileUploadRequest.ContentType,
|
||||
}
|
||||
});
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new FileUploadResponse(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var successResponse = JsonConvert.DeserializeObject<FileUploadSuccessResponse>(response.Result);
|
||||
|
||||
return new FileUploadResponse(successResponse.FajlAzonosito, successResponse.Utvonal, successResponse.FajlMeretByteLength);
|
||||
}
|
||||
|
||||
var failureResponse = JsonConvert.DeserializeObject<FileUploadFailureResponse>(response.Result);
|
||||
|
||||
return new FileUploadResponse(failureResponse.Uzenet);
|
||||
});
|
||||
}
|
||||
|
||||
public FileFinalizeResponse Finalize(string intezmenyAzonosito, string privateToken, FileFinalizeRequest fileFinalizeRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var relativeUri = $"/fajlok/{intezmenyAzonosito}";
|
||||
|
||||
var response = Post(relativeUri, privateToken.GetAuthorizationHeaderWithJson(), body: fileFinalizeRequest);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new FileFinalizeResponse(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var internalResponse = JsonConvert.DeserializeObject<InternalFileFinalizeResponse>(response.Result);
|
||||
|
||||
if (internalResponse.IsSikeres)
|
||||
{
|
||||
return new FileFinalizeResponse();
|
||||
}
|
||||
|
||||
var errormessage = string.Join(", ", internalResponse.Fajlok.Where(x => !string.IsNullOrWhiteSpace(x.HibaSzoveg)).Select(x => x.HibaSzoveg));
|
||||
|
||||
errormessage = !string.IsNullOrWhiteSpace(errormessage) ? errormessage : internalResponse.HibaSzoveg;
|
||||
|
||||
return new FileFinalizeResponse(errormessage);
|
||||
}
|
||||
|
||||
return new FileFinalizeResponse(ErrorResource.IsmeretlenHibaTortent);
|
||||
});
|
||||
}
|
||||
|
||||
public GetUrlResponse GetUrl(string intezmenyAzonosito, string privateToken, GetUrlRequest getUrlRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var relativeUri = $"/fajl-url/{intezmenyAzonosito}";
|
||||
|
||||
var response = Get(relativeUri, privateToken.GetAuthorizationHeaderWithJson(), getUrlRequest.GetUrlRequestParameters());
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new GetUrlResponse(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return GetUrlResponse.GetUrlResponseWithUrl(response.Result);
|
||||
}
|
||||
|
||||
var failureResponse = JsonConvert.DeserializeObject<GetUrlFailureResponse>(response.Result);
|
||||
|
||||
return new GetUrlResponse(failureResponse.Uzenet);
|
||||
});
|
||||
}
|
||||
|
||||
public FileDeleteResponse Delete(string intezmenyAzonosito, string privateToken, FileDeleteRequest fileDeleteRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var relativeUri = $"/fajlok/{intezmenyAzonosito}";
|
||||
|
||||
var response = Delete(relativeUri, privateToken.GetAuthorizationHeaderWithJson(), body: fileDeleteRequest);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new FileDeleteResponse(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NoContent)
|
||||
{
|
||||
return new FileDeleteResponse();
|
||||
}
|
||||
|
||||
var failureResponse = JsonConvert.DeserializeObject<FileDeleteFailureResponse>(response.Result);
|
||||
|
||||
return new FileDeleteResponse(failureResponse.Uzenet);
|
||||
});
|
||||
}
|
||||
|
||||
private GetTokenResponse GetToken(Dictionary<string, string> tokenRequestParameters)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.IDPUrl;
|
||||
|
||||
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) where T : IResponse, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return action();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return (T)Activator.CreateInstance(typeof(T), ExceptionUtil.ExceptionToString(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
211
Kreta.Client/FileService/FileServiceClientV3.cs
Normal file
211
Kreta.Client/FileService/FileServiceClientV3.cs
Normal file
|
@ -0,0 +1,211 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Kreta.Client.ClientBase;
|
||||
using Kreta.Client.FileService.Configuration;
|
||||
using Kreta.Client.FileService.Extension;
|
||||
using Kreta.Client.FileService.Request;
|
||||
using Kreta.Client.FileService.Response;
|
||||
using Kreta.Client.FileService.Response.FileFinalize;
|
||||
using Kreta.Framework;
|
||||
using Kreta.Framework.Exceptions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService
|
||||
{
|
||||
internal class FileServiceClientV3 : RestSharpClientBase, IFileServiceClientV3
|
||||
{
|
||||
private readonly IFileServiceClientConfiguration fileServiceClientConfiguration;
|
||||
|
||||
public FileServiceClientV3(IFileServiceClientConfiguration fileServiceClientConfiguration)
|
||||
{
|
||||
this.fileServiceClientConfiguration = fileServiceClientConfiguration ?? throw new ArgumentNullException(nameof(fileServiceClientConfiguration));
|
||||
}
|
||||
|
||||
public GetTokenResponse GetPrivateToken()
|
||||
{
|
||||
return GetToken(fileServiceClientConfiguration.GetPrivateTokenRequestParameters());
|
||||
}
|
||||
|
||||
private GetTokenResponse GetToken(Dictionary<string, string> tokenRequestParameters)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.IDPUrl;
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
public FileUploadResponse Upload(string privateToken, IFileUploadRequest fileUploadRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var header = privateToken.GetAuthorizationHeaderWithJson();
|
||||
header.Add("X-version", ApiVersions.V3);
|
||||
|
||||
var filePath = new Dictionary<string, string> { { "Utvonal", fileUploadRequest.Path } };
|
||||
var relativeUrl = $"/{UrlConstants.Fajlok}/{UrlConstants.Feltoltes}";
|
||||
|
||||
var response = Post(relativeUrl, header, parameters: filePath, fileList: new List<Jira.Model.Request.File>
|
||||
{
|
||||
new Jira.Model.Request.File
|
||||
{
|
||||
Name = "fajl",
|
||||
FileName = fileUploadRequest.FileName,
|
||||
Content = fileUploadRequest.Content,
|
||||
ContentType = fileUploadRequest.ContentType,
|
||||
}
|
||||
});
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new FileUploadResponse(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var successResponse = JsonConvert.DeserializeObject<FileUploadSuccessResponse>(response.Result);
|
||||
|
||||
return new FileUploadResponse(successResponse.FajlAzonosito, successResponse.Utvonal, successResponse.FajlMeretByteLength);
|
||||
}
|
||||
|
||||
var failureResponse = JsonConvert.DeserializeObject<FileUploadFailureResponse>(response.Result);
|
||||
|
||||
return new FileUploadResponse(failureResponse.Uzenet);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public FileFinalizeResponseV3 Veglegesites(string privateToken, FileFinalizeRequestV3 fileFinalizeRequestV3)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var header = privateToken.GetAuthorizationHeaderWithJson();
|
||||
header.Add("X-version", ApiVersions.V3);
|
||||
|
||||
var response = Post(
|
||||
relativeUri: $"/{UrlConstants.Fajlok}/{UrlConstants.Veglegesites}",
|
||||
header,
|
||||
parameters: new Dictionary<string, string> { { nameof(fileFinalizeRequestV3.FajlId), fileFinalizeRequestV3.FajlId.ToString() }, { nameof(fileFinalizeRequestV3.Utvonal), fileFinalizeRequestV3.Utvonal } });
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new FileFinalizeResponseV3(true);
|
||||
}
|
||||
|
||||
var result = JsonConvert.DeserializeObject<FinalizedFileDtoV3>(response.Result);
|
||||
|
||||
return new FileFinalizeResponseV3(result.FajlId, result.IsSikeres, result.HibaSzoveg, false, response.StatusCode, response.ErrorMessage, response.Exception);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public GetFileResponse GetFile(string intezmenyAzonosito, string privateToken, GetUrlRequest getUrlRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var relativeUri = $"/{UrlConstants.Fajlok}/{UrlConstants.Letoltes}";
|
||||
var header = privateToken.GetAuthorizationHeaderWithJson();
|
||||
header.Add("X-version", ApiVersions.V3);
|
||||
|
||||
var response = Post(relativeUri, header, body: getUrlRequest.GetUrlRequestParametersV3());
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new GetFileResponse(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<GetFileResponse>(response.Result);
|
||||
}
|
||||
|
||||
return new GetFileResponse(response.ErrorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
public FileDeleteResponseV3 Delete(string intezmenyAzonosito, string privateToken, FileDeleteRequest fileDeleteRequest)
|
||||
{
|
||||
return ExceptionLogger(() =>
|
||||
{
|
||||
BaseUrl = fileServiceClientConfiguration.FileUploadUrl;
|
||||
|
||||
var relativeUri = $"/{UrlConstants.Fajlok}/{UrlConstants.Torles}";
|
||||
var header = privateToken.GetAuthorizationHeaderWithJson();
|
||||
header.Add("X-version", ApiVersions.V3);
|
||||
|
||||
var response = Post(relativeUri, header, body: new[] { new { FajlId = fileDeleteRequest.FajlAzonosito, fileDeleteRequest.Utvonal } });
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
return new FileDeleteResponseV3(true);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<FileDeleteResponseV3>>(response.Result)[0];
|
||||
}
|
||||
|
||||
return new FileDeleteResponseV3(response.ErrorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
private T ExceptionLogger<T>(Func<T> action) where T : IResponse, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return action();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SDAServer.Instance.Logger.ExceptionThrown(ex);
|
||||
|
||||
return (T)Activator.CreateInstance(typeof(T), ExceptionUtil.ExceptionToString(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class UrlConstants
|
||||
{
|
||||
public const string Fajlok = "fajlok";
|
||||
public const string FajlUrl = "fajl-url";
|
||||
public const string IdeiglenesFajlok = "ideiglenesfajlok";
|
||||
public const string Veglegesites = "veglegesites";
|
||||
public const string Letoltes = "letoltes";
|
||||
public const string Feltoltes = "feltoltes";
|
||||
public const string Torles = "torles";
|
||||
public const string Rollback = "rollback";
|
||||
public const string Clone = "clone";
|
||||
public const string Zip = "zip";
|
||||
}
|
||||
public class ApiVersions
|
||||
{
|
||||
public const int DefaultMajor = 1;
|
||||
public const int DefaultMinor = 0;
|
||||
|
||||
public const string V1 = "1.0";
|
||||
public const string V2 = "2.0";
|
||||
public const string V3 = "3.0";
|
||||
}
|
||||
}
|
20
Kreta.Client/FileService/IFileServiceClient.cs
Normal file
20
Kreta.Client/FileService/IFileServiceClient.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using Kreta.Client.FileService.Request;
|
||||
using Kreta.Client.FileService.Response;
|
||||
|
||||
namespace Kreta.Client.FileService
|
||||
{
|
||||
public interface IFileServiceClient
|
||||
{
|
||||
GetTokenResponse GetPrivateToken();
|
||||
|
||||
GetTokenResponse GetPublicToken();
|
||||
|
||||
FileFinalizeResponse Finalize(string intezmenyAzonosito, string privateToken, FileFinalizeRequest fileFinalizeRequest);
|
||||
|
||||
FileUploadResponse Upload(string publicToken, IFileUploadRequest fileUploadRequest);
|
||||
|
||||
GetUrlResponse GetUrl(string intezmenyAzonosito, string privateToken, GetUrlRequest getUrlRequest);
|
||||
|
||||
FileDeleteResponse Delete(string intezmenyAzonosito, string privateToken, FileDeleteRequest fileDeleteRequest);
|
||||
}
|
||||
}
|
17
Kreta.Client/FileService/IFileServiceClientV3.cs
Normal file
17
Kreta.Client/FileService/IFileServiceClientV3.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Kreta.Client.FileService.Request;
|
||||
using Kreta.Client.FileService.Response;
|
||||
|
||||
namespace Kreta.Client.FileService
|
||||
{
|
||||
public interface IFileServiceClientV3
|
||||
{
|
||||
GetTokenResponse GetPrivateToken();
|
||||
|
||||
FileUploadResponse Upload(string privateToken, IFileUploadRequest fileUploadRequest);
|
||||
|
||||
GetFileResponse GetFile(string intezmenyAzonosito, string privateToken, GetUrlRequest getUrlRequest);
|
||||
|
||||
FileDeleteResponseV3 Delete(string intezmenyAzonosito, string privateToken, FileDeleteRequest fileDeleteRequest);
|
||||
FileFinalizeResponseV3 Veglegesites(string privateToken, FileFinalizeRequestV3 fileFinalizeRequestV3);
|
||||
}
|
||||
}
|
30
Kreta.Client/FileService/Model/FileData.cs
Normal file
30
Kreta.Client/FileService/Model/FileData.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Model
|
||||
{
|
||||
public class FileData
|
||||
{
|
||||
public FileData(string utvonal, Guid fajlAzonosito)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(utvonal))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(utvonal));
|
||||
}
|
||||
|
||||
if (fajlAzonosito == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentException(nameof(fajlAzonosito));
|
||||
}
|
||||
|
||||
Utvonal = utvonal;
|
||||
FajlAzonosito = fajlAzonosito;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "utvonal")]
|
||||
public string Utvonal { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "fajlAzonosito")]
|
||||
public Guid FajlAzonosito { get; set; }
|
||||
}
|
||||
}
|
17
Kreta.Client/FileService/Model/FileDataWithError.cs
Normal file
17
Kreta.Client/FileService/Model/FileDataWithError.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Model
|
||||
{
|
||||
internal class FileDataWithError
|
||||
{
|
||||
[JsonProperty(PropertyName = "fajlAzonosito")]
|
||||
public Guid FajlAzonosito { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "fajlMeretByteLength")]
|
||||
public int FajlMeretByteLength { get; set; }
|
||||
|
||||
[JsonProperty("hibaSzoveg")]
|
||||
public string HibaSzoveg { get; set; }
|
||||
}
|
||||
}
|
36
Kreta.Client/FileService/Request/DKT_FileUploadRequest.cs
Normal file
36
Kreta.Client/FileService/Request/DKT_FileUploadRequest.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public class DKT_FileUploadRequest : IFileUploadRequest
|
||||
{
|
||||
public DKT_FileUploadRequest(string fileName, byte[] content, string contentType, string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
|
||||
if (content?.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contentType))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(contentType));
|
||||
}
|
||||
|
||||
FileName = fileName;
|
||||
Path = path;
|
||||
Content = content;
|
||||
ContentType = contentType;
|
||||
}
|
||||
|
||||
public string FileName { get; }
|
||||
public string Path { get; }
|
||||
public byte[] Content { get; }
|
||||
|
||||
public string ContentType { get; }
|
||||
}
|
||||
}
|
34
Kreta.Client/FileService/Request/FileDeleteRequest.cs
Normal file
34
Kreta.Client/FileService/Request/FileDeleteRequest.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using Kreta.Client.FileService.Constant;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public class FileDeleteRequest
|
||||
{
|
||||
public FileDeleteRequest(string utvonal, Guid fajlAzonosito)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(utvonal))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(utvonal));
|
||||
}
|
||||
|
||||
if (fajlAzonosito == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentException(nameof(fajlAzonosito));
|
||||
}
|
||||
|
||||
Utvonal = utvonal;
|
||||
FajlAzonosito = fajlAzonosito;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "konyvtar")]
|
||||
public string Konyvtar => Folder.HaziFeladatok;
|
||||
|
||||
[JsonProperty(PropertyName = "utvonal")]
|
||||
public string Utvonal { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "fajlAzonosito")]
|
||||
public Guid FajlAzonosito { get; set; }
|
||||
}
|
||||
}
|
27
Kreta.Client/FileService/Request/FileFinalizeRequest.cs
Normal file
27
Kreta.Client/FileService/Request/FileFinalizeRequest.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Kreta.Client.FileService.Constant;
|
||||
using Kreta.Client.FileService.Model;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public class FileFinalizeRequest
|
||||
{
|
||||
public FileFinalizeRequest(List<FileData> fajlok)
|
||||
{
|
||||
if (fajlok?.Count == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fajlok));
|
||||
}
|
||||
|
||||
Fajlok = fajlok;
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "konyvtar")]
|
||||
public string Konyvtar => Folder.HaziFeladatok;
|
||||
|
||||
[JsonProperty(PropertyName = "fajlok")]
|
||||
public List<FileData> Fajlok { get; }
|
||||
}
|
||||
}
|
15
Kreta.Client/FileService/Request/FileFinalizeRequestV3.cs
Normal file
15
Kreta.Client/FileService/Request/FileFinalizeRequestV3.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public class FileFinalizeRequestV3
|
||||
{
|
||||
[JsonProperty(PropertyName = "fajlId")]
|
||||
public Guid FajlId { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "utvonal")]
|
||||
public string Utvonal { get; }
|
||||
|
||||
}
|
||||
}
|
34
Kreta.Client/FileService/Request/FileUploadRequest.cs
Normal file
34
Kreta.Client/FileService/Request/FileUploadRequest.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public class FileUploadRequest : IFileUploadRequest
|
||||
{
|
||||
public FileUploadRequest(string fileName, byte[] content, string contentType, string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
|
||||
if (content?.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(contentType))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(contentType));
|
||||
}
|
||||
|
||||
Path = path;
|
||||
FileName = fileName;
|
||||
Content = content;
|
||||
ContentType = contentType;
|
||||
}
|
||||
public string Path { get; }
|
||||
public string FileName { get; }
|
||||
public byte[] Content { get; }
|
||||
public string ContentType { get; }
|
||||
}
|
||||
}
|
38
Kreta.Client/FileService/Request/GetUrlRequest.cs
Normal file
38
Kreta.Client/FileService/Request/GetUrlRequest.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using System;
|
||||
using Kreta.Client.FileService.Constant;
|
||||
|
||||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public class GetUrlRequest
|
||||
{
|
||||
public GetUrlRequest(string utvonal, Guid fajlAzonosito, string fajlNev)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(utvonal))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(utvonal));
|
||||
}
|
||||
|
||||
if (fajlAzonosito == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentException(nameof(fajlAzonosito));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(fajlNev))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(fajlNev));
|
||||
}
|
||||
|
||||
Utvonal = utvonal;
|
||||
FajlAzonosito = fajlAzonosito;
|
||||
FajlNev = fajlNev;
|
||||
}
|
||||
|
||||
public string Konyvtar => Folder.HaziFeladatok;
|
||||
|
||||
public string Utvonal { get; set; }
|
||||
|
||||
public Guid FajlAzonosito { get; }
|
||||
|
||||
public string FajlNev { get; }
|
||||
}
|
||||
}
|
11
Kreta.Client/FileService/Request/IFileUploadRequest.cs
Normal file
11
Kreta.Client/FileService/Request/IFileUploadRequest.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace Kreta.Client.FileService.Request
|
||||
{
|
||||
public interface IFileUploadRequest
|
||||
{
|
||||
string FileName { get; }
|
||||
string Path { get; }
|
||||
byte[] Content { get; }
|
||||
string ContentType { get; }
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class FileDeleteFailureResponse
|
||||
{
|
||||
[JsonProperty("uzenet")]
|
||||
public string Uzenet { get; set; }
|
||||
|
||||
[JsonProperty("hibaAzonosito")]
|
||||
public Guid HibaAzonosito { get; set; }
|
||||
|
||||
[JsonProperty("datumUtc")]
|
||||
public DateTime DatumUtc { get; set; }
|
||||
|
||||
[JsonProperty("megnevezes")]
|
||||
public string Megnevezes { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class FileDeleteResponse : IResponse
|
||||
{
|
||||
public FileDeleteResponse()
|
||||
{
|
||||
IsSuccess = true;
|
||||
}
|
||||
|
||||
public FileDeleteResponse(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public FileDeleteResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class FileDeleteResponseV3 : IResponse
|
||||
{
|
||||
public FileDeleteResponseV3()
|
||||
{
|
||||
}
|
||||
|
||||
public FileDeleteResponseV3(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public FileDeleteResponseV3(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
IsSuccess = false;
|
||||
}
|
||||
|
||||
[JsonProperty("fajlId")]
|
||||
public Guid FileId { get; set; }
|
||||
|
||||
[JsonProperty("sikeres")]
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
[JsonProperty("hibaUzenet")]
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
[JsonProperty("hiba")]
|
||||
public string Error { get; set; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class FileFinalizeResponse : IResponse
|
||||
{
|
||||
public FileFinalizeResponse()
|
||||
{
|
||||
IsSuccess = true;
|
||||
}
|
||||
|
||||
public FileFinalizeResponse(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public FileFinalizeResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class FileFinalizeResponseV3 : IResponse
|
||||
{
|
||||
|
||||
public FileFinalizeResponseV3()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FileFinalizeResponseV3(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public FileFinalizeResponseV3(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public FileFinalizeResponseV3(Guid fajlId, bool isSuccess, string error, bool tryAgain, HttpStatusCode statusCode, string errorMessage, Exception exception) : this(isSuccess)
|
||||
{
|
||||
FajlAzonosito = fajlId;
|
||||
Error = error;
|
||||
TryAgain = tryAgain;
|
||||
StatusCode = statusCode;
|
||||
ErrorMessage = errorMessage;
|
||||
Exception = exception;
|
||||
}
|
||||
|
||||
public Guid FajlAzonosito { get; }
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
public string ErrorMessage { get; }
|
||||
public Exception Exception { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Response.FileFinalize
|
||||
{
|
||||
public class FinalizedFileDtoV3
|
||||
{
|
||||
public Guid FajlId { get; set; }
|
||||
|
||||
public string HibaSzoveg { get; set; }
|
||||
|
||||
public bool IsSikeres { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Client.FileService.Model;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class InternalFileFinalizeResponse
|
||||
{
|
||||
[JsonProperty("fajlok")]
|
||||
public List<FileDataWithError> Fajlok { get; set; }
|
||||
|
||||
[JsonProperty("hibaSzoveg")]
|
||||
public string HibaSzoveg { get; set; }
|
||||
|
||||
[JsonProperty("isSikeres")]
|
||||
public bool IsSikeres { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class FileUploadFailureResponse
|
||||
{
|
||||
[JsonProperty("uzenet")]
|
||||
public string Uzenet { get; set; }
|
||||
|
||||
[JsonProperty("hibaAzonosito")]
|
||||
public Guid HibaAzonosito { get; set; }
|
||||
|
||||
[JsonProperty("datumUtc")]
|
||||
public DateTime DatumUtc { get; set; }
|
||||
|
||||
[JsonProperty("megnevezes")]
|
||||
public string Megnevezes { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class FileUploadResponse : IResponse
|
||||
{
|
||||
public FileUploadResponse() { }
|
||||
|
||||
public FileUploadResponse(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public FileUploadResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public FileUploadResponse(Guid fajlAzonosito, string utvonal, int fajlMeretByteLength)
|
||||
{
|
||||
if (fajlAzonosito == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentException(nameof(fajlAzonosito));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(utvonal))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(utvonal));
|
||||
}
|
||||
|
||||
if (fajlMeretByteLength < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(fajlMeretByteLength));
|
||||
}
|
||||
|
||||
IsSuccess = true;
|
||||
FajlAzonosito = fajlAzonosito;
|
||||
Utvonal = utvonal;
|
||||
FajlMeretByteLength = fajlMeretByteLength;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public Guid FajlAzonosito { get; }
|
||||
|
||||
public string Utvonal { get; }
|
||||
|
||||
public int FajlMeretByteLength;
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class FileUploadSuccessResponse
|
||||
{
|
||||
[JsonProperty(PropertyName = "fajlId")]
|
||||
private Guid FajlAzonositoV3 { set { FajlAzonosito = value; } }
|
||||
|
||||
[JsonProperty(PropertyName = "fajlAzonosito")]
|
||||
public Guid FajlAzonosito { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "utvonal")]
|
||||
public string Utvonal { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "fajlMeretByteLength")]
|
||||
public int FajlMeretByteLength { get; set; }
|
||||
}
|
||||
}
|
37
Kreta.Client/FileService/Response/GetFile/GetFileResponse.cs
Normal file
37
Kreta.Client/FileService/Response/GetFile/GetFileResponse.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class GetFileResponse : IResponse
|
||||
{
|
||||
public GetFileResponse() { }
|
||||
|
||||
public GetFileResponse(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public GetFileResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; private set; }
|
||||
|
||||
[JsonProperty("fajlId")]
|
||||
public Guid FajlId { get; set; }
|
||||
|
||||
[JsonProperty("tartalom")]
|
||||
public string Tartalom { get; set; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class GetTokenFailureResponse
|
||||
{
|
||||
[JsonProperty("error")]
|
||||
public string Error { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class GetTokenResponse : IResponse
|
||||
{
|
||||
public GetTokenResponse() { }
|
||||
|
||||
public GetTokenResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public GetTokenResponse(string accessToken, int expiresIn)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(accessToken))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(accessToken));
|
||||
}
|
||||
|
||||
if (expiresIn < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(expiresIn));
|
||||
}
|
||||
|
||||
IsSuccess = true;
|
||||
AccessToken = accessToken;
|
||||
ExpiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
public string AccessToken { get; }
|
||||
|
||||
public int ExpiresIn { get; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class GetTokenSuccessResponse
|
||||
{
|
||||
[JsonProperty(PropertyName = "access_token")]
|
||||
public string AccessToken { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "expires_in")]
|
||||
public int ExpiresIn { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "token_type")]
|
||||
public string TokenType { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal class GetUrlFailureResponse
|
||||
{
|
||||
[JsonProperty("uzenet")]
|
||||
public string Uzenet { get; set; }
|
||||
|
||||
[JsonProperty("hibaAzonosito")]
|
||||
public Guid HibaAzonosito { get; set; }
|
||||
|
||||
[JsonProperty("datumUtc")]
|
||||
public DateTime DatumUtc { get; set; }
|
||||
|
||||
[JsonProperty("megnevezes")]
|
||||
public string Megnevezes { get; set; }
|
||||
}
|
||||
}
|
46
Kreta.Client/FileService/Response/GetUrl/GetUrlResponse.cs
Normal file
46
Kreta.Client/FileService/Response/GetUrl/GetUrlResponse.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
|
||||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
public class GetUrlResponse : IResponse
|
||||
{
|
||||
public GetUrlResponse() { }
|
||||
|
||||
public GetUrlResponse(bool tryAgain)
|
||||
{
|
||||
TryAgain = tryAgain;
|
||||
}
|
||||
|
||||
public GetUrlResponse(string error)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(error))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(error));
|
||||
}
|
||||
|
||||
Error = error;
|
||||
}
|
||||
|
||||
internal static GetUrlResponse GetUrlResponseWithUrl(string url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
|
||||
return new GetUrlResponse
|
||||
{
|
||||
IsSuccess = true,
|
||||
Url = url,
|
||||
};
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; private set; }
|
||||
|
||||
public string Url { get; private set; }
|
||||
|
||||
public string Error { get; }
|
||||
|
||||
public bool TryAgain { get; }
|
||||
}
|
||||
}
|
11
Kreta.Client/FileService/Response/IResponse.cs
Normal file
11
Kreta.Client/FileService/Response/IResponse.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace Kreta.Client.FileService.Response
|
||||
{
|
||||
internal interface IResponse
|
||||
{
|
||||
bool IsSuccess { get; }
|
||||
|
||||
string Error { get; }
|
||||
|
||||
bool TryAgain { get; }
|
||||
}
|
||||
}
|
|
@ -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)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace Kreta.Client.GlobalApi.Configuration
|
||||
{
|
||||
public interface IGlobalApiConfiguration
|
||||
{
|
||||
string GlobalApiUrl { get; }
|
||||
string TokenUrl { get; }
|
||||
string ClientId { get; }
|
||||
string ClientSecret { get; }
|
||||
}
|
||||
}
|
104
Kreta.Client/GlobalApi/GlobalApiClient.cs
Normal file
104
Kreta.Client/GlobalApi/GlobalApiClient.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
13
Kreta.Client/GlobalApi/IGlobalApiClient.cs
Normal file
13
Kreta.Client/GlobalApi/IGlobalApiClient.cs
Normal 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);
|
||||
}
|
||||
}
|
19
Kreta.Client/GlobalApi/Models/Models.cs
Normal file
19
Kreta.Client/GlobalApi/Models/Models.cs
Normal 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; }
|
||||
}
|
||||
}
|
24
Kreta.Client/Jira/Interface/IJiraClient.cs
Normal file
24
Kreta.Client/Jira/Interface/IJiraClient.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Client.Jira.Model.Request;
|
||||
using Kreta.Client.Jira.Model.Response;
|
||||
|
||||
namespace Kreta.Client.Jira.Interface
|
||||
{
|
||||
public interface IJiraClient
|
||||
{
|
||||
bool IsFileUploadEnabled { get; set; }
|
||||
|
||||
void CreateBasicAuthenticator(string username, string password);
|
||||
string GetServiceDeskId();
|
||||
GetRequestModel GetBejelentes(string id);
|
||||
GetRequestTypeModel GetRequestTypes(string serviceDeskId);
|
||||
GetRequestModel CreateBejelentes(TicketRequest ticketRequest);
|
||||
TemporaryAttachmentsModel UploadAttachments(List<File> fileList, string serviceDeskId);
|
||||
void AddAttachmentsToIssue(AddAttachments addAttachmentsModel, string isssueId);
|
||||
string CreateCommentToBejelentes(string id, CommentRequest commentRequest);
|
||||
GetRequestsModel GetBejelentesek(string requestType, string serviceDeskId, string requestStatus, string first, string limit);
|
||||
GetRequestsComentsModel GetBejelentesCommentek(string id);
|
||||
void ChangeAdminEmail(string intemzenyAzonosito, string newAddress);
|
||||
void SubscribeToBejegyzes(string id);
|
||||
}
|
||||
}
|
240
Kreta.Client/Jira/JiraClient.cs
Normal file
240
Kreta.Client/Jira/JiraClient.cs
Normal file
|
@ -0,0 +1,240 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Kreta.Client.ClientBase;
|
||||
using Kreta.Client.Jira.Interface;
|
||||
using Kreta.Client.Jira.Model.Request;
|
||||
using Kreta.Client.Jira.Model.Response;
|
||||
using Kreta.Core;
|
||||
using Kreta.Resources;
|
||||
|
||||
namespace Kreta.Client.Jira
|
||||
{
|
||||
internal class JiraClient : RestSharpClientBase, IJiraClient
|
||||
{
|
||||
private readonly IUgyfelszolgalatConfig UgyfelszolgalatConfig;
|
||||
public bool IsFileUploadEnabled { get; set; }
|
||||
private readonly int[] JiraGropuIdFilters;
|
||||
|
||||
private const string RequestPath = "request";
|
||||
private const string RequestIdPath = RequestPath + "/{id}";
|
||||
private const string ServicedeskPath = "servicedesk";
|
||||
private const string RequestTypePath = ServicedeskPath + "/{id}/requesttype";
|
||||
private const string CommentPath = RequestPath + "/{id}/comment";
|
||||
private const string SubscribePath = RequestPath + "/{id}/notification";
|
||||
private const string AttachmentUploadPath = ServicedeskPath + "/{id}/attachTemporaryFile";
|
||||
private const string AddAttachmentToIssuePath = RequestIdPath + "/attachment";
|
||||
private const string JiraServiceApiLdapEmail = "/api/v1/ldap/email";
|
||||
|
||||
public JiraClient(IUgyfelszolgalatConfig ugyfelszolgalatConfig)
|
||||
{
|
||||
UgyfelszolgalatConfig = ugyfelszolgalatConfig ?? throw new ArgumentNullException(nameof(ugyfelszolgalatConfig));
|
||||
|
||||
BaseUrl = ugyfelszolgalatConfig.Url;
|
||||
IsFileUploadEnabled = ugyfelszolgalatConfig.IsFileUploadEnabled;
|
||||
JiraGropuIdFilters = !string.IsNullOrWhiteSpace(UgyfelszolgalatConfig.CommaSeparatedGroupIdFilters) ?
|
||||
UgyfelszolgalatConfig.CommaSeparatedGroupIdFilters.Split(',').Select(x => int.Parse(x)).ToArray() :
|
||||
new int[] { };
|
||||
}
|
||||
|
||||
public GetRequestsModel GetBejelentesek(string requestType, string serviceDeskId, string requestStatus, string first, string limit)
|
||||
{
|
||||
var parameters = new Dictionary<string, string>
|
||||
{
|
||||
{ "expand", "requestType" },
|
||||
{ "serviceDeskId", serviceDeskId },
|
||||
{ "start", first },
|
||||
{ "limit", limit },
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(requestStatus))
|
||||
{
|
||||
parameters.Add("requestStatus", requestStatus);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(requestType))
|
||||
{
|
||||
parameters.Add("requestTypeId", requestType);
|
||||
}
|
||||
|
||||
var response = Get<GetRequestsModel>(RequestPath, parameters: parameters);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
var result = response.Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public string CreateCommentToBejelentes(string id, CommentRequest commentRequest)
|
||||
{
|
||||
var urlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", id }
|
||||
};
|
||||
|
||||
var response = Post(CommentPath, urlSegments: urlSegments, body: commentRequest);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
var result = response.Result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public TemporaryAttachmentsModel UploadAttachments(List<File> fileList, string serviceDeskId)
|
||||
{
|
||||
if (fileList == null || fileList.Count < 1 || !UgyfelszolgalatConfig.IsFileUploadEnabled)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{ "X-Atlassian-Token", "no-check" },
|
||||
{ "X-ExperimentalApi", "opt-in" },
|
||||
{ "Content-Type", "multipart/form-data"}
|
||||
};
|
||||
|
||||
var firstPostUrlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", serviceDeskId }
|
||||
};
|
||||
|
||||
var response = Post<TemporaryAttachmentsModel>(AttachmentUploadPath, headers: headers, urlSegments: firstPostUrlSegments, fileList: fileList);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
public void AddAttachmentsToIssue(AddAttachments addAttachmentsModel, string isssueId)
|
||||
{
|
||||
if (addAttachmentsModel.TemporaryAttachmentIds == null || addAttachmentsModel.TemporaryAttachmentIds.Count < 1 || !UgyfelszolgalatConfig.IsFileUploadEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var secondPostUrlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", isssueId }
|
||||
};
|
||||
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{ "X-Atlassian-Token", "no-check" },
|
||||
{ "X-ExperimentalApi", "opt-in" },
|
||||
{ "Content-Type", "application/json" }
|
||||
};
|
||||
|
||||
var response = Post(AddAttachmentToIssuePath, headers: headers, urlSegments: secondPostUrlSegments, body: addAttachmentsModel);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
}
|
||||
|
||||
public string GetServiceDeskId()
|
||||
{
|
||||
var response = Get<GetServiceDeskModel>(ServicedeskPath);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
|
||||
return response.Result.Values.SingleOrDefault(a => a.ProjectKey == UgyfelszolgalatConfig.ProjectKey)?.Id;
|
||||
}
|
||||
|
||||
public GetRequestModel CreateBejelentes(TicketRequest ticketRequest)
|
||||
{
|
||||
var response = Post<GetRequestModel>(RequestPath, body: ticketRequest);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
public GetRequestsComentsModel GetBejelentesCommentek(string id)
|
||||
{
|
||||
var urlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", id }
|
||||
};
|
||||
|
||||
var response = Get<GetRequestsComentsModel>(CommentPath, urlSegments: urlSegments);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
public GetRequestTypeModel GetRequestTypes(string serviceDeskId)
|
||||
{
|
||||
var urlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", serviceDeskId }
|
||||
};
|
||||
|
||||
var response = Get<GetRequestTypeModel>(RequestTypePath, urlSegments: urlSegments);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
var result = response.Result;
|
||||
|
||||
var validRequestTypeItemList = JiraGropuIdFilters.Length > 0 ?
|
||||
result.Values.Where(requestType => requestType.GroupIds.Exists(groupId => JiraGropuIdFilters.Contains(int.Parse(groupId)))).ToList() :
|
||||
result.Values;
|
||||
|
||||
result.Values = validRequestTypeItemList;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public GetRequestModel GetBejelentes(string id)
|
||||
{
|
||||
var urlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", id }
|
||||
};
|
||||
|
||||
var parameters = new Dictionary<string, string>
|
||||
{
|
||||
{ "expand", "requestType,serviceDesk,action,comment" }
|
||||
};
|
||||
|
||||
var response = Get<GetRequestModel>(RequestIdPath, parameters: parameters, urlSegments: urlSegments);
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
public void ChangeAdminEmail(string intemzenyAzonosito, string newAddress)
|
||||
{
|
||||
var headers = new Dictionary<string, string>
|
||||
{
|
||||
{ "ApiKey", UgyfelszolgalatConfig.JiraServiceApiKey },
|
||||
{ "Content-Type", "application/json-patch+json" }
|
||||
};
|
||||
BaseUrl = UgyfelszolgalatConfig.JiraServiceApiUrl;
|
||||
|
||||
var response = Patch($"{JiraServiceApiLdapEmail}/{intemzenyAzonosito}", headers, body: new object[] { new { op = "replace", path = "/mail", value = newAddress } });
|
||||
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
}
|
||||
|
||||
public void SubscribeToBejegyzes(string id)
|
||||
{
|
||||
var urlSegments = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", id }
|
||||
};
|
||||
|
||||
var response = Post(SubscribePath, urlSegments: urlSegments);
|
||||
|
||||
ErrorByStatusCode(response.StatusCode);
|
||||
}
|
||||
|
||||
private void ErrorByStatusCode(HttpStatusCode code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case HttpStatusCode.BadRequest:
|
||||
throw new ClientException(ErrorResource.JiraHibasKeres);
|
||||
case HttpStatusCode.Unauthorized:
|
||||
throw new ClientException(ErrorResource.JiraNincsBejelentkezve);
|
||||
case HttpStatusCode.Forbidden:
|
||||
throw new ClientException(ErrorResource.JiraNemMegfeleloJogosultsag);
|
||||
case HttpStatusCode.NotFound:
|
||||
throw new ClientException(ErrorResource.JiraNemMegfeleloUtvonal);
|
||||
case HttpStatusCode.PreconditionFailed:
|
||||
throw new ClientException(ErrorResource.JiraKisérletiJelleguHiba);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
26
Kreta.Client/Jira/Model/Request/AddAttachments.cs
Normal file
26
Kreta.Client/Jira/Model/Request/AddAttachments.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Kreta.Client.Jira.Model.Response;
|
||||
using Kreta.Resources;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Request
|
||||
{
|
||||
public class AddAttachments
|
||||
{
|
||||
[JsonProperty("temporaryAttachmentIds")]
|
||||
public List<string> TemporaryAttachmentIds { get; set; }
|
||||
|
||||
[JsonProperty("public")]
|
||||
public bool IsPublic => true;
|
||||
|
||||
[JsonProperty("additionalComment")]
|
||||
public AdditionalCommentModel AdditionalComment { get; set; }
|
||||
|
||||
public static implicit operator AddAttachments(TemporaryAttachmentsModel temporaryAttachmentsModel) => new AddAttachments
|
||||
{
|
||||
TemporaryAttachmentIds = temporaryAttachmentsModel?.TemporaryAttachments.Select(attachment => attachment.TemporaryAttachmentId).ToList(),
|
||||
AdditionalComment = new AdditionalCommentModel { Body = UgyfelszolgalatResource.AKovetkezoFajlokatAKretaUgyfelszolgalatBefogadta }
|
||||
};
|
||||
}
|
||||
}
|
10
Kreta.Client/Jira/Model/Request/AdditionalCommentModel.cs
Normal file
10
Kreta.Client/Jira/Model/Request/AdditionalCommentModel.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Request
|
||||
{
|
||||
public class AdditionalCommentModel
|
||||
{
|
||||
[JsonProperty("body")]
|
||||
public string Body { get; set; }
|
||||
}
|
||||
}
|
13
Kreta.Client/Jira/Model/Request/CommentRequest.cs
Normal file
13
Kreta.Client/Jira/Model/Request/CommentRequest.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Request
|
||||
{
|
||||
public class CommentRequest
|
||||
{
|
||||
[JsonProperty("body")]
|
||||
public string Body { get; set; }
|
||||
|
||||
[JsonProperty("public")]
|
||||
internal bool IsPublic => true;
|
||||
}
|
||||
}
|
10
Kreta.Client/Jira/Model/Request/File.cs
Normal file
10
Kreta.Client/Jira/Model/Request/File.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Kreta.Client.Jira.Model.Request
|
||||
{
|
||||
public class File
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public byte[] Content { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
}
|
||||
}
|
13
Kreta.Client/Jira/Model/Request/RequestFieldValues.cs
Normal file
13
Kreta.Client/Jira/Model/Request/RequestFieldValues.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Request
|
||||
{
|
||||
public class RequestFieldValues
|
||||
{
|
||||
[JsonProperty("summary")]
|
||||
public string Summary { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
17
Kreta.Client/Jira/Model/Request/TicketRequest.cs
Normal file
17
Kreta.Client/Jira/Model/Request/TicketRequest.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Request
|
||||
{
|
||||
public class TicketRequest
|
||||
{
|
||||
[JsonProperty("serviceDeskId")]
|
||||
public string ServiceDeskId { get; set; }
|
||||
|
||||
[JsonProperty("requestTypeId")]
|
||||
public string RequestTypeId { get; set; }
|
||||
|
||||
[JsonProperty("requestFieldValues")]
|
||||
public RequestFieldValues RequestFieldValues { get; set; }
|
||||
|
||||
}
|
||||
}
|
12
Kreta.Client/Jira/Model/Response/Attachment.cs
Normal file
12
Kreta.Client/Jira/Model/Response/Attachment.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class Attachment
|
||||
{
|
||||
[JsonProperty("temporaryAttachmentId")]
|
||||
public string TemporaryAttachmentId { get; set; }
|
||||
[JsonProperty("fileName")]
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
}
|
10
Kreta.Client/Jira/Model/Response/CreatedDate.cs
Normal file
10
Kreta.Client/Jira/Model/Response/CreatedDate.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class CreatedDate
|
||||
{
|
||||
public string Iso8601 { get; set; }
|
||||
public string Jira { get; set; }
|
||||
public string Friendly { get; set; }
|
||||
public string EpochMillis { get; set; }
|
||||
}
|
||||
}
|
8
Kreta.Client/Jira/Model/Response/CurrentStatus.cs
Normal file
8
Kreta.Client/Jira/Model/Response/CurrentStatus.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class CurrentStatus
|
||||
{
|
||||
public string Status { get; set; }
|
||||
public CreatedDate StatusDate { get; set; }
|
||||
}
|
||||
}
|
19
Kreta.Client/Jira/Model/Response/GetRequestModel.cs
Normal file
19
Kreta.Client/Jira/Model/Response/GetRequestModel.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class GetRequestModel
|
||||
{
|
||||
public string IssueId { get; set; }
|
||||
public string IssueKey { get; set; }
|
||||
public string RequestTypeId { get; set; }
|
||||
public GetRequestTypeModelValue RequestType { get; set; }
|
||||
public string ServiceDeskId { get; set; }
|
||||
public GetServiceDeskModelValue ServiceDesk { get; set; }
|
||||
public CreatedDate CreatedDate { get; set; }
|
||||
public JiraUser Reporter { get; set; }
|
||||
public List<RequestFieldValue> RequestFieldValues { get; set; }
|
||||
public CurrentStatus CurrentStatus { get; set; }
|
||||
public RequestJiraLink Links { get; set; }
|
||||
}
|
||||
}
|
9
Kreta.Client/Jira/Model/Response/GetRequestTypeModel.cs
Normal file
9
Kreta.Client/Jira/Model/Response/GetRequestTypeModel.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class GetRequestTypeModel : JiraRequestBase
|
||||
{
|
||||
public List<GetRequestTypeModelValue> Values { get; set; }
|
||||
}
|
||||
}
|
17
Kreta.Client/Jira/Model/Response/GetRequestTypeModelValue.cs
Normal file
17
Kreta.Client/Jira/Model/Response/GetRequestTypeModelValue.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class GetRequestTypeModelValue
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string HelpText { get; set; }
|
||||
public string ServiceDeskId { get; set; }
|
||||
public List<string> GroupIds { get; set; }
|
||||
public JiraIcon Icon { get; set; }
|
||||
public int Order { get; set; }
|
||||
public bool IsFileUploadEnabled { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class GetRequestsComentsModel : JiraRequestBase
|
||||
{
|
||||
public List<RequestsComentValue> Values { get; set; }
|
||||
}
|
||||
}
|
22
Kreta.Client/Jira/Model/Response/GetRequestsModel.cs
Normal file
22
Kreta.Client/Jira/Model/Response/GetRequestsModel.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Client.Jira.Model.Response
|
||||
{
|
||||
public class GetRequestsModel : JiraRequestBase
|
||||
{
|
||||
public List<GetRequestsModelValue> values { get; set; }
|
||||
|
||||
public class GetRequestsModelValue
|
||||
{
|
||||
public string IssueId { get; set; }
|
||||
public string IssueKey { get; set; }
|
||||
public string RequestTypeId { get; set; }
|
||||
public GetRequestTypeModelValue RequestType { get; set; }
|
||||
public CreatedDate CreatedDate { get; set; }
|
||||
public JiraUser Reporter { get; set; }
|
||||
public List<RequestFieldValue> RequestFieldValues { get; set; }
|
||||
public CurrentStatus CurrentStatus { get; set; }
|
||||
public RequestJiraLink Links { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue