Первый
This commit is contained in:
commit
829636b78c
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#Ignore thumbnails created by Windows
|
||||
Thumbs.db
|
||||
#Ignore files built by Visual Studio
|
||||
*.obj
|
||||
*.exe
|
||||
*.pdb
|
||||
*.user
|
||||
*.aps
|
||||
*.pch
|
||||
*.vspscc
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ncb
|
||||
*.suo
|
||||
*.tlb
|
||||
*.tlh
|
||||
*.bak
|
||||
*.cache
|
||||
*.ilk
|
||||
*.log
|
||||
[Bb]in
|
||||
[Dd]ebug*/
|
||||
*.lib
|
||||
*.sbr
|
||||
obj/
|
||||
[Rr]elease*/
|
||||
_ReSharper*/
|
||||
[Tt]est[Rr]esult*
|
||||
.vs/
|
||||
#Nuget packages folder
|
||||
packages/
|
25
HRM_MQ_Consumer_Service.sln
Normal file
25
HRM_MQ_Consumer_Service.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HRM_MQ_Consumer_Service", "HRM_MQ_Consumer_Service\HRM_MQ_Consumer_Service.csproj", "{4E5D446E-7AF9-490D-B503-59BCBFCCA63F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4E5D446E-7AF9-490D-B503-59BCBFCCA63F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4E5D446E-7AF9-490D-B503-59BCBFCCA63F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4E5D446E-7AF9-490D-B503-59BCBFCCA63F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4E5D446E-7AF9-490D-B503-59BCBFCCA63F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FE5F9BE8-894B-42E9-8127-8146CF8E0163}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
67
HRM_MQ_Consumer_Service/App.config
Normal file
67
HRM_MQ_Consumer_Service/App.config
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.1" newVersion="8.0.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.OData.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-7.21.0.0" newVersion="7.21.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.OData.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-7.21.0.0" newVersion="7.21.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Spatial" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-7.21.0.0" newVersion="7.21.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<appSettings>
|
||||
<add key="rabbitmq_host_name" value="astsrvrabbit1" />
|
||||
<add key="rabbitmq_user_name" value="erp" />
|
||||
<add key="rabbitmq_password" value="Z!1;Q5#GE4v" />
|
||||
<add key="rabbitmq_virtualhost" value="erp" />
|
||||
<!--<add key="rabbitmq_queue_name" value="counterparty_1c_exchange" />-->
|
||||
<add key="rabbitmq_queue_name" value="erp_1c_test" />
|
||||
<!--<add key="qdoc_integration_service_url" value="https://qdoc.solidcore-resources.com/Integration/odata/" />-->
|
||||
<add key="qdoc_integration_service_url" value="https://astsrvqtest.solidcore-resources.com/Integration/odata/" />
|
||||
<add key="qdoc_login" value="Administrator" />
|
||||
<!--<add key="qdoc_password" value="MQVuEw9avO" />-->
|
||||
<add key="qdoc_password" value="D3cTXol8Se" />
|
||||
</appSettings>
|
||||
</configuration>
|
37
HRM_MQ_Consumer_Service/HRMConsumerService.Designer.cs
generated
Normal file
37
HRM_MQ_Consumer_Service/HRMConsumerService.Designer.cs
generated
Normal file
@ -0,0 +1,37 @@
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
partial class HRMConsumerService
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
this.ServiceName = "Service1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
77
HRM_MQ_Consumer_Service/HRMConsumerService.cs
Normal file
77
HRM_MQ_Consumer_Service/HRMConsumerService.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using HRM_MQ_Consumer_Service.Parsers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
public partial class HRMConsumerService : ServiceBase
|
||||
{
|
||||
private ConnectionFactory connectionFactory = new ConnectionFactory
|
||||
{
|
||||
HostName = ConfigurationManager.AppSettings["rabbitmq_host_name"],
|
||||
UserName = ConfigurationManager.AppSettings["rabbitmq_user_name"],
|
||||
Password = ConfigurationManager.AppSettings["rabbitmq_password"],
|
||||
VirtualHost = ConfigurationManager.AppSettings["rabbitmq_virtualhost"]
|
||||
};
|
||||
private IConnection _connection;
|
||||
private IChannel _channel;
|
||||
private AsyncEventingBasicConsumer _consumer;
|
||||
private CounterpartyJSONParser _counterpartyParser;
|
||||
public HRMConsumerService()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
internal void TestStatupAndStop(string[] args)
|
||||
{
|
||||
this.OnStart(args);
|
||||
Console.ReadLine();
|
||||
this.OnStop();
|
||||
}
|
||||
|
||||
protected override async void OnStart(string[] args)
|
||||
{
|
||||
string queue = ConfigurationManager.AppSettings["rabbitmq_queue_name"];
|
||||
_connection = await connectionFactory.CreateConnectionAsync();
|
||||
_channel = await _connection.CreateChannelAsync();
|
||||
await _channel.QueueDeclareAsync(
|
||||
queue: queue,
|
||||
durable: false,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
_consumer = new AsyncEventingBasicConsumer(_channel);
|
||||
_counterpartyParser = new CounterpartyJSONParser();
|
||||
_consumer.ReceivedAsync += async (model, ea) =>
|
||||
{
|
||||
var body = ea.Body.ToArray();
|
||||
var message = Encoding.UTF8.GetString(body);
|
||||
var result = await _counterpartyParser.Parse(message);
|
||||
//var result = await _counterpartyParser.Parse(message);
|
||||
//Console.WriteLine($"Recieved {message}");
|
||||
};
|
||||
await _channel.BasicConsumeAsync(
|
||||
queue: queue,
|
||||
autoAck: true,
|
||||
consumer: _consumer);
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
_channel?.Dispose();
|
||||
_connection?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
159
HRM_MQ_Consumer_Service/HRM_MQ_Consumer_Service.csproj
Normal file
159
HRM_MQ_Consumer_Service/HRM_MQ_Consumer_Service.csproj
Normal file
@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4E5D446E-7AF9-490D-B503-59BCBFCCA63F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>HRM_MQ_Consumer_Service</RootNamespace>
|
||||
<AssemblyName>HRM_MQ_Consumer_Service</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=9.0.0.6, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.9.0.6\lib\net462\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.ObjectPool, Version=8.0.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.ObjectPool.8.0.4\lib\net462\Microsoft.Extensions.ObjectPool.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Primitives, Version=9.0.0.6, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Primitives.9.0.6\lib\net462\Microsoft.Extensions.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.OData.Core, Version=7.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.OData.Core.7.21.0\lib\net45\Microsoft.OData.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.OData.Edm, Version=7.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.OData.Edm.7.21.0\lib\net45\Microsoft.OData.Edm.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Spatial, Version=7.21.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Spatial.7.21.0\lib\net45\Microsoft.Spatial.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RabbitMQ.Client, Version=7.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\RabbitMQ.Client.7.1.2\lib\netstandard2.0\RabbitMQ.Client.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Simple.OData.Client.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58885f4495efc1ae, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Simple.OData.V4.Client.6.0.1\lib\net461\Simple.OData.Client.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Simple.OData.Client.Dynamic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58885f4495efc1ae, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Simple.OData.V4.Client.6.0.1\lib\net461\Simple.OData.Client.Dynamic.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Simple.OData.Client.V4.Adapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58885f4495efc1ae, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Simple.OData.V4.Client.6.0.1\lib\net461\Simple.OData.Client.V4.Adapter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=8.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Pipelines, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.IO.Pipelines.8.0.0\lib\net462\System.IO.Pipelines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encodings.Web, Version=4.0.5.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.4.7.2\lib\net461\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.4.6.0\lib\net461\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Channels, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Channels.8.0.0\lib\net462\System.Threading.Channels.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.RateLimiting, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.RateLimiting.8.0.0\lib\net462\System.Threading.RateLimiting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Logger\Logger.cs" />
|
||||
<Compile Include="OData\ODataAccess.cs" />
|
||||
<Compile Include="OData\QDocWrapper.cs" />
|
||||
<Compile Include="Parsers\CounterpartyJSONParser.cs" />
|
||||
<Compile Include="Structure\CounterParty.cs" />
|
||||
<Compile Include="Parsers\CounterpartyXMLParser.cs" />
|
||||
<Compile Include="Structure\CounterParty1C.cs" />
|
||||
<Compile Include="Structure\PackageInfo.cs" />
|
||||
<Compile Include="ProjectInstaller.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ProjectInstaller.Designer.cs">
|
||||
<DependentUpon>ProjectInstaller.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="HRMConsumerService.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="HRMConsumerService.Designer.cs">
|
||||
<DependentUpon>HRMConsumerService.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="ProjectInstaller.resx">
|
||||
<DependentUpon>ProjectInstaller.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
127
HRM_MQ_Consumer_Service/Logger/Logger.cs
Normal file
127
HRM_MQ_Consumer_Service/Logger/Logger.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service.Logger
|
||||
{
|
||||
public enum LogLevel
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
public class Logger
|
||||
{
|
||||
//private readonly string _name;
|
||||
//private readonly string _logDirPath;
|
||||
|
||||
public Logger(string name, string logDirPath = "log\\")
|
||||
{
|
||||
_name = name;
|
||||
_directoryPath = logDirPath;
|
||||
|
||||
if (!Directory.Exists(logDirPath))
|
||||
{
|
||||
Directory.CreateDirectory(logDirPath);
|
||||
}
|
||||
// Ensure the log file exists or create it
|
||||
//if (!File.Exists(_logFilePath))
|
||||
//{
|
||||
// using (File.Create(_logFilePath)) { }
|
||||
//}
|
||||
}
|
||||
|
||||
private string _name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
|
||||
private string _directoryPath;
|
||||
|
||||
public string DirectoryPath
|
||||
{
|
||||
get { return _directoryPath; }
|
||||
set { _directoryPath = value; }
|
||||
}
|
||||
|
||||
public void Log(LogLevel level, string message)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(message);
|
||||
var str = Encoding.UTF8.GetString(bytes);
|
||||
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
var logMessage = $"[{timestamp}] [{level}] [{_name}] {str}";
|
||||
|
||||
// Write to console (optional)
|
||||
WriteToConsole(level, logMessage);
|
||||
|
||||
// Write to file
|
||||
WriteToFile(logMessage);
|
||||
}
|
||||
|
||||
private void WriteToConsole(LogLevel level, string message)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case LogLevel.Info:
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
break;
|
||||
case LogLevel.Warning:
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
break;
|
||||
case LogLevel.Error:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
break;
|
||||
default:
|
||||
Console.ResetColor();
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine(message);
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
private void WriteToFile(string message)
|
||||
{
|
||||
var today = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
var filePath = $"{_directoryPath}\\{today}_{_name}.txt";
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
using (File.Create(filePath)) { }
|
||||
}
|
||||
try
|
||||
{
|
||||
// Append the log message to the file
|
||||
using (StreamWriter writer = new StreamWriter(filePath, true, Encoding.UTF8))
|
||||
{
|
||||
writer.WriteLine(message);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Failed to write to log file: {ex.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
public void Info(string message)
|
||||
{
|
||||
Log(LogLevel.Info, message);
|
||||
}
|
||||
|
||||
public void Warn(string message)
|
||||
{
|
||||
Log(LogLevel.Warning, message);
|
||||
}
|
||||
|
||||
public void Error(string message)
|
||||
{
|
||||
Log(LogLevel.Error, message);
|
||||
}
|
||||
}
|
||||
}
|
41
HRM_MQ_Consumer_Service/OData/ODataAccess.cs
Normal file
41
HRM_MQ_Consumer_Service/OData/ODataAccess.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Simple.OData.Client;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Net.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service.OData
|
||||
{
|
||||
public class ODataAccess
|
||||
{
|
||||
// URL сервиса интеграции.
|
||||
|
||||
private string IntegrationServiceUrl;
|
||||
private string Login;
|
||||
private string Password;
|
||||
|
||||
//private const string IntegrationServiceUrl = "https://qdoc.solidcore-resources.com/Integration/odata/";
|
||||
//private const string Login = "Administrator";
|
||||
//private const string Password = "MQVuEw9avO";
|
||||
|
||||
public ODataAccess()
|
||||
{
|
||||
IntegrationServiceUrl = ConfigurationManager.AppSettings["qdoc_integration_service_url"];
|
||||
Login = ConfigurationManager.AppSettings["qdoc_login"];
|
||||
Password = ConfigurationManager.AppSettings["qdoc_password"];
|
||||
// Настройки Simple OData Client: добавление ко всем запросам URL сервиса и
|
||||
// заголовка с данными аутентификации.
|
||||
var odataClientSettings = new ODataClientSettings(new Uri(IntegrationServiceUrl));
|
||||
odataClientSettings.BeforeRequest += (HttpRequestMessage message) =>
|
||||
{
|
||||
var authenticationHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Login}:{Password}"));
|
||||
message.Headers.Add("Authorization", "Basic " + authenticationHeaderValue);
|
||||
};
|
||||
Client = new ODataClient(odataClientSettings);
|
||||
}
|
||||
|
||||
public ODataClient Client { get; set; }
|
||||
}
|
||||
}
|
184
HRM_MQ_Consumer_Service/OData/QDocWrapper.cs
Normal file
184
HRM_MQ_Consumer_Service/OData/QDocWrapper.cs
Normal file
@ -0,0 +1,184 @@
|
||||
using HRM_MQ_Consumer_Service.Structure;
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service.OData
|
||||
{
|
||||
public class QDocWrapper
|
||||
{
|
||||
private ODataClient _client;
|
||||
private Logger.Logger _logger;
|
||||
|
||||
public QDocWrapper(Logger.Logger logger)
|
||||
{
|
||||
var oDataAccess = new ODataAccess();
|
||||
_client = oDataAccess.Client;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<CounterParty> GetCompanyByBIN(string bin)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(bin))
|
||||
{
|
||||
var company = await _client
|
||||
.For("ICompanies")
|
||||
.Expand("HeadCompany")
|
||||
.Filter($"BINArmadoc eq '{bin}'")
|
||||
.FindEntryAsync();
|
||||
if (company != null)
|
||||
{
|
||||
var result = new CounterParty
|
||||
{
|
||||
Id = (long)company["Id"],
|
||||
Name = company["Name"]?.ToString(),
|
||||
LegalAddress = company["LegalAddress"]?.ToString(),
|
||||
PostalAddress = company["PostalAddress"]?.ToString(),
|
||||
GeneralCompany = company["HeadCompany"]?.ToString(),
|
||||
Code = company["Code"]?.ToString(),
|
||||
Guid = company["ExternalId"]?.ToString(),
|
||||
Resident = !(bool)company["Nonresident"],
|
||||
LegalName = company["LegalName"]?.ToString(),
|
||||
Bin = company["BINArmadoc"]?.ToString()
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<CounterParty> GetCompanyByGuid(string guid)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(guid))
|
||||
{
|
||||
var company = await _client
|
||||
.For("ICompanies")
|
||||
.Expand("HeadCompany")
|
||||
.Filter($"ExternalId eq '{guid}'")
|
||||
.FindEntryAsync();
|
||||
if (company != null)
|
||||
{
|
||||
var result = new CounterParty
|
||||
{
|
||||
Id = (long)company["Id"],
|
||||
Name = company["Name"]?.ToString(),
|
||||
LegalAddress = company["LegalAddress"]?.ToString(),
|
||||
PostalAddress = company["PostalAddress"]?.ToString(),
|
||||
GeneralCompany = company["HeadCompany"]?.ToString(),
|
||||
Code = company["Code"]?.ToString(),
|
||||
Guid = company["ExternalId"]?.ToString(),
|
||||
Resident = !(bool)company["Nonresident"],
|
||||
LegalName = company["LegalName"]?.ToString(),
|
||||
Bin = company["BINArmadoc"]?.ToString()
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<bool> GetBusinessUnitByBin(string bin)
|
||||
{
|
||||
bool result = false;
|
||||
if (!string.IsNullOrEmpty(bin))
|
||||
{
|
||||
var businessUnit = await _client
|
||||
.For("ICompanies")
|
||||
.Expand("HeadCompany")
|
||||
.Filter($"ExternalId eq '{bin}'")
|
||||
.FindEntryAsync();
|
||||
if (businessUnit != null) result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task UpdateCounterparty(CounterParty counterparty)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (counterparty == null) return;
|
||||
var newCounterparty = new
|
||||
{
|
||||
counterparty.Name,
|
||||
counterparty.LegalName,
|
||||
ExternalId = counterparty.Guid,
|
||||
Status = counterparty.Deleted == "true" ? "Closed" : "Active",
|
||||
counterparty.LegalAddress,
|
||||
counterparty.PostalAddress,
|
||||
Nonresident = counterparty.Resident != true ? true : false,
|
||||
BINArmadoc = counterparty.Bin != null ? counterparty.Bin : string.Empty,
|
||||
TIN = counterparty.Tin != null ? counterparty.Tin : string.Empty
|
||||
};
|
||||
await _client
|
||||
.For("ICompanies")
|
||||
.Key(counterparty.UpdCounterparty.Id)
|
||||
.Set(newCounterparty)
|
||||
.UpdateEntryAsync();
|
||||
_logger.Info($"{counterparty.Name} updated.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"{counterparty.Name} - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task CreateCounterparty(CounterParty counterparty)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (counterparty == null) return;
|
||||
var newCounterparty = new
|
||||
{
|
||||
counterparty.Name,
|
||||
counterparty.LegalName,
|
||||
ExternalId = counterparty.Guid,
|
||||
Status = counterparty.Deleted == "true" ? "Active" : "Closed",
|
||||
counterparty.LegalAddress,
|
||||
counterparty.PostalAddress,
|
||||
Nonresident = counterparty.Resident != true ? true : false,
|
||||
BINArmadoc = counterparty.Resident == true ? counterparty.Bin : string.Empty,
|
||||
TIN = counterparty.Resident == false ? counterparty.Bin : string.Empty
|
||||
};
|
||||
await _client
|
||||
.For("ICompanies")
|
||||
.Set(newCounterparty)
|
||||
.InsertEntryAsync();
|
||||
_logger.Info($"{counterparty.Name} created.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"{counterparty.Name} - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task CreateCounterparty(CounterParty1C counterparty)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (counterparty == null) return;
|
||||
var newCounterparty = new
|
||||
{
|
||||
counterparty.Name,
|
||||
counterparty.LegalName,
|
||||
ExternalId = counterparty.Guid,
|
||||
Nonresident = counterparty.NonResident,
|
||||
BINArmadoc = counterparty.NonResident != true ? counterparty.BIN : string.Empty,
|
||||
TIN = counterparty.NonResident != false ? counterparty.BIN : string.Empty
|
||||
};
|
||||
await _client
|
||||
.For("ICompanies")
|
||||
.Set(newCounterparty)
|
||||
.InsertEntryAsync();
|
||||
_logger.Info($"{counterparty.Name} created.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"{counterparty.Name} - {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
HRM_MQ_Consumer_Service/Parsers/CounterpartyJSONParser.cs
Normal file
54
HRM_MQ_Consumer_Service/Parsers/CounterpartyJSONParser.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using HRM_MQ_Consumer_Service.OData;
|
||||
using HRM_MQ_Consumer_Service.Structure;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service.Parsers
|
||||
{
|
||||
internal class CounterpartyJSONParser
|
||||
{
|
||||
private Logger.Logger _logger;
|
||||
private static QDocWrapper _wrapper;
|
||||
|
||||
public CounterpartyJSONParser()
|
||||
{
|
||||
_logger = new Logger.Logger("Counterparties_test");
|
||||
_wrapper = new QDocWrapper(_logger);
|
||||
}
|
||||
|
||||
public async Task<bool> Parse(string message)
|
||||
{
|
||||
bool result = false;
|
||||
CounterParty company;
|
||||
var converted = JsonConvert.DeserializeObject<CounterParty1C>(message);
|
||||
var found = await TryFindCompany(converted);
|
||||
if (found != null)
|
||||
{
|
||||
await _wrapper.UpdateCounterparty(found);
|
||||
}
|
||||
else await _wrapper.CreateCounterparty(converted);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<CounterParty> TryFindCompany(CounterParty1C converted)
|
||||
{
|
||||
CounterParty company;
|
||||
|
||||
company = await _wrapper.GetCompanyByGuid(converted.Guid);
|
||||
|
||||
if (company == null)
|
||||
{
|
||||
company = await _wrapper.GetCompanyByBIN(converted.BIN);
|
||||
}
|
||||
if (company != null)
|
||||
{
|
||||
company.UpdCounterparty = new CounterParty { Id = company.Id };
|
||||
}
|
||||
return company;
|
||||
}
|
||||
}
|
||||
}
|
169
HRM_MQ_Consumer_Service/Parsers/CounterpartyXMLParser.cs
Normal file
169
HRM_MQ_Consumer_Service/Parsers/CounterpartyXMLParser.cs
Normal file
@ -0,0 +1,169 @@
|
||||
using HRM_MQ_Consumer_Service.OData;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service.Parsers
|
||||
{
|
||||
internal class CounterpartyXMLParser
|
||||
{
|
||||
private Logger.Logger _logger;
|
||||
private static QDocWrapper _wrapper;
|
||||
|
||||
public CounterpartyXMLParser()
|
||||
{
|
||||
_logger = new Logger.Logger("Counterparties_test");
|
||||
_wrapper = new QDocWrapper(_logger);
|
||||
}
|
||||
public async Task<bool> Parse(string message)
|
||||
{
|
||||
var package = new PackageInfo();
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml(message);
|
||||
XmlElement xRoot = xml.DocumentElement;
|
||||
XmlNodeList nodes = xRoot.SelectNodes("*");
|
||||
package = GetPackageInfo(nodes, package);
|
||||
|
||||
foreach (var counterparty in package.AllLoadedComp)
|
||||
{
|
||||
if (counterparty.UpdCounterparty != null)
|
||||
{
|
||||
await _wrapper.UpdateCounterparty(counterparty);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _wrapper.CreateCounterparty(counterparty);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Info("Package loading complete.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static PackageInfo GetPackageInfo(XmlNodeList nodeList, PackageInfo packageInfo)
|
||||
{
|
||||
foreach (XmlNode node in nodeList)
|
||||
{
|
||||
packageInfo = RecurseXmlDocumentNoSiblings(node, packageInfo);
|
||||
}
|
||||
return packageInfo;
|
||||
}
|
||||
|
||||
private static PackageInfo RecurseXmlDocumentNoSiblings(XmlNode root, PackageInfo packageInfo)
|
||||
{
|
||||
if (root is XmlElement)
|
||||
{
|
||||
if (root.HasChildNodes)
|
||||
return RecurseXmlDocument(root.FirstChild, packageInfo).Result;
|
||||
}
|
||||
return packageInfo;
|
||||
}
|
||||
|
||||
private static async Task<PackageInfo> RecurseXmlDocument(XmlNode root, PackageInfo packageInfo)
|
||||
{
|
||||
if (root is XmlElement)
|
||||
{
|
||||
if (root.Name == "m:Дата")
|
||||
// Dialogs.NotifyMessage("Дата отправки пакета " + root.InnerText);
|
||||
packageInfo.DateReceived = DateTime.Parse(root.InnerText);
|
||||
if (root.Name == "m:Номер")
|
||||
// Dialogs.NotifyMessage("Номер пакета " + root.InnerText);
|
||||
packageInfo.Id = root.InnerText;
|
||||
if (root.Name == "m:Объекты")
|
||||
{
|
||||
|
||||
XmlNodeList allObjLoad = root.ChildNodes;
|
||||
if (allObjLoad.Count > 0)
|
||||
{
|
||||
//"Осуществляется загрузка контрагентов со следующими параметрами:"
|
||||
|
||||
foreach (XmlNode item in allObjLoad)
|
||||
{
|
||||
CounterParty tempCompany = null;
|
||||
tempCompany = new CounterParty();
|
||||
foreach (XmlNode Countparty in item.ChildNodes)
|
||||
{
|
||||
if (Countparty.Name == "m:Тип" && Countparty.InnerText != "Справочник.Контрагенты")
|
||||
{
|
||||
//$"Это не контрагент, тип {Countparty.InnerText}"
|
||||
packageInfo.ErrorsList.Add($"Это не контрагент, тип {Countparty.InnerText}");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Countparty.Name == "m:Реквизиты")
|
||||
{
|
||||
foreach (XmlNode CountpartyOthers in Countparty.ChildNodes)
|
||||
{
|
||||
string tempKey = CountpartyOthers.ChildNodes[0].InnerText;
|
||||
string tempValue = CountpartyOthers.ChildNodes[1].Name == "m:ЗначениеСсылка" ? CountpartyOthers.ChildNodes[1].ChildNodes[1].InnerText : CountpartyOthers.ChildNodes[1].InnerText;
|
||||
|
||||
switch (tempKey)
|
||||
{
|
||||
case "Наименование":
|
||||
tempCompany.Name = tempValue;
|
||||
break;
|
||||
case "ГоловнойКонтрагент":
|
||||
tempCompany.GeneralCompany = tempValue;
|
||||
break;
|
||||
case "НаименованиеПолное":
|
||||
tempCompany.LegalName = tempValue;
|
||||
break;
|
||||
case "Код":
|
||||
tempCompany.Code = tempValue;
|
||||
break;
|
||||
case "БИН":
|
||||
tempCompany.Bin = tempValue;
|
||||
break;
|
||||
case "ЮрАдрес":
|
||||
tempCompany.LegalAddress = tempValue;
|
||||
break;
|
||||
case "ФактАдрес":
|
||||
tempCompany.PostalAddress = tempValue;
|
||||
break;
|
||||
case "Резидент":
|
||||
tempCompany.Resident = bool.Parse(tempValue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(tempCompany.Bin))
|
||||
{
|
||||
tempCompany.UpdCounterparty = _wrapper.GetCompanyByBIN(tempCompany.Bin).Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempCompany.UpdCounterparty = _wrapper.GetCompanyByGuid(tempCompany.Guid).Result;
|
||||
}
|
||||
|
||||
if (Countparty.Name == "m:Ид")
|
||||
{
|
||||
tempCompany.UpdCounterparty = _wrapper.GetCompanyByGuid(Countparty.InnerText).Result;
|
||||
tempCompany.Guid = Countparty.InnerText;
|
||||
}
|
||||
if (Countparty.Name == "m:ПометкаУдаления")
|
||||
tempCompany.Deleted = Countparty.InnerText;
|
||||
}
|
||||
//if (armad.ExchangeKZ.BusinessUnits.GetAll().FirstOrDefault(x => x.BINArmadoc == tempCompany.Bin) != null)
|
||||
if (_wrapper.GetBusinessUnitByBin(tempCompany.Bin).Result)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
packageInfo.AllLoadedComp.Add(tempCompany);
|
||||
|
||||
}
|
||||
}
|
||||
return packageInfo;
|
||||
}
|
||||
if (root.HasChildNodes)
|
||||
packageInfo = RecurseXmlDocument(root.FirstChild, packageInfo).Result;
|
||||
if (root.NextSibling != null)
|
||||
packageInfo = RecurseXmlDocument(root.NextSibling, packageInfo).Result;
|
||||
|
||||
}
|
||||
return packageInfo;
|
||||
}
|
||||
}
|
||||
}
|
34
HRM_MQ_Consumer_Service/Program.cs
Normal file
34
HRM_MQ_Consumer_Service/Program.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Главная точка входа для приложения.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//Для отладки сервиса
|
||||
if (Environment.UserInteractive)
|
||||
{
|
||||
HRMConsumerService service = new HRMConsumerService();
|
||||
service.TestStatupAndStop(args);
|
||||
}
|
||||
else
|
||||
{
|
||||
ServiceBase[] ServicesToRun;
|
||||
ServicesToRun = new ServiceBase[]
|
||||
{
|
||||
new HRMConsumerService()
|
||||
};
|
||||
ServiceBase.Run(ServicesToRun);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
HRM_MQ_Consumer_Service/ProjectInstaller.Designer.cs
generated
Normal file
60
HRM_MQ_Consumer_Service/ProjectInstaller.Designer.cs
generated
Normal file
@ -0,0 +1,60 @@
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
partial class ProjectInstaller
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
|
||||
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
|
||||
//
|
||||
// serviceProcessInstaller1
|
||||
//
|
||||
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalService;
|
||||
this.serviceProcessInstaller1.Password = null;
|
||||
this.serviceProcessInstaller1.Username = null;
|
||||
//
|
||||
// serviceInstaller1
|
||||
//
|
||||
this.serviceInstaller1.Description = "Message queue consumer";
|
||||
this.serviceInstaller1.DisplayName = "1C HRM RabbitMQ Consumer";
|
||||
this.serviceInstaller1.ServiceName = "1C HRM RabbitMQ Consumer";
|
||||
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
|
||||
//
|
||||
// ProjectInstaller
|
||||
//
|
||||
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
|
||||
this.serviceProcessInstaller1,
|
||||
this.serviceInstaller1});
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
|
||||
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
|
||||
}
|
||||
}
|
19
HRM_MQ_Consumer_Service/ProjectInstaller.cs
Normal file
19
HRM_MQ_Consumer_Service/ProjectInstaller.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration.Install;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
public partial class ProjectInstaller : System.Configuration.Install.Installer
|
||||
{
|
||||
public ProjectInstaller()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
129
HRM_MQ_Consumer_Service/ProjectInstaller.resx
Normal file
129
HRM_MQ_Consumer_Service/ProjectInstaller.resx
Normal file
@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="serviceProcessInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 54</value>
|
||||
</metadata>
|
||||
<metadata name="serviceInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>221, 53</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</root>
|
36
HRM_MQ_Consumer_Service/Properties/AssemblyInfo.cs
Normal file
36
HRM_MQ_Consumer_Service/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Общие сведения об этой сборке предоставляются следующим набором
|
||||
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
|
||||
// общие сведения об этой сборке.
|
||||
[assembly: AssemblyTitle("HRM_MQ_Consumer_Service")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("HRM_MQ_Consumer_Service")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
|
||||
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
|
||||
// компонент COM, задайте для атрибута ComVisible этого типа значение TRUE.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Указанный ниже идентификатор GUID предназначен для идентификации библиотеки типов, если этот проект будет видимым для COM-объектов
|
||||
[assembly: Guid("4e5d446e-7af9-490d-b503-59bcbfcca63f")]
|
||||
|
||||
// Сведения о версии сборки состоят из указанных ниже четырех значений:
|
||||
//
|
||||
// Основной номер версии
|
||||
// Дополнительный номер версии
|
||||
// Номер сборки
|
||||
// Номер редакции
|
||||
//
|
||||
// Можно задать все значения или принять номера сборки и редакции по умолчанию
|
||||
// используя "*", как показано ниже:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
42
HRM_MQ_Consumer_Service/Structure/CounterParty.cs
Normal file
42
HRM_MQ_Consumer_Service/Structure/CounterParty.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
public class CounterParty
|
||||
{
|
||||
public long Id { get; set; }
|
||||
//Наименование
|
||||
[JsonProperty("Наименование")]
|
||||
public string Name { get; set; }
|
||||
//Юридическое наименование
|
||||
[JsonProperty("ПолноеНаименование")]
|
||||
public string LegalName { get; set; }
|
||||
//Идентификатор 1С
|
||||
[JsonProperty("УникальныйИдентификатор")]
|
||||
public string Guid { get; set; }
|
||||
//Головная организация
|
||||
public string GeneralCompany { get; set; }
|
||||
//Код
|
||||
public string Code { get; set; }
|
||||
//БИН
|
||||
[JsonProperty("БИН")]
|
||||
public string Bin { get; set; }
|
||||
//ИНН
|
||||
[JsonProperty("ИНН")]
|
||||
public string Tin { get; set; }
|
||||
//Юридический адрес
|
||||
public string LegalAddress { get; set; }
|
||||
//Почтовый адрес
|
||||
public string PostalAddress { get; set; }
|
||||
//Резидент
|
||||
[JsonProperty("НеРезидент")]
|
||||
public bool Resident { get; set; }
|
||||
//Признак удаления
|
||||
public string Deleted { get; set; }
|
||||
|
||||
//Найденный объект
|
||||
public CounterParty UpdCounterparty { get; set; }
|
||||
|
||||
}
|
||||
}
|
25
HRM_MQ_Consumer_Service/Structure/CounterParty1C.cs
Normal file
25
HRM_MQ_Consumer_Service/Structure/CounterParty1C.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service.Structure
|
||||
{
|
||||
public class CounterParty1C
|
||||
{
|
||||
[JsonProperty("Наименование")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("БИН")]
|
||||
public string BIN { get; set; }
|
||||
[JsonProperty("УникальныйИдентификатор")]
|
||||
public string Guid { get; set; }
|
||||
[JsonProperty("НеРезидент")]
|
||||
public bool NonResident { get; set; }
|
||||
[JsonProperty("ПолноеНаименование")]
|
||||
public string LegalName { get; set; }
|
||||
[JsonProperty("ИНН")]
|
||||
public string TIN { get; set; }
|
||||
}
|
||||
}
|
32
HRM_MQ_Consumer_Service/Structure/PackageInfo.cs
Normal file
32
HRM_MQ_Consumer_Service/Structure/PackageInfo.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HRM_MQ_Consumer_Service
|
||||
{
|
||||
partial class PackageInfo
|
||||
{
|
||||
//Номер пакета
|
||||
public string Id { get; set; }
|
||||
//Строка авторизации
|
||||
public string Auth { get; set; }
|
||||
//Тело запроса
|
||||
public string RequestUrl { get; set; }
|
||||
//Тело ответа
|
||||
public string RequestXml { get; set; }
|
||||
//Тело запроса
|
||||
public string ResponseXml { get; set; }
|
||||
//Список ошибок
|
||||
public List<string> ErrorsList { get; set; }
|
||||
//Дата Ответа
|
||||
public DateTime DateReceived { get; set; }
|
||||
//Запись в логе
|
||||
//public ILogsExchange log { get; set; }
|
||||
//структура запроса
|
||||
public bool OperationCheck { get; set; }
|
||||
//вызов delete запроса
|
||||
public bool Delete { get; set; }
|
||||
|
||||
//Перечисление данных для создания/обновления контрагентов
|
||||
public List<CounterParty> AllLoadedComp { get; set; } = new List<CounterParty>();
|
||||
}
|
||||
}
|
25
HRM_MQ_Consumer_Service/packages.config
Normal file
25
HRM_MQ_Consumer_Service/packages.config
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.Configuration.Abstractions" version="9.0.6" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.ObjectPool" version="8.0.4" targetFramework="net48" />
|
||||
<package id="Microsoft.Extensions.Primitives" version="9.0.6" targetFramework="net48" />
|
||||
<package id="Microsoft.OData.Core" version="7.21.0" targetFramework="net48" />
|
||||
<package id="Microsoft.OData.Edm" version="7.21.0" targetFramework="net48" />
|
||||
<package id="Microsoft.Spatial" version="7.21.0" targetFramework="net48" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||
<package id="RabbitMQ.Client" version="7.1.2" targetFramework="net48" />
|
||||
<package id="Simple.OData.V4.Client" version="6.0.1" targetFramework="net48" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="8.0.1" targetFramework="net48" />
|
||||
<package id="System.IO.Pipelines" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
|
||||
<package id="System.Text.Encodings.Web" version="4.7.2" targetFramework="net48" />
|
||||
<package id="System.Text.Json" version="4.6.0" targetFramework="net48" />
|
||||
<package id="System.Threading.Channels" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Threading.RateLimiting" version="8.0.0" targetFramework="net48" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user