Add org registry export
This commit is contained in:
33
Hcs.Client/Client/Api/OrgRegistryCommonApi.cs
Normal file
33
Hcs.Client/Client/Api/OrgRegistryCommonApi.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using Hcs.Client.Api.Request.Exception;
|
||||
using Hcs.Client.Api.Request.OrgRegistryCommon;
|
||||
using Hcs.Service.Async.OrgRegistryCommon;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Client.Api
|
||||
{
|
||||
// http://open-gkh.ru/OrganizationsRegistryCommonAsyncService/
|
||||
public class OrgRegistryCommonApi(ClientBase client) : ApiBase(client)
|
||||
{
|
||||
/// <summary>
|
||||
/// Возвращает сведения из реестра организаций
|
||||
/// </summary>
|
||||
/// <param name="ogrn">ОГРН</param>
|
||||
/// <param name="kpp">КПП</param>
|
||||
/// <param name="token">Токен отмены</param>
|
||||
/// <returns>Сведения из реестра организаций</returns>
|
||||
public async Task<IEnumerable<exportOrgRegistryResultType>> ExportOrgRegistryAsync(string ogrn, string kpp, CancellationToken token = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new ExportOrgRegistryRequest(client);
|
||||
return await request.ExecuteAsync(ogrn, kpp, token);
|
||||
}
|
||||
catch (NoResultsRemoteException)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
using Hcs.Client.Internal;
|
||||
using Hcs.Service.Async.OrgRegistryCommon;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Client.Api.Request.OrgRegistryCommon
|
||||
{
|
||||
internal class ExportOrgRegistryRequest(ClientBase client) : OrgRegistryCommonRequestBase(client)
|
||||
{
|
||||
private const int OGRN_LENGTH = 13;
|
||||
|
||||
internal async Task<IEnumerable<exportOrgRegistryResultType>> ExecuteAsync(string ogrn, string kpp, CancellationToken token)
|
||||
{
|
||||
if (ogrn.Length != OGRN_LENGTH)
|
||||
{
|
||||
throw new System.ArgumentException($"The length of {ogrn} is incorrect");
|
||||
}
|
||||
|
||||
var criteria = new exportOrgRegistryRequestSearchCriteria();
|
||||
if (!string.IsNullOrEmpty(kpp))
|
||||
{
|
||||
criteria.Items = [ogrn, kpp];
|
||||
criteria.ItemsElementName = [ItemsChoiceType3.OGRN, ItemsChoiceType3.KPP];
|
||||
}
|
||||
else
|
||||
{
|
||||
criteria.Items = [ogrn];
|
||||
criteria.ItemsElementName = [ItemsChoiceType3.OGRN];
|
||||
}
|
||||
|
||||
// http://open-gkh.ru/OrganizationsRegistryCommon/exportOrgRegistryRequest.html
|
||||
var request = new exportOrgRegistryRequest
|
||||
{
|
||||
Id = Constants.SIGNED_XML_ELEMENT_ID,
|
||||
version = "10.0.2.1",
|
||||
SearchCriteria = [criteria]
|
||||
};
|
||||
|
||||
var result = await SendAndWaitResultAsync(request, async asyncClient =>
|
||||
{
|
||||
var response = await asyncClient.exportOrgRegistryAsync(CreateRequestHeader(), request);
|
||||
return response.AckRequest.Ack;
|
||||
}, token);
|
||||
|
||||
return result.Items.OfType<exportOrgRegistryResultType>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
using Hcs.Client.Api.Request;
|
||||
using Hcs.Client.Api.Request.Adapter;
|
||||
using Hcs.Service.Async.OrgRegistryCommon;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Service.Async.OrgRegistryCommon
|
||||
{
|
||||
#pragma warning disable IDE1006
|
||||
public partial class getStateResult : IGetStateResultMany { }
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public partial class RegOrgPortsTypeAsyncClient : IAsyncClient<ISRequestHeader>
|
||||
{
|
||||
public async Task<IGetStateResponse> GetStateAsync(ISRequestHeader header, IGetStateRequest request)
|
||||
{
|
||||
return await getStateAsync(header, (getStateRequest)request);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public partial class getStateResponse : IGetStateResponse
|
||||
#pragma warning restore IDE1006
|
||||
{
|
||||
public IGetStateResult GetStateResult => getStateResult;
|
||||
}
|
||||
|
||||
public partial class AckRequestAck : IAck { }
|
||||
|
||||
public partial class ErrorMessageType : IErrorMessage { }
|
||||
|
||||
#pragma warning disable IDE1006
|
||||
public partial class getStateRequest : IGetStateRequest { }
|
||||
#pragma warning restore IDE1006
|
||||
}
|
||||
|
||||
namespace Hcs.Client.Api.Request.OrgRegistryCommon
|
||||
{
|
||||
internal class OrgRegistryCommonRequestBase(ClientBase client) :
|
||||
RequestBase<getStateResult,
|
||||
RegOrgPortsTypeAsyncClient,
|
||||
RegOrgPortsTypeAsync,
|
||||
ISRequestHeader,
|
||||
AckRequestAck,
|
||||
ErrorMessageType,
|
||||
getStateRequest>(client)
|
||||
{
|
||||
protected override EndPoint EndPoint => EndPoint.OrgRegistryCommonAsync;
|
||||
|
||||
protected override bool EnableMinimalResponseWaitDelay => true;
|
||||
|
||||
protected override bool CanBeRestarted => true;
|
||||
|
||||
protected override int RestartTimeoutMinutes => 20;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user