table Template

This commit is contained in:
Mikhail Kuznetsov
2023-09-01 12:40:41 +10:00
parent d6f1752465
commit 21eb83a50f
11 changed files with 1173 additions and 8 deletions

View File

@@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Models;
using System.Globalization;
namespace PARR.EsppTemplateSync.Services
{
@@ -20,18 +22,55 @@ namespace PARR.EsppTemplateSync.Services
return isSuccess;
}
public async Task<bool> ParseStringAsync(string str)
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);
logger.LogInformation($"Получено сообщение: {ek}");
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);
bool isSuccess = true;
//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 isSuccess;
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;
}
}
}