fix FormatException в ParserService(isActive), добавлен CallbackException в честный MqService
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
internal interface IManager
|
||||
{
|
||||
Task<bool> ManageFileAsync(string path);
|
||||
Task<bool> ManageStringAsync(string str);
|
||||
Task ManageStringAsync(string str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,20 +37,18 @@ namespace PARR.EsppTemplateSync.Services
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<bool> ManageStringAsync(string str)
|
||||
public async Task ManageStringAsync(string str)
|
||||
{
|
||||
bool isSuccess = true;
|
||||
////TODO:
|
||||
|
||||
// тут обязательно нужна проверка, если str не того формата, возникает exception в ParseStringAsync
|
||||
if (str == null || str.Trim().Length == 0)
|
||||
return false;
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return;
|
||||
|
||||
var esppTemplate = parserService.ParseString(str);
|
||||
|
||||
if (esppTemplate == null)
|
||||
{
|
||||
isSuccess = false;
|
||||
logger.LogError($"Не удалось распознать строку({str}) в Template");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -61,77 +59,12 @@ namespace PARR.EsppTemplateSync.Services
|
||||
//}
|
||||
|
||||
await SyncTemplateAsync(esppTemplate);
|
||||
// var template = await GetTemplateAsync(esppTemplate);
|
||||
//var isChanged = false;
|
||||
//if (template == null)
|
||||
//{
|
||||
// // создает запись-шаблон из ЕСПП в ПАРР. Возможно избыточно так как эталон в ПАРР
|
||||
// ////esppTemplate.StatusCode = "Deactivating";
|
||||
// ////---
|
||||
// //esppTemplate.StatusCode = (int)StatusTemplateEnum.Ok;
|
||||
// //esppTemplate.IsActive = false;
|
||||
// //if (!await templateService.CreateAsync(esppTemplate) || !await templateService.CommitAsync())
|
||||
// //{
|
||||
// // logger.LogError($"Не удалось создать запись Template {esppTemplate.Name}({esppTemplate.ShortDescription})");
|
||||
// //}
|
||||
// //else
|
||||
// // logger.LogInformation($"----- Создана запись Template {esppTemplate.Name}({esppTemplate.ShortDescription}) -----");
|
||||
// //---
|
||||
// logger.LogWarning($"----- Найден шаблон ЕСПП незарегистрированный в ПАРР {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
// return false;
|
||||
//}
|
||||
//else isChanged = await CheckChangesAsync(esppTemplate, template);
|
||||
////if (isChanged)
|
||||
|
||||
////var isChanged = await UpdateIfNeedAsync(template);
|
||||
|
||||
// //if (isChanged)
|
||||
// //{
|
||||
// // logger.LogInformation($"----- Запись в ЕСПП отличается от Template {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
|
||||
// // //template.Status = "Updating";
|
||||
// // template.StatusCode = (int)StatusTemplateEnum.Updating;
|
||||
|
||||
// // if (!await templateService.CommitAsync())
|
||||
// // logger.LogError($"Не удалось обновить запись Template {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription})");
|
||||
// // else
|
||||
// // logger.LogInformation($"----- Требуется обновление шаблона в ЕСПП роботом {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}) -----");
|
||||
// //}
|
||||
// //else
|
||||
// //{
|
||||
// // //if (template.Status != "Ok")
|
||||
// // if (template.StatusCode != (int)StatusTemplateEnum.Ok)
|
||||
// // {
|
||||
// // template.DateModified = DateTimeOffset.UtcNow;
|
||||
// // template.StatusCode = (int)StatusTemplateEnum.Ok;
|
||||
|
||||
// // if (!await templateService.CommitAsync())
|
||||
// // logger.LogInformation($"Шаблон в ЕСПП соответствует шаблону в ПАРР {esppTemplate.Name}({esppTemplate.ApplicationsInWork?.ShortDescription}). Установлен статус {StatusTemplateEnum.Ok}");
|
||||
// // }
|
||||
// //}
|
||||
}
|
||||
|
||||
//todo: only true?????
|
||||
return isSuccess;
|
||||
return;
|
||||
}
|
||||
|
||||
//private async Task<Template?> GetTemplateAsync(Template esppTemplate)
|
||||
//{
|
||||
// using (var scope = serviceProvider.CreateScope())
|
||||
// {
|
||||
// var services = scope.ServiceProvider;
|
||||
|
||||
// var templateService = services.GetService<ITemplateService>();
|
||||
|
||||
// if (templateService == null)
|
||||
// {
|
||||
// throw new Exception($"Не найден сервис: {nameof(ITemplateService)}");
|
||||
// // return;
|
||||
// }
|
||||
|
||||
// return await templateService.GetTemplateByNameAsync(esppTemplate.Name);
|
||||
// }
|
||||
//}
|
||||
|
||||
private async Task SyncTemplateAsync(EsppTemplate esppTemplate)
|
||||
{
|
||||
|
||||
@@ -30,8 +30,7 @@ namespace PARR.EsppTemplateSync.Services
|
||||
|
||||
public EsppTemplate? ParseString(string str)
|
||||
{
|
||||
//TODO: а если формат нет тот? Все будет ок?
|
||||
|
||||
// TODO: а если формат нет тот? Все будет ок?
|
||||
var splittedContent = str.Split(globalSettings.ParsingSeparator);
|
||||
if (splittedContent.Length != 17)
|
||||
{
|
||||
@@ -40,7 +39,19 @@ namespace PARR.EsppTemplateSync.Services
|
||||
|
||||
//var name = splittedContent[0].Trim().Substring(1, splittedContent[0].Length - 2);
|
||||
var name = splittedContent[0].Trim();
|
||||
var isActive = splittedContent[1].Trim();
|
||||
|
||||
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
|
||||
if (globalSettings.TemplatePrefix.Trim().Length > 0
|
||||
&& !name.StartsWith(globalSettings.TemplatePrefix, true, currentCulture)
|
||||
)
|
||||
{
|
||||
logger.LogWarning($"Имя шаблона не соответствует обязательному префиксу({globalSettings.TemplatePrefix}). Шаблон {name} игнорирован");
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
if (!bool.TryParse(splittedContent[1].Trim(), out var isActive))
|
||||
isActive = false;
|
||||
var workGroup = splittedContent[2].Trim();
|
||||
var shortDescription = splittedContent[3].Trim();
|
||||
var category = splittedContent[4].Trim();
|
||||
@@ -61,8 +72,7 @@ namespace PARR.EsppTemplateSync.Services
|
||||
var template = new EsppTemplate
|
||||
{
|
||||
Name = name,
|
||||
// todo: tryparse??? IsActive
|
||||
IsActive = bool.Parse(isActive),
|
||||
IsActive = isActive,
|
||||
WorkGroup = workGroup,
|
||||
ShortDescription = shortDescription,
|
||||
//Category = category,
|
||||
@@ -84,6 +94,8 @@ namespace PARR.EsppTemplateSync.Services
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private DateTimeOffset? ConvertDateFromStr(string dateString)
|
||||
{
|
||||
var format = "dd/MM/yy HH:mm:ss";
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace PARR.EsppTemplateSync.Settings
|
||||
public StorageSettings? StorageSettings { get; set; }
|
||||
public List<string>? IgnoreTemplateFields { get; set; }
|
||||
public string ParsingSeparator { get; set; } = "<|>";
|
||||
public string TemplatePrefix { get; set; }
|
||||
}
|
||||
|
||||
internal class MqSettings : IMqSettings
|
||||
|
||||
Reference in New Issue
Block a user