105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using Microsoft.Extensions.Logging;
|
||
using PARR.DAL.Models;
|
||
using System.Globalization;
|
||
|
||
namespace PARR.EsppTemplateSync.Services
|
||
{
|
||
internal class ParserService : IParserService
|
||
{
|
||
private readonly ILogger<ParserService> logger;
|
||
|
||
public ParserService(ILogger<ParserService> logger)
|
||
{
|
||
this.logger = logger;
|
||
}
|
||
public async Task<bool> ParseFileAsync(string path)
|
||
{
|
||
//TODO:
|
||
|
||
bool isSuccess = true;
|
||
|
||
|
||
return isSuccess;
|
||
}
|
||
|
||
public Template? ParseString(string str)
|
||
{
|
||
//TODO: а если формат нет тот? Все будет ок?
|
||
|
||
//TODO:
|
||
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();
|
||
|
||
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();
|
||
|
||
//logger.LogInformation($"Получено сообщение: {ek}");
|
||
var template = new Template
|
||
{
|
||
Id = Guid.NewGuid(),
|
||
DateCreated = DateTime.UtcNow,
|
||
Name = name,
|
||
isActive = bool.Parse(isActive),
|
||
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,
|
||
Status = "Checking"
|
||
};
|
||
|
||
//bool isSuccess = true;
|
||
|
||
|
||
return template;
|
||
}
|
||
|
||
private DateTimeOffset? ConvertDateFromStr(string dateString)
|
||
{
|
||
var format = "dd/MM/yy HH:mm:ss";
|
||
var provider = CultureInfo.CurrentCulture;
|
||
try
|
||
{
|
||
var result = DateTimeOffset.ParseExact(dateString, format, provider).ToOffset(new TimeSpan(0));
|
||
logger.LogInformation($"{dateString} было преобразовано в {result.ToString()}.");
|
||
return result;
|
||
}
|
||
catch (FormatException)
|
||
{
|
||
logger.LogWarning($"{dateString} имеет некоррктный формат для преобразование в DateTimeOffset");
|
||
}
|
||
return null;
|
||
}
|
||
}
|
||
}
|