Перевод на RabbitMQ
This commit is contained in:
parent
8333c02b42
commit
128953c4f2
@ -3,7 +3,7 @@ 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}") = "JSONParser", "JSONParser\JSONParser.csproj", "{DF1EDBD8-CD2B-4996-B4BE-CB03789C9093}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JSONParser", "JSONParser\JSONParser.csproj", "{DF1EDBD8-CD2B-4996-B4BE-CB03789C9093}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -8,12 +8,21 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.OData.Core" Version="7.21.0" />
|
||||
<PackageReference Include="Microsoft.OData.Edm" Version="7.21.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
|
||||
<PackageReference Include="Simple.OData.V4.Client" Version="6.0.1" />
|
||||
<PackageReference Include="System.ServiceProcess.ServiceController" Version="9.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="config.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,50 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JSONParser.Logger
|
||||
{
|
||||
// Customized ILogger, writes logs to text files
|
||||
public class CustomFileLogger : ILogger
|
||||
{
|
||||
private readonly string _categoryName;
|
||||
private readonly StreamWriter _logFileWriter;
|
||||
|
||||
public CustomFileLogger(string categoryName, StreamWriter logFileWriter)
|
||||
{
|
||||
_categoryName = categoryName;
|
||||
_logFileWriter = logFileWriter;
|
||||
}
|
||||
|
||||
public IDisposable BeginScope<TState>(TState state)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel)
|
||||
{
|
||||
// Ensure that only information level and higher logs are recorded
|
||||
return logLevel >= LogLevel.Information;
|
||||
}
|
||||
|
||||
public void Log<TState>(
|
||||
LogLevel logLevel,
|
||||
EventId eventId,
|
||||
TState state,
|
||||
Exception exception,
|
||||
Func<TState, Exception, string> formatter)
|
||||
{
|
||||
// Ensure that only information level and higher logs are recorded
|
||||
if (!IsEnabled(logLevel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the formatted log message
|
||||
var message = formatter(state, exception);
|
||||
|
||||
//Write log messages to text file
|
||||
//_logFileWriter.WriteLine($"[{logLevel}] [{_categoryName}] {message}");
|
||||
_logFileWriter.WriteLine($"[{logLevel}] {message}");
|
||||
_logFileWriter.Flush();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSONParser.Logger
|
||||
{
|
||||
// Customized ILoggerProvider, writes logs to text files
|
||||
public class CustomFileLoggerProvider : ILoggerProvider
|
||||
{
|
||||
private readonly StreamWriter _logFileWriter;
|
||||
|
||||
public CustomFileLoggerProvider(StreamWriter logFileWriter)
|
||||
{
|
||||
_logFileWriter = logFileWriter ?? throw new ArgumentNullException(nameof(logFileWriter));
|
||||
}
|
||||
|
||||
public ILogger CreateLogger(string categoryName)
|
||||
{
|
||||
return new CustomFileLogger(categoryName, _logFileWriter);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_logFileWriter.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
104
JSONParser/Logger/Logger.cs
Normal file
104
JSONParser/Logger/Logger.cs
Normal file
@ -0,0 +1,104 @@
|
||||
namespace JSONParser.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;
|
||||
_logDirPath = logDirPath;
|
||||
|
||||
if (!Directory.Exists(logDirPath))
|
||||
{
|
||||
Directory.CreateDirectory(logDirPath);
|
||||
}
|
||||
// Ensure the log file exists or create it
|
||||
//if (!File.Exists(_logFilePath))
|
||||
//{
|
||||
// using (File.Create(_logFilePath)) { }
|
||||
//}
|
||||
}
|
||||
|
||||
public void Log(LogLevel level, string message)
|
||||
{
|
||||
var timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
var logMessage = $"[{timestamp}] [{level}] [{_name}] {message}";
|
||||
|
||||
// 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 = $"{_logDirPath}\\{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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,117 +2,77 @@
|
||||
using JSONParser;
|
||||
using JSONParser.Logger;
|
||||
using JSONParser.QDocWrapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using RabbitMQ.Client.Events;
|
||||
using RabbitMQ.Client;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public async static Task Main(string[] args)
|
||||
{
|
||||
await LaunchConsumer();
|
||||
}
|
||||
|
||||
private static async Task LaunchConsumer()
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("config.json", optional: false);
|
||||
IConfiguration config = builder.Build();
|
||||
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
|
||||
var odata = new ODataAccess();
|
||||
var odata = new ODataAccess(config);
|
||||
var odataClient = odata.Client;
|
||||
|
||||
//var cnt = await odataClient
|
||||
// .For("IEmployees")
|
||||
// .Expand("Department/BusinessUnit")
|
||||
// .Filter("Department/BusinessUnit/Name eq 'Бакырчикское горнодобывающее предприятие ТОО' and Status eq 'Active'")
|
||||
// .FindEntriesAsync();
|
||||
//using ILoggerFactory factory = LoggerFactory.Create(builder => builder.AddConsole());
|
||||
//ILogger logger = factory.CreateLogger("HRM_MQ");
|
||||
|
||||
//var responsePath = @"C:\Users\anboevdd\Desktop\other\test_response.json";
|
||||
//var resp = File.ReadAllText(responsePath);
|
||||
//var arr = JArray.Parse(resp);
|
||||
var logger = new Logger("HRM_MQ", @"C:\log");
|
||||
|
||||
var logFolderPath = $@"C:\ОШС_logs\{DateTime.Now:yyyy_MM_dd}";
|
||||
|
||||
Directory.CreateDirectory(logFolderPath);
|
||||
|
||||
using (StreamWriter logFileWriter = new($@"{logFolderPath}\{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}_log.log", append: true))
|
||||
{
|
||||
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddSimpleConsole(options =>
|
||||
{
|
||||
options.IncludeScopes = true;
|
||||
options.SingleLine = true;
|
||||
options.TimestampFormat = "HH:mm:ss";
|
||||
});
|
||||
builder.AddProvider(new CustomFileLoggerProvider(logFileWriter));
|
||||
});
|
||||
ILogger logger = loggerFactory.CreateLogger("ОШС");
|
||||
var wrapper = new QDocWrapper(odataClient, logger);
|
||||
|
||||
Console.WriteLine("Получение данных из сервиса 1С");
|
||||
var jarray = await GetArrayFromService();
|
||||
//var jarray = arr;
|
||||
File.WriteAllText($@"{logFolderPath}\{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}_response.json", jarray.ToString());
|
||||
Console.WriteLine("Данные получены");
|
||||
Console.WriteLine("Парсинг...");
|
||||
var structure = new JSONStructure(jarray);
|
||||
Console.WriteLine("Данные структурированы. Создание записей в QDoc.");
|
||||
var rabbitFactory = new ConnectionFactory
|
||||
{
|
||||
HostName = config["RabbitSettings:HostName"],
|
||||
UserName = config["RabbitSettings:UserName"],
|
||||
Password = config["RabbitSettings:Password"],
|
||||
VirtualHost = config["RabbitSettings:VirtualHost"]
|
||||
};
|
||||
|
||||
foreach (var businessUnit in structure.BusinessUnits)
|
||||
{
|
||||
var id = await wrapper.CreateBusinessUnit(businessUnit);
|
||||
}
|
||||
var connection = await rabbitFactory.CreateConnectionAsync();
|
||||
var channel = await connection.CreateChannelAsync();
|
||||
|
||||
foreach (var department in structure.Departments)
|
||||
await channel.QueueDeclareAsync(
|
||||
queue: config["RabbitSettings:ChannelName"],
|
||||
durable: false,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||
consumer.ReceivedAsync += async (model, ea) =>
|
||||
{
|
||||
var id = await wrapper.CreateDepartment(department);
|
||||
}
|
||||
var body = ea.Body.ToArray();
|
||||
var message = Encoding.UTF8.GetString(body);
|
||||
var jarray = JArray.Parse(message);
|
||||
await CreateFromJArray(odataClient, logger, wrapper, jarray);
|
||||
//Console.WriteLine($" [x] Received {message}");
|
||||
await Task.Yield();
|
||||
};
|
||||
await channel.BasicConsumeAsync(
|
||||
queue: config["RabbitSettings:ChannelName"],
|
||||
autoAck: true,
|
||||
consumer: consumer);
|
||||
|
||||
foreach (var jobTitle in structure.JobTitles)
|
||||
while (true)
|
||||
{
|
||||
var id = await wrapper.CreateJobTitle(jobTitle);
|
||||
}
|
||||
|
||||
|
||||
foreach (var employee in structure.Employees)
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = await wrapper.CreateEmployee(employee);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
logger.LogError($"{employee.Type} - {employee.Sid} - Failed to create");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var businessUnit in structure.BusinessUnits)
|
||||
{
|
||||
var ceoId = await businessUnit.CreateNCEO(odataClient);
|
||||
if (ceoId > 0)
|
||||
{
|
||||
logger.LogInformation($"{businessUnit.Type} - {businessUnit.Sid} - CEO_Created");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning($"{businessUnit.Type} - {businessUnit.Sid} - CEO_Skip");
|
||||
if (businessUnit.NCEO != null && businessUnit.NCEO.Sid != null)
|
||||
{
|
||||
logger.LogWarning($"Сотрудники - {businessUnit.NCEO.Sid} - Skipped_CEO_Sid");
|
||||
}
|
||||
}
|
||||
var accountId = await businessUnit.CreateAccount(odataClient);
|
||||
if (accountId > 0)
|
||||
{
|
||||
logger.LogInformation($"{businessUnit.Type} - {businessUnit.Sid} - Account_Created");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning($"{businessUnit.Type} - {businessUnit.Sid} - Account_Skip");
|
||||
if (businessUnit.Account != null && businessUnit.Account.Sid != null)
|
||||
{
|
||||
logger.LogWarning($"Сотрудники - {businessUnit.Account.Sid} - Skipped_Account_Sid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var serialized = JsonConvert.SerializeObject(notValid);
|
||||
//Console.ReadLine();
|
||||
|
||||
static async Task<JArray> GetArrayFromService()
|
||||
{
|
||||
JArray array = [];
|
||||
@ -130,3 +90,66 @@ static async Task<JArray> GetArrayFromService()
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
static async Task CreateFromJArray(Simple.OData.Client.ODataClient? odataClient, Logger logger, QDocWrapper wrapper, JArray jarray)
|
||||
{
|
||||
var structure = new JSONStructure(jarray);
|
||||
|
||||
foreach (var businessUnit in structure.BusinessUnits)
|
||||
{
|
||||
var id = await wrapper.CreateBusinessUnit(businessUnit);
|
||||
}
|
||||
|
||||
foreach (var department in structure.Departments)
|
||||
{
|
||||
var id = await wrapper.CreateDepartment(department);
|
||||
}
|
||||
|
||||
foreach (var jobTitle in structure.JobTitles)
|
||||
{
|
||||
var id = await wrapper.CreateJobTitle(jobTitle);
|
||||
}
|
||||
|
||||
foreach (var employee in structure.Employees)
|
||||
{
|
||||
try
|
||||
{
|
||||
var id = await wrapper.CreateEmployee(employee);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
logger.Error($"{employee.Type} - {employee.Sid} - Failed to create");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var businessUnit in structure.BusinessUnits)
|
||||
{
|
||||
var ceoId = await businessUnit.CreateNCEO(odataClient);
|
||||
if (ceoId > 0)
|
||||
{
|
||||
logger.Info($"{businessUnit.Type} - {businessUnit.Sid} - CEO_Created");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn($"{businessUnit.Type} - {businessUnit.Sid} - CEO_Skip");
|
||||
if (businessUnit.NCEO != null && businessUnit.NCEO.Sid != null)
|
||||
{
|
||||
logger.Warn($"Сотрудники - {businessUnit.NCEO.Sid} - Skipped_CEO_Sid");
|
||||
}
|
||||
}
|
||||
var accountId = await businessUnit.CreateAccount(odataClient);
|
||||
if (accountId > 0)
|
||||
{
|
||||
logger.Info($"{businessUnit.Type} - {businessUnit.Sid} - Account_Created");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn($"{businessUnit.Type} - {businessUnit.Sid} - Account_Skip");
|
||||
if (businessUnit.Account != null && businessUnit.Account.Sid != null)
|
||||
{
|
||||
logger.Warn($"Сотрудники - {businessUnit.Account.Sid} - Skipped_Account_Sid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +1,29 @@
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace JSONParser.QDocWrapper
|
||||
{
|
||||
public class ODataAccess
|
||||
{
|
||||
// URL сервиса интеграции.
|
||||
#if DEBUG
|
||||
//private const string IntegrationServiceUrl = "http://astsrvdds.polymetal.ru/Integration/odata/";
|
||||
//private const string Login = "Administrator";
|
||||
//private const string Password = "11111";
|
||||
|
||||
private const string IntegrationServiceUrl = "https://astsrvqtest.solidcore-resources.com/Integration/odata/";
|
||||
private const string Login = "Administrator";
|
||||
private const string Password = "D3cTXol8Se";
|
||||
private string IntegrationServiceUrl;
|
||||
private string Login;
|
||||
private string Password;
|
||||
private IConfiguration _config;
|
||||
|
||||
//private const string IntegrationServiceUrl = "https://qdoc.solidcore-resources.com/Integration/odata/";
|
||||
//private const string Login = "Administrator";
|
||||
//private const string Password = "MQVuEw9avO";
|
||||
#endif
|
||||
|
||||
#if RELEASE
|
||||
private const string IntegrationServiceUrl = "https://qdoc.solidcore-resources.com/Integration/odata/";
|
||||
private const string Login = "Administrator";
|
||||
private const string Password = "MQVuEw9avO";
|
||||
#endif
|
||||
|
||||
public ODataAccess()
|
||||
public ODataAccess(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
IntegrationServiceUrl = config["QDocSettings:IntegrationServiceUrl"];
|
||||
Login = config["QDocSettings:Login"];
|
||||
Password = config["QDocSettings:Password"];
|
||||
// Настройки Simple OData Client: добавление ко всем запросам URL сервиса и
|
||||
// заголовка с данными аутентификации.
|
||||
var odataClientSettings = new ODataClientSettings(new Uri(IntegrationServiceUrl));
|
||||
|
@ -1,21 +1,13 @@
|
||||
using JSONParser.Structure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Simple.OData.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design.Serialization;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSONParser.QDocWrapper
|
||||
{
|
||||
public class QDocWrapper
|
||||
{
|
||||
ODataClient _client;
|
||||
ILogger _logger;
|
||||
public QDocWrapper(ODataClient client, ILogger logger)
|
||||
Logger.Logger _logger;
|
||||
public QDocWrapper(ODataClient client, Logger.Logger logger)
|
||||
{
|
||||
_client = client;
|
||||
_logger = logger;
|
||||
@ -37,7 +29,7 @@ namespace JSONParser.QDocWrapper
|
||||
|
||||
if ((employee.Person == null || employee.Department == null) || employee.Status == false && emp == null)
|
||||
{
|
||||
_logger.LogWarning($"{employee.Type} - {employee.Sid} - Skip");
|
||||
_logger.Warn($"{employee.Type} - {employee.Sid} - Skip");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -89,7 +81,15 @@ namespace JSONParser.QDocWrapper
|
||||
|
||||
if (employee.Login != null)
|
||||
{
|
||||
dynamic currLogin = emp["Login"];
|
||||
string loginName = currLogin["LoginName"];
|
||||
var id = await employee.Login.GetIdBySid(_client);
|
||||
if (id != 0 && !loginName.Equals(employee.Login.LoginName))
|
||||
{
|
||||
long currId = currLogin["Id"];
|
||||
employee.Login.CloseLogin(_client, currId);
|
||||
employee.Login.OpenLogin(_client, id);
|
||||
}
|
||||
if (id == 0)
|
||||
{
|
||||
id = await employee.Login.Create(_client);
|
||||
@ -107,7 +107,7 @@ namespace JSONParser.QDocWrapper
|
||||
|
||||
if (employee.Person.DirectumId == 0 || employee.Department.DirectumId == 0 || employee.JobTitle.DirectumId == 0)
|
||||
{
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Not Valid");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Not Valid");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -116,14 +116,14 @@ namespace JSONParser.QDocWrapper
|
||||
{
|
||||
result = (long)emp["Id"];
|
||||
employee.DirectumId = result;
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Unchanged");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Unchanged");
|
||||
}
|
||||
else if (emp != null && empByLogin == 0)
|
||||
{
|
||||
result = (long)emp["Id"];
|
||||
await employee.Update(_client, result);
|
||||
employee.DirectumId = result;
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Updated");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Updated");
|
||||
}
|
||||
else if (emp != null && empByLogin > 0)
|
||||
{
|
||||
@ -131,20 +131,20 @@ namespace JSONParser.QDocWrapper
|
||||
if (result != empByLogin)
|
||||
{
|
||||
await employee.CloseRecord(_client, empByLogin);
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Closed");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Closed");
|
||||
}
|
||||
await employee.Update(_client, result);
|
||||
employee.DirectumId = result;
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Updated");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Updated");
|
||||
}
|
||||
else if (emp == null && empByLogin > 0)
|
||||
{
|
||||
await employee.CloseRecord(_client, empByLogin);
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Closed");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Closed");
|
||||
if (employee.Person != null && employee.Department != null)
|
||||
{
|
||||
result = await employee.Create(_client);
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Created");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Created");
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -152,7 +152,7 @@ namespace JSONParser.QDocWrapper
|
||||
if (employee.Person != null && employee.Department != null)
|
||||
{
|
||||
result = await employee.Create(_client);
|
||||
_logger.LogInformation($"{employee.Type} - {employee.Sid} - Created");
|
||||
_logger.Info($"{employee.Type} - {employee.Sid} - Created");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -187,7 +187,7 @@ namespace JSONParser.QDocWrapper
|
||||
|
||||
if (department.BusinessUnit.DirectumId == 0)
|
||||
{
|
||||
_logger.LogInformation($"{department.Type} - {department.Sid} - Not Valid");
|
||||
_logger.Info($"{department.Type} - {department.Sid} - Not Valid");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -195,19 +195,19 @@ namespace JSONParser.QDocWrapper
|
||||
{
|
||||
result = (long)dept["Id"];
|
||||
department.DirectumId = result;
|
||||
_logger.LogInformation($"{department.Type} - {department.Sid} - Unchanged");
|
||||
_logger.Info($"{department.Type} - {department.Sid} - Unchanged");
|
||||
}
|
||||
else if (dept != null)
|
||||
{
|
||||
result = (long)dept["Id"];
|
||||
await department.Update(_client, result);
|
||||
department.DirectumId = result;
|
||||
_logger.LogInformation($"{department.Type} - {department.Sid} - Updated");
|
||||
_logger.Info($"{department.Type} - {department.Sid} - Updated");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await department.Create(_client);
|
||||
_logger.LogInformation($"{department.Type} - {department.Sid} - Created");
|
||||
_logger.Info($"{department.Type} - {department.Sid} - Created");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -233,7 +233,7 @@ namespace JSONParser.QDocWrapper
|
||||
jobTitle.DirectumId = result;
|
||||
dynamic dept = job["Department"];
|
||||
jobTitle.Department.DirectumId = (long)dept["Id"];
|
||||
_logger.LogInformation($"{jobTitle.Type} - {jobTitle.Sid} - Unchanged");
|
||||
_logger.Info($"{jobTitle.Type} - {jobTitle.Sid} - Unchanged");
|
||||
}
|
||||
else if (job != null)
|
||||
{
|
||||
@ -242,14 +242,14 @@ namespace JSONParser.QDocWrapper
|
||||
jobTitle.DirectumId = result;
|
||||
dynamic dept = job["Department"];
|
||||
jobTitle.Department.DirectumId = (long)dept["Id"];
|
||||
_logger.LogInformation($"{jobTitle.Type} - {jobTitle.Sid} - Updated");
|
||||
_logger.Info($"{jobTitle.Type} - {jobTitle.Sid} - Updated");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jobTitle.Department != null)
|
||||
{
|
||||
result = await jobTitle.Create(_client);
|
||||
_logger.LogInformation($"{jobTitle.Type} - {jobTitle.Sid} - Created");
|
||||
_logger.Info($"{jobTitle.Type} - {jobTitle.Sid} - Created");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -267,19 +267,19 @@ namespace JSONParser.QDocWrapper
|
||||
{
|
||||
result = (long)per["Id"];
|
||||
person.DirectumId = result;
|
||||
_logger.LogInformation($"{person.Type} - {person.Sid} - Unchanged");
|
||||
_logger.Info($"{person.Type} - {person.Sid} - Unchanged");
|
||||
}
|
||||
else if (per != null)
|
||||
{
|
||||
result = (long)per["Id"];
|
||||
await person.Update(_client, result);
|
||||
person.DirectumId = result;
|
||||
_logger.LogInformation($"{person.Type} - {person.Sid} - Updated");
|
||||
_logger.Info($"{person.Type} - {person.Sid} - Updated");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await person.Create(_client);
|
||||
_logger.LogInformation($"{person.Type} - {person.Sid} - Created");
|
||||
_logger.Info($"{person.Type} - {person.Sid} - Created");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -306,19 +306,19 @@ namespace JSONParser.QDocWrapper
|
||||
{
|
||||
result = (long)bu["Id"];
|
||||
businessUnit.DirectumId = result;
|
||||
_logger.LogInformation($"{businessUnit.Type} - {businessUnit.Sid} - Unchanged");
|
||||
_logger.Info($"{businessUnit.Type} - {businessUnit.Sid} - Unchanged");
|
||||
}
|
||||
else if (bu != null)
|
||||
{
|
||||
result = (long)bu["Id"];
|
||||
await businessUnit.Update(_client, result);
|
||||
businessUnit.DirectumId = result;
|
||||
_logger.LogInformation($"{businessUnit.Type} - {businessUnit.Sid} - Updated");
|
||||
_logger.Info($"{businessUnit.Type} - {businessUnit.Sid} - Updated");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await businessUnit.Create(_client);
|
||||
_logger.LogInformation($"{businessUnit.Type} - {businessUnit.Sid} - Created");
|
||||
_logger.Info($"{businessUnit.Type} - {businessUnit.Sid} - Created");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -335,19 +335,19 @@ namespace JSONParser.QDocWrapper
|
||||
{
|
||||
result = (long)log["Id"];
|
||||
login.DirectumId = result;
|
||||
_logger.LogInformation($"{login.Type} - {login.Sid} - Unchanged");
|
||||
_logger.Info($"{login.Type} - {login.Sid} - Unchanged");
|
||||
}
|
||||
else if (log != null)
|
||||
{
|
||||
result = (long)log["Id"];
|
||||
await login.Update(_client, result);
|
||||
login.DirectumId = result;
|
||||
_logger.LogInformation($"{login.Type} - {login.Sid} - Updated");
|
||||
_logger.Info($"{login.Type} - {login.Sid} - Updated");
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await login.Create(_client);
|
||||
_logger.LogInformation($"{login.Type} - {login.Sid} - Created");
|
||||
_logger.Info($"{login.Type} - {login.Sid} - Created");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
42
JSONParser/RabbitMQ/RabbitConnection.cs
Normal file
42
JSONParser/RabbitMQ/RabbitConnection.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using System.Text;
|
||||
|
||||
namespace JSONParser.RabbitMQ
|
||||
{
|
||||
public class RabbitConnection
|
||||
{
|
||||
public async void ReciveMessage()
|
||||
{
|
||||
var factory = new ConnectionFactory
|
||||
{
|
||||
HostName = "astsrvrabbit1",
|
||||
UserName = "erp",
|
||||
Password = @"Z!1;Q5#GE4v",
|
||||
VirtualHost = "erp"
|
||||
};
|
||||
|
||||
var connection = await factory.CreateConnectionAsync();
|
||||
var channel = await connection.CreateChannelAsync();
|
||||
|
||||
await channel.QueueDeclareAsync(
|
||||
queue: "hrm",
|
||||
durable: false,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||
consumer.ReceivedAsync += async (model, ea) =>
|
||||
{
|
||||
var body = ea.Body.ToArray();
|
||||
var message = Encoding.UTF8.GetString(body);
|
||||
Console.WriteLine($" [x] Received {message}");
|
||||
await Task.Yield();
|
||||
};
|
||||
await channel.BasicConsumeAsync(
|
||||
queue: "hrm",
|
||||
autoAck: true,
|
||||
consumer: consumer);
|
||||
}
|
||||
}
|
||||
}
|
@ -74,5 +74,31 @@ namespace JSONParser.Structure
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async void CloseLogin(ODataClient client, long id)
|
||||
{
|
||||
var closedLogin = new
|
||||
{
|
||||
Status = "Closed"
|
||||
};
|
||||
await client
|
||||
.For("ILogins")
|
||||
.Key(id)
|
||||
.Set(closedLogin)
|
||||
.UpdateEntryAsync();
|
||||
}
|
||||
|
||||
public async void OpenLogin(ODataClient client, long id)
|
||||
{
|
||||
var openedLogin = new
|
||||
{
|
||||
Status = "Active"
|
||||
};
|
||||
await client
|
||||
.For("ILogins")
|
||||
.Key(id)
|
||||
.Set(openedLogin)
|
||||
.UpdateEntryAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
JSONParser/config.json
Normal file
14
JSONParser/config.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"RabbitSettings": {
|
||||
"HostName": "astsrvrabbit1",
|
||||
"UserName": "erp",
|
||||
"Password": "Z!1;Q5#GE4v",
|
||||
"VirtualHost": "erp",
|
||||
"ChannelName": "hrm"
|
||||
},
|
||||
"QDocSettings": {
|
||||
"IntegrationServiceUrl": "https://astsrvqtest.solidcore-resources.com/Integration/odata/",
|
||||
"Login": "Administrator",
|
||||
"Password": "D3cTXol8Se"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user