Enhance event occurrence parsing with detailed issue reporting and location configuration
This commit introduces a new structure for handling parsing issues in the EventOccurrenceParser, allowing for detailed reporting of parsing problems such as unmatched lines, missing event definitions, and parsing failures for time, date, and location. A new ParsingIssue class has been added to encapsulate these details. Additionally, a LocationParsingConfiguration class has been implemented to support customizable location patterns, enhancing the flexibility of the parser. The EventOccurrenceParserService has been updated to utilize this configuration, and new tests have been added to ensure robust issue detection and reporting. Furthermore, the UI has been updated to display parsing issues, improving user feedback during the import process.
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Text;
|
||||
using Core.Entities;
|
||||
using Core.Models;
|
||||
using Core.Parsers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Core.Services;
|
||||
|
||||
@@ -11,6 +12,22 @@ namespace Core.Services;
|
||||
/// </summary>
|
||||
public class EventOccurrenceParserService : IEventOccurrenceParserService
|
||||
{
|
||||
private readonly LocationParsingConfiguration? _locationConfig;
|
||||
|
||||
public EventOccurrenceParserService(IConfiguration? configuration = null)
|
||||
{
|
||||
// Load location parsing configuration from IConfiguration if provided
|
||||
if (configuration != null)
|
||||
{
|
||||
_locationConfig = configuration.GetSection("LocationParsingSettings").Get<LocationParsingConfiguration>()
|
||||
?? LocationParsingConfiguration.Default;
|
||||
}
|
||||
else
|
||||
{
|
||||
_locationConfig = LocationParsingConfiguration.Default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public EventOccurrenceParseResult ParseFromText(string text, ICollection<EventDefinition> events)
|
||||
{
|
||||
@@ -31,9 +48,12 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
|
||||
File.WriteAllText(tempFile, text, Encoding.UTF8);
|
||||
var fileInfo = new FileInfo(tempFile);
|
||||
|
||||
// Use the existing EventOccurrenceParser
|
||||
var parser = new EventOccurrenceParser(fileInfo, events);
|
||||
var parsedOccurrences = parser.Parse();
|
||||
// Use the existing EventOccurrenceParser with location configuration
|
||||
var parser = new EventOccurrenceParser(fileInfo, events, _locationConfig);
|
||||
var parserResult = parser.Parse();
|
||||
|
||||
// Copy occurrences from parser result
|
||||
var parsedOccurrences = parserResult.Occurrences;
|
||||
|
||||
// Convert parsed occurrences to result format, handling special event types
|
||||
foreach (var kvp in parsedOccurrences)
|
||||
@@ -79,9 +99,8 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
|
||||
}
|
||||
}
|
||||
|
||||
// Track any occurrences without a matching EventDefinition
|
||||
// (This would be detected if parser.Parse() returns occurrences with null EventDefinition keys,
|
||||
// but the current parser implementation doesn't do this - all occurrences have a currentEventDefinition)
|
||||
// Copy parsing issues from parser result
|
||||
result.Issues.AddRange(parserResult.Issues);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user