Add device metering values import
This commit is contained in:
23
Hcs.Client/Client/Api/DeviceMeteringApi.cs
Normal file
23
Hcs.Client/Client/Api/DeviceMeteringApi.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Hcs.Client.Api.Request.DeviceMetering;
|
||||
using Hcs.Service.Async.DeviceMetering;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Client.Api
|
||||
{
|
||||
// http://open-gkh.ru/DeviceMeteringServiceAsync/
|
||||
public class DeviceMeteringApi(ClientBase client) : ApiBase(client)
|
||||
{
|
||||
/// <summary>
|
||||
/// Импорт показаний приборов учета
|
||||
/// </summary>
|
||||
/// <param name="values">Показания прибора учета</param>
|
||||
/// <param name="token">Токен отмены</param>
|
||||
/// <returns>true, если операция выполнена успешно, иначе - false</returns>
|
||||
public async Task<bool> ImportMeteringDeviceValuesAsync(importMeteringDeviceValuesRequestMeteringDevicesValues values, CancellationToken token = default)
|
||||
{
|
||||
var request = new ImportMeteringDeviceValuesRequest(client);
|
||||
return await request.ExecuteAsync(values, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
using Hcs.Client.Api.Request;
|
||||
using Hcs.Client.Api.Request.Adapter;
|
||||
using Hcs.Service.Async.DeviceMetering;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Service.Async.DeviceMetering
|
||||
{
|
||||
#pragma warning disable IDE1006
|
||||
public partial class getStateResult : IGetStateResultMany { }
|
||||
#pragma warning restore IDE1006
|
||||
|
||||
public partial class DeviceMeteringPortTypesAsyncClient : IAsyncClient<RequestHeader>
|
||||
{
|
||||
public async Task<IGetStateResponse> GetStateAsync(RequestHeader 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.DeviceMetering
|
||||
{
|
||||
internal class DeviceMeteringRequestBase(ClientBase client) :
|
||||
RequestBase<getStateResult,
|
||||
DeviceMeteringPortTypesAsyncClient,
|
||||
DeviceMeteringPortTypesAsync,
|
||||
RequestHeader,
|
||||
AckRequestAck,
|
||||
ErrorMessageType,
|
||||
getStateRequest>(client)
|
||||
{
|
||||
protected override EndPoint EndPoint => EndPoint.DeviceMeteringAsync;
|
||||
|
||||
protected override bool EnableMinimalResponseWaitDelay => true;
|
||||
|
||||
protected override bool CanBeRestarted => true;
|
||||
|
||||
protected override int RestartTimeoutMinutes => 20;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
using Hcs.Client.Api.Request.Exception;
|
||||
using Hcs.Client.Internal;
|
||||
using Hcs.Service.Async.DeviceMetering;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hcs.Client.Api.Request.DeviceMetering
|
||||
{
|
||||
internal class ImportMeteringDeviceValuesRequest(ClientBase client) : DeviceMeteringRequestBase(client)
|
||||
{
|
||||
protected override bool CanBeRestarted => false;
|
||||
|
||||
internal async Task<bool> ExecuteAsync(importMeteringDeviceValuesRequestMeteringDevicesValues values, CancellationToken token)
|
||||
{
|
||||
// http://open-gkh.ru/DeviceMetering/importMeteringDeviceValuesRequest.html
|
||||
var request = new importMeteringDeviceValuesRequest
|
||||
{
|
||||
Id = Constants.SIGNED_XML_ELEMENT_ID,
|
||||
version = "10.0.1.1",
|
||||
MeteringDevicesValues = [values]
|
||||
};
|
||||
|
||||
var result = await SendAndWaitResultAsync(request, async asyncClient =>
|
||||
{
|
||||
var response = await asyncClient.importMeteringDeviceValuesAsync(CreateRequestHeader(), request);
|
||||
return response.AckRequest.Ack;
|
||||
}, token);
|
||||
|
||||
result.Items.OfType<ErrorMessageType>().ToList().ForEach(error =>
|
||||
{
|
||||
throw RemoteException.CreateNew(error.ErrorCode, error.Description);
|
||||
});
|
||||
|
||||
// TODO: Проверить содержимое ответа
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,8 @@ namespace Hcs.Client
|
||||
/// </summary>
|
||||
public class UniClient : ClientBase
|
||||
{
|
||||
public DeviceMeteringApi DeviceMetering => new(this);
|
||||
|
||||
public HouseManagementApi HouseManagement => new(this);
|
||||
|
||||
public NsiApi Nsi => new(this);
|
||||
|
||||
Reference in New Issue
Block a user