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

View file

@ -0,0 +1,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)];
}
}

View file

@ -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; }
}
}

View 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";
}
}

View file

@ -0,0 +1,7 @@
namespace Kreta.Client.FileService.Constant
{
internal static class Folder
{
public const string HaziFeladatok = "HaziFeladatok";
}
}

View file

@ -0,0 +1,7 @@
namespace Kreta.Client.FileService.Constant
{
internal static class GrantType
{
public const string ClientCredentials = "client_credentials";
}
}

View 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";
}
}

View 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";
}
}

View file

@ -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 },
};
}
}
}

View 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 }
};
}
}
}

View 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" },
};
}
}

View 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));
}
}
}
}

View 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";
}
}

View 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);
}
}

View 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);
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View 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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View 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; }
}
}

View file

@ -0,0 +1,10 @@
using Newtonsoft.Json;
namespace Kreta.Client.FileService.Response
{
internal class GetTokenFailureResponse
{
[JsonProperty("error")]
public string Error { get; set; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View 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; }
}
}

View file

@ -0,0 +1,11 @@
namespace Kreta.Client.FileService.Response
{
internal interface IResponse
{
bool IsSuccess { get; }
string Error { get; }
bool TryAgain { get; }
}
}