Files
parr_api/PARR.EsppTemplateSync/Services/ParserService.cs

104 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.Extensions.Logging;
using PARR.EsppTemplateSync.Domain;
using PARR.EsppTemplateSync.Settings;
using System.Globalization;
namespace PARR.EsppTemplateSync.Services
{
internal class ParserService : IParserService
{
private readonly ILogger<ParserService> logger;
private readonly GlobalSettings globalSettings;
public ParserService(
ILogger<ParserService> logger,
GlobalSettings globalSettings
)
{
this.logger = logger;
this.globalSettings = globalSettings;
}
public async Task<bool> ParseFileAsync(string path)
{
//TODO:
bool isSuccess = true;
return isSuccess;
}
public EsppTemplate? ParseString(string str)
{
//TODO: а если формат нет тот? Все будет ок?
var splittedContent = str.Split(globalSettings.ParsingSeparator);
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();
var template = new EsppTemplate
{
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
};
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;
}
}
}