82 lines
3.0 KiB
C#
82 lines
3.0 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 async Task<Template> ParseStringAsync(string str)
|
||
{
|
||
//TODO: а если формат нет тот? Все будет ок?
|
||
|
||
//TODO:
|
||
var splittedContent = str.Split(";");
|
||
var ek = splittedContent[0].Trim().Substring(1, splittedContent[0].Length - 2);
|
||
var isActive = splittedContent[1].Trim().Substring(1, splittedContent[1].Length - 2);
|
||
var workGroup = splittedContent[2].Trim().Substring(1, splittedContent[2].Length - 2);
|
||
var shortDescription = splittedContent[3].Trim().Substring(1, splittedContent[3].Length - 2);
|
||
var category = splittedContent[4].Trim().Substring(1, splittedContent[4].Length - 2);
|
||
var ekDateCreatedStr = splittedContent[5].Trim().Substring(1, splittedContent[5].Length - 2);
|
||
var process = splittedContent[6].Trim().Substring(1, splittedContent[6].Length - 2);
|
||
var subProcess = splittedContent[7].Trim().Substring(1, splittedContent[7].Length - 2);
|
||
|
||
//logger.LogInformation($"Получено сообщение: {ek}");
|
||
var template = new Template
|
||
{
|
||
Id = Guid.NewGuid(),
|
||
DateCreated = DateTime.UtcNow,
|
||
EK = ek,
|
||
isActive = bool.Parse(isActive),
|
||
WorkGroup = workGroup,
|
||
ShortDescription = shortDescription,
|
||
Category = category,
|
||
//todo: EKDateCreated
|
||
//EKDateCreated = ConvertDateFromStr(ekDateCreatedStr+ " +03:00"),
|
||
EKDateCreated = null,
|
||
Process = process,
|
||
SubProcess = subProcess,
|
||
Status = "Checking"
|
||
};
|
||
|
||
//bool isSuccess = true;
|
||
|
||
|
||
return template;
|
||
}
|
||
|
||
private DateTimeOffset? ConvertDateFromStr(string dateString)
|
||
{
|
||
var format = "dd/MM/yy HH:mm:ss zzz";
|
||
var provider = CultureInfo.CurrentCulture;
|
||
try
|
||
{
|
||
var result = DateTimeOffset.ParseExact(dateString, format, provider);
|
||
logger.LogInformation($"{dateString} было преобразовано в {result.ToString()}.");
|
||
return result;
|
||
}
|
||
catch (FormatException)
|
||
{
|
||
logger.LogWarning($"{dateString} имеет некоррктный формат для преобразование в DateTimeOffset");
|
||
}
|
||
return null;
|
||
}
|
||
}
|
||
}
|