diff --git a/JSONParser.sln b/JSONParser.sln
index e23e4c2..f5ac67f 100644
--- a/JSONParser.sln
+++ b/JSONParser.sln
@@ -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
diff --git a/JSONParser/JSONParser.csproj b/JSONParser/JSONParser.csproj
index e57b292..f953f08 100644
--- a/JSONParser/JSONParser.csproj
+++ b/JSONParser/JSONParser.csproj
@@ -8,12 +8,21 @@
+
+
+
+
+
+
+
+ Always
+
diff --git a/JSONParser/Logger/CustomFileLogger.cs b/JSONParser/Logger/CustomFileLogger.cs
deleted file mode 100644
index 3774260..0000000
--- a/JSONParser/Logger/CustomFileLogger.cs
+++ /dev/null
@@ -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 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(
- LogLevel logLevel,
- EventId eventId,
- TState state,
- Exception exception,
- Func 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();
- }
- }
-}
diff --git a/JSONParser/Logger/CustomFileLoggerProvider.cs b/JSONParser/Logger/CustomFileLoggerProvider.cs
deleted file mode 100644
index 0e2ad62..0000000
--- a/JSONParser/Logger/CustomFileLoggerProvider.cs
+++ /dev/null
@@ -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();
- }
- }
-}
diff --git a/JSONParser/Logger/Logger.cs b/JSONParser/Logger/Logger.cs
new file mode 100644
index 0000000..e3212c8
--- /dev/null
+++ b/JSONParser/Logger/Logger.cs
@@ -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);
+ }
+ }
+}
diff --git a/JSONParser/Program.cs b/JSONParser/Program.cs
index e2f598a..5723590 100644
--- a/JSONParser/Program.cs
+++ b/JSONParser/Program.cs
@@ -2,131 +2,154 @@
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;
-Console.OutputEncoding = Encoding.UTF8;
-
-var odata = new ODataAccess();
-var odataClient = odata.Client;
-
-//var cnt = await odataClient
-// .For("IEmployees")
-// .Expand("Department/BusinessUnit")
-// .Filter("Department/BusinessUnit/Name eq 'Бакырчикское горнодобывающее предприятие ТОО' and Status eq 'Active'")
-// .FindEntriesAsync();
-
-//var responsePath = @"C:\Users\anboevdd\Desktop\other\test_response.json";
-//var resp = File.ReadAllText(responsePath);
-//var arr = JArray.Parse(resp);
-
-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))
+public static class Program
{
- ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
+ public async static Task Main(string[] args)
{
- 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.");
-
- foreach (var businessUnit in structure.BusinessUnits)
- {
- var id = await wrapper.CreateBusinessUnit(businessUnit);
+ await LaunchConsumer();
}
- foreach (var department in structure.Departments)
+ private static async Task LaunchConsumer()
{
- var id = await wrapper.CreateDepartment(department);
- }
+ var builder = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("config.json", optional: false);
+ IConfiguration config = builder.Build();
- foreach (var jobTitle in structure.JobTitles)
- {
- var id = await wrapper.CreateJobTitle(jobTitle);
- }
+ Console.OutputEncoding = Encoding.UTF8;
+ var odata = new ODataAccess(config);
+ var odataClient = odata.Client;
- foreach (var employee in structure.Employees)
- {
- try
+ //using ILoggerFactory factory = LoggerFactory.Create(builder => builder.AddConsole());
+ //ILogger logger = factory.CreateLogger("HRM_MQ");
+
+ var logger = new Logger("HRM_MQ", @"C:\log");
+
+ var wrapper = new QDocWrapper(odataClient, logger);
+
+ var rabbitFactory = new ConnectionFactory
{
- var id = await wrapper.CreateEmployee(employee);
- }
- catch (Exception)
+ HostName = config["RabbitSettings:HostName"],
+ UserName = config["RabbitSettings:UserName"],
+ Password = config["RabbitSettings:Password"],
+ VirtualHost = config["RabbitSettings:VirtualHost"]
+ };
+
+ var connection = await rabbitFactory.CreateConnectionAsync();
+ var channel = await connection.CreateChannelAsync();
+
+ 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) =>
{
- logger.LogError($"{employee.Type} - {employee.Sid} - Failed to create");
+ 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);
+
+ while (true)
+ {
+
}
}
- foreach (var businessUnit in structure.BusinessUnits)
+ static async Task GetArrayFromService()
{
- var ceoId = await businessUnit.CreateNCEO(odataClient);
- if (ceoId > 0)
+ JArray array = [];
+ using (var client = new HttpClient())
{
- logger.LogInformation($"{businessUnit.Type} - {businessUnit.Sid} - CEO_Created");
+ var byteArray = Encoding.ASCII.GetBytes("QDoc:Xe3xihuz");
+ client.Timeout = new TimeSpan(0, 10, 0);
+ client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+
+ HttpResponseMessage response = await client.GetAsync("http://ast1c/HRMkz31/hs/qdoc/staff");
+ await client.DeleteAsync("http://ast1c/HRMkz31/hs/qdoc/staff");
+ string responseBody = await response.Content.ReadAsStringAsync();
+ array = JArray.Parse(responseBody);
}
- else
+ 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)
{
- logger.LogWarning($"{businessUnit.Type} - {businessUnit.Sid} - CEO_Skip");
- if (businessUnit.NCEO != null && businessUnit.NCEO.Sid != null)
+ 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
{
- logger.LogWarning($"Сотрудники - {businessUnit.NCEO.Sid} - Skipped_CEO_Sid");
+ var id = await wrapper.CreateEmployee(employee);
+ }
+ catch (Exception)
+ {
+ logger.Error($"{employee.Type} - {employee.Sid} - Failed to create");
}
}
- var accountId = await businessUnit.CreateAccount(odataClient);
- if (accountId > 0)
+
+ foreach (var businessUnit in structure.BusinessUnits)
{
- 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)
+ var ceoId = await businessUnit.CreateNCEO(odataClient);
+ if (ceoId > 0)
{
- logger.LogWarning($"Сотрудники - {businessUnit.Account.Sid} - Skipped_Account_Sid");
+ 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");
+ }
}
}
}
-}
-
-//var serialized = JsonConvert.SerializeObject(notValid);
-//Console.ReadLine();
-
-static async Task GetArrayFromService()
-{
- JArray array = [];
- using (var client = new HttpClient())
- {
- var byteArray = Encoding.ASCII.GetBytes("QDoc:Xe3xihuz");
- client.Timeout = new TimeSpan(0, 10, 0);
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
- client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
-
- HttpResponseMessage response = await client.GetAsync("http://ast1c/HRMkz31/hs/qdoc/staff");
- await client.DeleteAsync("http://ast1c/HRMkz31/hs/qdoc/staff");
- string responseBody = await response.Content.ReadAsStringAsync();
- array = JArray.Parse(responseBody);
- }
- return array;
}
\ No newline at end of file
diff --git a/JSONParser/QDocWrapper/ODataAccess.cs b/JSONParser/QDocWrapper/ODataAccess.cs
index e37a3fe..0eeefd5 100644
--- a/JSONParser/QDocWrapper/ODataAccess.cs
+++ b/JSONParser/QDocWrapper/ODataAccess.cs
@@ -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));
diff --git a/JSONParser/QDocWrapper/QDocWrapper.cs b/JSONParser/QDocWrapper/QDocWrapper.cs
index 3780995..98cd109 100644
--- a/JSONParser/QDocWrapper/QDocWrapper.cs
+++ b/JSONParser/QDocWrapper/QDocWrapper.cs
@@ -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;
}
diff --git a/JSONParser/RabbitMQ/RabbitConnection.cs b/JSONParser/RabbitMQ/RabbitConnection.cs
new file mode 100644
index 0000000..a33bc05
--- /dev/null
+++ b/JSONParser/RabbitMQ/RabbitConnection.cs
@@ -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);
+ }
+ }
+}
diff --git a/JSONParser/Structure/Login.cs b/JSONParser/Structure/Login.cs
index ddbe99e..f2e6642 100644
--- a/JSONParser/Structure/Login.cs
+++ b/JSONParser/Structure/Login.cs
@@ -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();
+ }
}
}
diff --git a/JSONParser/config.json b/JSONParser/config.json
new file mode 100644
index 0000000..2dc76d8
--- /dev/null
+++ b/JSONParser/config.json
@@ -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"
+ }
+}
\ No newline at end of file