Files
hcs/Hcs.Client/ClientApi/HouseManagementApi/HcsMethodExportSupplyResourceContractObjectAddress.cs
HOME-LAPTOP\kshkulev 33ab055b43 Add project
Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.
2025-08-12 11:21:10 +09:00

126 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Hcs.ClientApi.DataTypes;
using Hcs.ClientApi.RemoteCaller;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using HouseManagement = Hcs.Service.Async.HouseManagement.v14_5_0_1;
namespace Hcs.ClientApi.HouseManagementApi
{
/// <summary>
/// Метод получения списка адресных объектов по договору ресурсоснабжения
/// </summary>
public class HcsMethodExportSupplyResourceContractObjectAddress : HcsHouseManagementMethod
{
public HcsMethodExportSupplyResourceContractObjectAddress(HcsClientConfig config) : base(config)
{
EnableMinimalResponseWaitDelay = true;
CanBeRestarted = true;
}
/// <summary>
/// Запрос на экспорт объектов жилищного фонда из договора ресурсоснабжения
/// </summary>
public async Task<int> QueryAddresses(
ГисДоговор договор, Action<ГисАдресныйОбъект> resultHandler, CancellationToken token)
{
int numResults = 0;
Action<ГисАдресныйОбъект> countingHandler = (result) =>
{
numResults += 1;
resultHandler(result);
};
Guid? nextGuid = null;
while (true)
{
var paged = await QueryOneBatch(договор, countingHandler, nextGuid, token);
if (paged.IsLastPage) break;
nextGuid = paged.NextGuid;
numResults += 1;
}
return numResults;
}
private async Task<HcsPagedResultState> QueryOneBatch(
ГисДоговор договор, Action<ГисАдресныйОбъект> resultHandler,
Guid? firstGuid, CancellationToken token)
{
var itemNames = new List<HouseManagement.ItemsChoiceType29> { };
List<string> items = new List<string> { };
if (договор.ГуидВерсииДоговора != default)
{
itemNames.Add(HouseManagement.ItemsChoiceType29.ContractGUID);
items.Add(FormatGuid(договор.ГуидВерсииДоговора));
}
else
{
itemNames.Add(HouseManagement.ItemsChoiceType29.ContractRootGUID);
items.Add(FormatGuid(договор.ГуидДоговора));
}
// TODO: Проверить комментарий
// Если указан guid следующей страницы данных, добавляем его в параметры
// (на 20.12.2023 эта функция не работает, первый пакет содержит 1000 записей
// и запрос второго пакета с ExportObjectGUID возвращает "Bad request")
if (firstGuid != null)
{
itemNames.Add(HouseManagement.ItemsChoiceType29.ExportObjectGUID);
items.Add(FormatGuid(firstGuid));
}
var request = new HouseManagement.exportSupplyResourceContractObjectAddressRequest
{
Id = HcsConstants.SignedXmlElementId,
Items = items.ToArray(),
ItemsElementName = itemNames.ToArray(),
// TODO: Проверить хардкод версии
version = "13.1.1.1" // Номер версии из сообщения об ошибке сервера HCS
};
try
{
var stateResult = await SendAndWaitResultAsync(request, async (portClient) =>
{
var ackResponse = await portClient.exportSupplyResourceContractObjectAddressDataAsync(
CreateRequestHeader(), request);
return ackResponse.AckRequest.Ack;
}, token);
var result = RequireSingleItem
<HouseManagement.getStateResultExportSupplyResourceContractObjectAddress>(stateResult.Items);
foreach (var x in result.ObjectAddress)
{
resultHandler(Adopt(x));
}
return new HcsPagedResultState(result.Item);
}
catch (HcsNoResultsRemoteException)
{
return HcsPagedResultState.IsLastPageResultState;
}
}
private ГисАдресныйОбъект Adopt(
HouseManagement.exportSupplyResourceContractObjectAddressResultType source)
{
return new ГисАдресныйОбъект()
{
ТипЗдания = (source.HouseTypeSpecified ? source.HouseType.ToString() : null),
ГуидЗданияФиас = ParseGuid(source.FIASHouseGuid),
ГуидДоговора = ParseGuid(source.ContractRootGUID),
ГуидВерсииДоговора = ParseGuid(source.ContractGUID),
ГуидАдресногоОбъекта = ParseGuid(source.ObjectGUID),
НомерПомещения = source.ApartmentNumber,
НомерКомнаты = source.RoomNumber
};
}
}
}