77 lines
2.8 KiB
C#
77 lines
2.8 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:
|
|
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,
|
|
EKDateCreated = ConvertDateFromStr(ekDateCreatedStr+ " +03:00"),
|
|
Process = process,
|
|
SubProcess = subProcess
|
|
};
|
|
|
|
//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);
|
|
Console.WriteLine("{0} было преобразовано в {1}.", dateString, result.ToString());
|
|
return result;
|
|
}
|
|
catch (FormatException)
|
|
{
|
|
Console.WriteLine("{0} имеет некоррктный формат для преобразование в DateTimeOffset", dateString);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|