Add project
Basic formatting applied. Unnecessary comments have been removed. Suspicious code is covered by TODO.
This commit is contained in:
52
Hcs.TestApp/ClientDemo/DebtRequestsDemo.cs
Normal file
52
Hcs.TestApp/ClientDemo/DebtRequestsDemo.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using Hcs.ClientApi;
|
||||
using Hcs.ClientApi.DebtRequestsApi;
|
||||
using System;
|
||||
|
||||
namespace Hcs.ClientDemo
|
||||
{
|
||||
public class DebtRequestsDemo
|
||||
{
|
||||
public static void DemoExportManySubrequests(HcsClient client)
|
||||
{
|
||||
Action<HcsDebtSubrequest> handler = delegate (HcsDebtSubrequest s)
|
||||
{
|
||||
client.Log($"Получен: {s}");
|
||||
};
|
||||
|
||||
var date = new DateTime(2024, 1, 22);
|
||||
int n = client.DebtRequests.ExportDSRsByPeriodOfSending(date, date, null, handler).Result;
|
||||
|
||||
client.Log($"Получено запросов: {n}");
|
||||
}
|
||||
|
||||
public static void DemoExportOneDebtRequest(HcsClient client)
|
||||
{
|
||||
HcsDebtSubrequest s;
|
||||
if (client.IsPPAK) s = client.DebtRequests.ExportDSRByRequestNumber("01202411454682").Result;
|
||||
else s = client.DebtRequests.ExportDSRByRequestNumber("0120241061").Result;
|
||||
client.Log($"Получен: {s}");
|
||||
}
|
||||
|
||||
public static void DemoImportOneDebtResponse(HcsClient client)
|
||||
{
|
||||
HcsDebtSubrequest s;
|
||||
if (client.IsPPAK) s = client.DebtRequests.ExportDSRByRequestNumber("01202411454682").Result;
|
||||
else s = client.DebtRequests.ExportDSRByRequestNumber("0120241061").Result;
|
||||
if (s == null) Console.WriteLine("Ошибка: подзапрос не найден");
|
||||
|
||||
var response = new HcsDebtResponse();
|
||||
response.TransportGuid = Guid.NewGuid();
|
||||
response.SubrequestGuid = s.SubrequestGuid;
|
||||
|
||||
// Если указывается наличие долга обязательно указание ФИО должников
|
||||
response.HasDebt = false;
|
||||
//response.PersonalData = new HcsPersonalData[] { new HcsPersonalData() {
|
||||
// FirstName = "A", MiddleName = "B", LastName = "C"
|
||||
//}};
|
||||
|
||||
var result = client.DebtRequests.ImportDSRResponse(response).Result;
|
||||
if (result.HasError) Console.WriteLine("Возникла ошибка по время отправки: " + result.Error);
|
||||
else Console.WriteLine("Запрос успешно выполнен: " + result.UpdateDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
Hcs.TestApp/ClientDemo/FileStoreDemo.cs
Normal file
67
Hcs.TestApp/ClientDemo/FileStoreDemo.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Hcs.ClientApi;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace Hcs.ClientDemo
|
||||
{
|
||||
public class FileStoreDemo
|
||||
{
|
||||
public static void DemoDownloadFile(HcsClient hcsClient)
|
||||
{
|
||||
Guid fileGuid = new Guid("e4c3b39f-ad59-11ef-bc8e-0242ac120002");
|
||||
|
||||
var file = hcsClient.FileStoreService.DownloadFile(
|
||||
fileGuid, HcsFileStoreContext.homemanagement, CancellationToken.None).Result;
|
||||
Console.WriteLine("\nКонтент len=" + file.Length +
|
||||
" type=" + file.ContentType + " streamLength=" + file.Stream.Length +
|
||||
" hash=" + hcsClient.ComputeGost94Hash(file.Stream));
|
||||
|
||||
using (var s = new FileStream(@"D:\temp\teplo0.pdf", FileMode.CreateNew, FileAccess.Write))
|
||||
{
|
||||
file.Stream.Seek(0, SeekOrigin.Begin);
|
||||
file.Stream.CopyTo(s);
|
||||
s.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DemoUploadFile(HcsClient hcsClient)
|
||||
{
|
||||
string sourceFileName = @"D:\temp\Проект договора.docx";
|
||||
|
||||
var contentType = HcsFile.GetMimeContentTypeForFileName(sourceFileName);
|
||||
if (contentType == null) throw new HcsException("Не найден тип mime для файла");
|
||||
|
||||
Console.WriteLine("Выгружаем файл: " + sourceFileName);
|
||||
using (var stream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
var file = new HcsFile(Path.GetFileName(sourceFileName), contentType, stream);
|
||||
var guid = hcsClient.FileStoreService.UploadFile(
|
||||
file, HcsFileStoreContext.homemanagement, CancellationToken.None).Result;
|
||||
Console.WriteLine("Выгруженный файл GUID=" + guid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DemoGetFileLength(HcsClient hcsClient)
|
||||
{
|
||||
Guid fileGuid = new Guid("33ddc355-60bd-4537-adf6-fbb31322e16f");
|
||||
var length = hcsClient.FileStoreService.GetFileLength(
|
||||
HcsFileStoreContext.homemanagement, fileGuid, CancellationToken.None).Result;
|
||||
Console.WriteLine($"\nДлина = {length} для файла с GUID " + fileGuid);
|
||||
}
|
||||
|
||||
public static void DemoGostHash(HcsClient hcsClient)
|
||||
{
|
||||
PrintFileHash(hcsClient, @"D:\temp\teplo0.pdf");
|
||||
}
|
||||
|
||||
public static void PrintFileHash(HcsClient hcsClient, string fileName)
|
||||
{
|
||||
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
var hash = hcsClient.ComputeGost94Hash(stream);
|
||||
Console.WriteLine($"{fileName} hash=" + hash + " len=" + new FileInfo(fileName).Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
153
Hcs.TestApp/ClientDemo/HouseManagementDemo.cs
Normal file
153
Hcs.TestApp/ClientDemo/HouseManagementDemo.cs
Normal file
@ -0,0 +1,153 @@
|
||||
using Hcs.ClientApi;
|
||||
using Hcs.ClientApi.DataTypes;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Hcs.ClientDemo
|
||||
{
|
||||
public class HouseManagementDemo
|
||||
{
|
||||
public static void DemoExportOrgRegistry(HcsClient client)
|
||||
{
|
||||
string ogrn = "1061001043421";
|
||||
string kpp = "";
|
||||
var orgs = client.OrgRegistryCommon.GetOrgByOgrn(ogrn, kpp).Result;
|
||||
Console.WriteLine($"Организация с ОГРН={ogrn} имеет {orgs.Count()} orgs:");
|
||||
foreach (var org in orgs)
|
||||
Console.WriteLine($" {org}");
|
||||
}
|
||||
|
||||
public static void DemoExportOneContract(HcsClient client)
|
||||
{
|
||||
var guid = new Guid("2d393e41-b7e2-4125-9593-c4127617e3f8");
|
||||
var договор = client.HouseManagement.ПолучитьДоговорРСО(guid).Result;
|
||||
Console.WriteLine($"Получен договор №{договор.НомерДоговора} Статус={договор.СтатусВерсииДоговора}");
|
||||
|
||||
if (договор.ПриложенияДоговора != null && договор.ПриложенияДоговора.Length > 0)
|
||||
{
|
||||
var приложение = договор.ПриложенияДоговора[0];
|
||||
Console.WriteLine($"Приложение: {приложение.ИмяПриложения} HASH={приложение.ХэшПриложения}");
|
||||
FileStoreDemo.PrintFileHash(client, $"d:\\\\temp\\{приложение.ИмяПриложения}");
|
||||
}
|
||||
}
|
||||
|
||||
public static void DemoTerminateOneContract(HcsClient client)
|
||||
{
|
||||
var guid = new Guid("c7418f95-8ec5-40a3-9474-c4924e17409e");
|
||||
var договор = client.HouseManagement.ПолучитьДоговорРСО(guid).Result;
|
||||
Console.WriteLine($"Получен договор №{договор.НомерДоговора} Статус={договор.СтатусВерсииДоговора}");
|
||||
|
||||
var d = client.HouseManagement.РасторгнутьДоговор(договор, new DateTime(2019, 4, 1)).Result;
|
||||
Console.WriteLine($"Дата внесения расторжения договора: {d}");
|
||||
}
|
||||
|
||||
public static void DemoImportNewContract(HcsClient client)
|
||||
{
|
||||
var договор = new ГисДоговор();
|
||||
договор.ТипДоговораРСО = ГисТипДоговораРСО.ПубличныйИлиНежилые;
|
||||
договор.НомерДоговора = "100-1-41-21900-01";
|
||||
договор.ДатаЗаключения = new DateTime(2007, 7, 1);
|
||||
|
||||
// TODO: Заполнить контрагента получив его GUID через OrgRegistryService по ОГРН
|
||||
договор.Контрагент = new ГисКонтрагент();
|
||||
|
||||
// TODO: Заполнить хотя бы один адрес
|
||||
var адреса = new List<ГисАдресныйОбъект>();
|
||||
var d = client.HouseManagement.РазместитьДоговор(договор, адреса).Result;
|
||||
Console.WriteLine($"Дата внесения нового договора: {d}");
|
||||
}
|
||||
|
||||
public static void DemoExportContractTrees(HcsClient client)
|
||||
{
|
||||
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
|
||||
Func<ГисДоговор, bool> contractFilter = (договор) =>
|
||||
{
|
||||
if (договор.СтатусВерсииДоговора == ГисСтатусВерсииДоговора.Аннулирован) return false;
|
||||
if (договор.СтатусВерсииДоговора == ГисСтатусВерсииДоговора.Расторгнут) return false;
|
||||
// ГИС возвращает проекты, но не может их найти по коду
|
||||
if (договор.СтатусВерсииДоговора == ГисСтатусВерсииДоговора.Проект) return false;
|
||||
if ("ЭККУК" == договор.НомерДоговора) return false;
|
||||
if ("ЭККЧС" == договор.НомерДоговора) return false;
|
||||
if ("ЭККНСУ" == договор.НомерДоговора) return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
var все = client.HouseManagement.ПолучитьВсеДоговорыИПриборы(contractFilter).Result;
|
||||
|
||||
using (StreamWriter file = File.CreateText(@"all.json"))
|
||||
{
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.Serialize(file, все);
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"{все}: {stopwatch.Elapsed}");
|
||||
}
|
||||
|
||||
public static void DemoExportMeteringDevices(HcsClient client)
|
||||
{
|
||||
Action<ГисПриборУчета> resultHandler = (прибор) =>
|
||||
{
|
||||
Console.WriteLine("" + прибор);
|
||||
};
|
||||
|
||||
// ул. Мурманская, 1А
|
||||
var houseGuid = new Guid("0c94cace-2030-4b0a-97c4-de85eef83282");
|
||||
var n = client.HouseManagement.ПолучитьПриборыУчетаПоЗданию(houseGuid, resultHandler).Result;
|
||||
Console.WriteLine("n = " + n);
|
||||
}
|
||||
|
||||
public static void DemoExportContractAddressObjects(HcsClient client)
|
||||
{
|
||||
Action<ГисАдресныйОбъект> resultHandler = (адрес) =>
|
||||
{
|
||||
Console.WriteLine("" + адрес);
|
||||
};
|
||||
|
||||
var гуидДоговора = new Guid("4f8b6688-ef14-43e6-99a9-846e59cd82e8");
|
||||
var договор = new ГисДоговор() { ГуидДоговора = гуидДоговора };
|
||||
var n = client.HouseManagement.ПолучитьАдресаДоговораРСО(договор, resultHandler).Result;
|
||||
Console.WriteLine("n = " + n);
|
||||
}
|
||||
|
||||
public static void DemoExportAccounts(HcsClient client)
|
||||
{
|
||||
Action<ГисЛицевойСчет> resultHandler = (лс) =>
|
||||
{
|
||||
Console.WriteLine("" + лс);
|
||||
};
|
||||
|
||||
// ул. Мурманская, 1А
|
||||
var houseGuid = new Guid("0c94cace-2030-4b0a-97c4-de85eef83282");
|
||||
var n = client.HouseManagement.ПолучитьЛицевыеСчетаПоЗданию(houseGuid, resultHandler).Result;
|
||||
Console.WriteLine("n = " + n);
|
||||
}
|
||||
|
||||
public static void DemoExportSupplyResourceContracts(HcsClient client)
|
||||
{
|
||||
var договоры = new List<ГисДоговор>();
|
||||
Action<ГисДоговор> resultHandler = (договорРСО) => { договоры.Add(договорРСО); };
|
||||
var n = client.HouseManagement.ПолучитьДоговорыРСО(resultHandler).Result;
|
||||
|
||||
договоры.Sort((x, y) => string.Compare(x.НомерДоговора, y.НомерДоговора));
|
||||
договоры.ForEach(x => Console.WriteLine(x.ToString()));
|
||||
Console.WriteLine("n = " + n);
|
||||
}
|
||||
|
||||
public static void DemoExportOneHouse(HcsClient client)
|
||||
{
|
||||
// Петрозаводск, Лисицыной, 19
|
||||
var guid = Guid.Parse("6596ad9d-fee2-4c5b-8249-dbf78b0281b9");
|
||||
var здание = client.HouseManagement.ПолучитьЗданиеПоГуидФиас(guid).Result;
|
||||
Console.WriteLine("ГисЗдание = " + здание);
|
||||
foreach (var помещение in здание.Помещения)
|
||||
{
|
||||
Console.WriteLine(помещение.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
78
Hcs.TestApp/ClientDemo/Program.cs
Normal file
78
Hcs.TestApp/ClientDemo/Program.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using Hcs.ClientApi;
|
||||
using System;
|
||||
|
||||
namespace Hcs.ClientDemo
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Демонстрационная программа вызова функций ГИС ЖКХ
|
||||
/// </summary>
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Чтобы сообщения об ошибках показывались на английском языке
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture =
|
||||
new System.Globalization.CultureInfo("en-US");
|
||||
|
||||
var client = new HcsClient();
|
||||
client.Logger = new HcsConsoleLogger();
|
||||
|
||||
// Чтобы создавались файлы сообщений и ответов системы
|
||||
//client.MessageCapture = new HcsFileWriterMessageCapture(null, client.Logger);
|
||||
|
||||
var cert = client.FindCertificate(x => x.SerialNumber == "02DD0FE0006DB0C5B24666AB8F30C74780");
|
||||
if (cert == null) return;
|
||||
|
||||
Console.WriteLine("Сертификат: " + cert.Subject);
|
||||
|
||||
client.SetSigningCertificate(cert);
|
||||
|
||||
// Промышленный или тестовый стенд
|
||||
client.IsPPAK = false;
|
||||
if (client.IsPPAK)
|
||||
{
|
||||
// GUID поставщика информации ЭКК ППАК (20.05.2022)
|
||||
client.OrgPPAGUID = "488d95f6-4f6a-4e4e-b78a-ea259ef0ded2";
|
||||
// Исполнитель/cотрудник ГИСЖКХ: ЛСА/КЛА
|
||||
client.ExecutorGUID = "e0cba564-b675-4077-b7da-356b18301bc2";
|
||||
}
|
||||
else
|
||||
{
|
||||
// GUID поставщика информации ЭКК СИТ02 (18.01.2024)
|
||||
client.OrgPPAGUID = "ee6b2615-c488-420c-a553-0ef31d65b77e";
|
||||
// Сотрудник тестового стенда СИТ02
|
||||
client.ExecutorGUID = "d284368e-849c-4002-a815-c8b199d35b05";
|
||||
}
|
||||
|
||||
#pragma warning disable CS0162
|
||||
try
|
||||
{
|
||||
if (false) DebtRequestsDemo.DemoExportOneDebtRequest(client);
|
||||
if (false) DebtRequestsDemo.DemoExportManySubrequests(client);
|
||||
if (false) DebtRequestsDemo.DemoImportOneDebtResponse(client);
|
||||
|
||||
if (false) HouseManagementDemo.DemoExportOneHouse(client);
|
||||
if (false) HouseManagementDemo.DemoExportSupplyResourceContracts(client);
|
||||
if (false) HouseManagementDemo.DemoExportAccounts(client);
|
||||
if (false) HouseManagementDemo.DemoExportContractAddressObjects(client);
|
||||
if (false) HouseManagementDemo.DemoExportMeteringDevices(client);
|
||||
if (false) HouseManagementDemo.DemoExportOneContract(client);
|
||||
if (false) HouseManagementDemo.DemoExportContractTrees(client);
|
||||
if (false) HouseManagementDemo.DemoImportNewContract(client);
|
||||
if (true) HouseManagementDemo.DemoExportOrgRegistry(client);
|
||||
|
||||
if (false) FileStoreDemo.DemoDownloadFile(client);
|
||||
if (false) FileStoreDemo.DemoGostHash(client);
|
||||
if (false) FileStoreDemo.DemoUploadFile(client);
|
||||
if (false) FileStoreDemo.DemoGetFileLength(client);
|
||||
if (false) FileStoreDemo.DemoGostHash(client);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
Console.ReadKey();
|
||||
}
|
||||
#pragma warning restore CS0162
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user