2023-09-01 11:47:39 +10:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-09-15 10:17:17 +10:00
|
|
|
|
using PARR.DAL.Contracts;
|
2023-09-01 12:40:41 +10:00
|
|
|
|
using PARR.DAL.Models;
|
2023-09-15 10:17:17 +10:00
|
|
|
|
using PARR.DAL.Services.Interfaces;
|
2023-09-01 12:40:41 +10:00
|
|
|
|
using System.Globalization;
|
2023-09-01 11:47:39 +10:00
|
|
|
|
|
|
|
|
|
|
namespace PARR.EsppTemplateSync.Services
|
2023-08-25 15:32:06 +10:00
|
|
|
|
{
|
|
|
|
|
|
internal class ParserService : IParserService
|
|
|
|
|
|
{
|
2023-09-01 11:47:39 +10:00
|
|
|
|
private readonly ILogger<ParserService> logger;
|
|
|
|
|
|
|
|
|
|
|
|
public ParserService(ILogger<ParserService> logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
|
}
|
2023-08-31 12:04:05 +10:00
|
|
|
|
public async Task<bool> ParseFileAsync(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
//TODO:
|
|
|
|
|
|
|
|
|
|
|
|
bool isSuccess = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return isSuccess;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-04 16:26:43 +10:00
|
|
|
|
public Template? ParseString(string str)
|
2023-08-25 15:32:06 +10:00
|
|
|
|
{
|
2023-09-04 12:17:50 +10:00
|
|
|
|
//TODO: а если формат нет тот? Все будет ок?
|
|
|
|
|
|
|
2023-08-25 15:32:06 +10:00
|
|
|
|
//TODO:
|
2023-09-13 14:44:21 +10:00
|
|
|
|
var splittedContent = str.Split("<|>");
|
|
|
|
|
|
if (splittedContent.Length != 17)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//var name = splittedContent[0].Trim().Substring(1, splittedContent[0].Length - 2);
|
|
|
|
|
|
var name = splittedContent[0].Trim();
|
|
|
|
|
|
var isActive = splittedContent[1].Trim();
|
|
|
|
|
|
var workGroup = splittedContent[2].Trim();
|
|
|
|
|
|
var shortDescription = splittedContent[3].Trim();
|
|
|
|
|
|
var category = splittedContent[4].Trim();
|
|
|
|
|
|
var responseArea = splittedContent[5].Trim();
|
|
|
|
|
|
var duration = splittedContent[6].Trim();
|
|
|
|
|
|
var ek = splittedContent[7].Trim();
|
|
|
|
|
|
var initiator = splittedContent[8].Trim();
|
2023-09-04 16:26:43 +10:00
|
|
|
|
|
2023-09-13 14:44:21 +10:00
|
|
|
|
var fullDescription = splittedContent[9].Trim();
|
|
|
|
|
|
var closingCode = splittedContent[10].Trim();
|
|
|
|
|
|
var solution = splittedContent[11].Trim();
|
|
|
|
|
|
var process = splittedContent[12].Trim();
|
|
|
|
|
|
var subProcess = splittedContent[13].Trim();
|
|
|
|
|
|
var tnk = splittedContent[14].Trim();
|
|
|
|
|
|
var work = splittedContent[15].Trim();
|
|
|
|
|
|
var worker = splittedContent[16].Trim();
|
2023-08-25 15:32:06 +10:00
|
|
|
|
|
2023-09-01 12:40:41 +10:00
|
|
|
|
//logger.LogInformation($"Получено сообщение: {ek}");
|
|
|
|
|
|
var template = new Template
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = Guid.NewGuid(),
|
|
|
|
|
|
DateCreated = DateTime.UtcNow,
|
2023-09-13 14:44:21 +10:00
|
|
|
|
Name = name,
|
2023-09-14 17:00:56 +10:00
|
|
|
|
IsActive = bool.Parse(isActive),
|
2023-09-19 12:17:05 +10:00
|
|
|
|
//WorkGroup = workGroup,
|
|
|
|
|
|
//ShortDescription = shortDescription,
|
|
|
|
|
|
//Category = category,
|
|
|
|
|
|
//ResponseArea = responseArea,
|
|
|
|
|
|
//Duration = duration,
|
|
|
|
|
|
//EK = ek,
|
|
|
|
|
|
//Initiator = initiator,
|
|
|
|
|
|
//FullDescription = fullDescription,
|
|
|
|
|
|
//ClosingCode = closingCode,
|
|
|
|
|
|
//Solution = solution,
|
|
|
|
|
|
//Process = process,
|
|
|
|
|
|
//SubProcess = subProcess,
|
|
|
|
|
|
//TNK = tnk,
|
|
|
|
|
|
//Work = work,
|
|
|
|
|
|
//Worker = worker,
|
2023-09-14 17:00:56 +10:00
|
|
|
|
//Status = "Checking"
|
2023-09-15 10:17:17 +10:00
|
|
|
|
StatusCode = (int)StatusTemplateEnum.Ok
|
2023-09-01 12:40:41 +10:00
|
|
|
|
};
|
2023-08-25 15:32:06 +10:00
|
|
|
|
|
2023-09-01 12:40:41 +10:00
|
|
|
|
//bool isSuccess = true;
|
2023-08-25 15:32:06 +10:00
|
|
|
|
|
2023-09-01 12:40:41 +10:00
|
|
|
|
|
|
|
|
|
|
return template;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private DateTimeOffset? ConvertDateFromStr(string dateString)
|
|
|
|
|
|
{
|
2023-09-04 16:26:43 +10:00
|
|
|
|
var format = "dd/MM/yy HH:mm:ss";
|
2023-09-01 12:40:41 +10:00
|
|
|
|
var provider = CultureInfo.CurrentCulture;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2023-09-04 16:26:43 +10:00
|
|
|
|
var result = DateTimeOffset.ParseExact(dateString, format, provider).ToOffset(new TimeSpan(0));
|
2023-09-01 16:19:32 +10:00
|
|
|
|
logger.LogInformation($"{dateString} было преобразовано в {result.ToString()}.");
|
2023-09-01 12:40:41 +10:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
|
{
|
2023-09-01 16:19:32 +10:00
|
|
|
|
logger.LogWarning($"{dateString} имеет некоррктный формат для преобразование в DateTimeOffset");
|
2023-09-01 12:40:41 +10:00
|
|
|
|
}
|
|
|
|
|
|
return null;
|
2023-08-25 15:32:06 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|