From 270bc9786d5f243200dc92e84452bd85e73ddae3 Mon Sep 17 00:00:00 2001 From: Mads Magnus Due Date: Wed, 20 Nov 2024 14:43:17 +0100 Subject: [PATCH] feat: move old xml parsers into new pattern --- .../IncomingMessagesExtensions.cs | 13 +- .../AggregatedMeasureDataXmlMessageParser.cs | 160 +++++---------- ...ldAggregatedMeasureDataXmlMessageParser.cs | 39 ++++ ...DateForMeasurementPointXmlMessageParser.cs | 3 - .../OldWholesaleSettlementXmlMessageParser.cs | 33 ++++ .../WholesaleSettlementXmlMessageParser.cs | 183 +++++------------- .../MessageParsers/XmlMessageParserBase.cs | 2 + .../MessageParserTests.cs | 2 +- .../MessageParserTests.cs | 2 +- 9 files changed, 186 insertions(+), 251 deletions(-) create mode 100644 source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/OldAggregatedMeasureDataXmlMessageParser.cs create mode 100644 source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/OldWholesaleSettlementXmlMessageParser.cs diff --git a/source/IncomingMessages.Application/Extensions/DependencyInjection/IncomingMessagesExtensions.cs b/source/IncomingMessages.Application/Extensions/DependencyInjection/IncomingMessagesExtensions.cs index 16ffc66c2b..61b6586bcb 100644 --- a/source/IncomingMessages.Application/Extensions/DependencyInjection/IncomingMessagesExtensions.cs +++ b/source/IncomingMessages.Application/Extensions/DependencyInjection/IncomingMessagesExtensions.cs @@ -61,11 +61,11 @@ public static IServiceCollection AddIncomingMessagesModule(this IServiceCollecti .AddScoped() .AddScoped() .AddScoped() - .AddScoped() + .AddScoped() .AddScoped() .AddScoped() .AddScoped() - .AddScoped() + .AddScoped() .AddScoped() .AddScoped() .AddScoped() @@ -137,11 +137,14 @@ public static IServiceCollection AddIncomingMessagesModule(this IServiceCollecti .AddSingleton(); services - .AddTransient(); + .AddTransient(); services - .AddTransient(); + .AddTransient(); services - .AddTransient(); + .AddTransient(); + + services + .AddTransient(); return services; } diff --git a/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/AggregatedMeasureDataXmlMessageParser.cs b/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/AggregatedMeasureDataXmlMessageParser.cs index 2db9e64b29..8054a8a575 100644 --- a/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/AggregatedMeasureDataXmlMessageParser.cs +++ b/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/AggregatedMeasureDataXmlMessageParser.cs @@ -12,131 +12,77 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Xml; -using System.Xml.Schema; +using System.Xml.Linq; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; using Energinet.DataHub.EDI.IncomingMessages.Domain; +using Energinet.DataHub.EDI.IncomingMessages.Domain.Abstractions; using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.BaseParsers; -using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.BaseParsers.Xml; using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Schemas.Cim.Xml; namespace Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.AggregatedMeasureDataRequestMessageParsers; -public class AggregatedMeasureDataXmlMessageParser : XmlBaseParser +public class AggregatedMeasureDataXmlMessageParser(CimXmlSchemaProvider schemaProvider) : XmlMessageParserBase(schemaProvider) { - private const string SeriesRecordElementName = "Series"; - private const string HeaderElementName = "RequestAggregatedMeasureData_MarketDocument"; - - public AggregatedMeasureDataXmlMessageParser(CimXmlSchemaProvider schemaProvider) - : base(schemaProvider) - { - } + private const string SeriesElementName = "Series"; + private const string MridElementName = "mRID"; + private const string MarketEvaluationPointTypeElementName = "marketEvaluationPoint.type"; + private const string MarketEvaluationPointSettlementMethodElementName = "marketEvaluationPoint.settlementMethod"; + private const string StartElementName = "start_DateAndOrTime.dateTime"; + private const string EndElementName = "end_DateAndOrTime.dateTime"; + private const string GridAreaElementName = "meteringGridArea_Domain.mRID"; + private const string EnergySupplierNumberElementName = "energySupplier_MarketParticipant.mRID"; + private const string BalanceResponsibleNumberElementName = "balanceResponsibleParty_MarketParticipant.mRID"; + private const string SettlementVersionElementName = "settlement_Series.version"; public override IncomingDocumentType DocumentType => IncomingDocumentType.RequestAggregatedMeasureData; - protected override async Task ParseXmlDataAsync( - XmlReader reader) + protected override string RootPayloadElementName => "RequestAggregatedMeasureData_MarketDocument"; + + protected override IReadOnlyCollection ParseTransactions(XDocument document, XNamespace ns, string senderNumber) { - var root = await reader.ReadRootElementAsync().ConfigureAwait(false); - var messageHeader = await MessageHeaderExtractor - .ExtractAsync(reader, root, HeaderElementName, SeriesRecordElementName) - .ConfigureAwait(false); + var seriesElements = document.Descendants(ns + SeriesElementName); + var result = new List(); - var series = new List(); - await foreach (var serie in ParseSeriesAsync(reader, root)) + foreach (var seriesElement in seriesElements) { - series.Add(serie); + var id = seriesElement.Element(ns + MridElementName)?.Value ?? string.Empty; + var marketEvaluationPointType = seriesElement.Element(ns + MarketEvaluationPointTypeElementName)?.Value ?? string.Empty; + var marketEvaluationSettlementMethod = seriesElement.Element(ns + MarketEvaluationPointSettlementMethodElementName)?.Value ?? string.Empty; + var startDateAndOrTimeDateTime = seriesElement.Element(ns + StartElementName)?.Value ?? string.Empty; + var endDateAndOrTimeDateTime = seriesElement.Element(ns + EndElementName)?.Value ?? string.Empty; + var meteringGridAreaDomainId = seriesElement.Element(ns + GridAreaElementName)?.Value ?? string.Empty; + var energySupplierMarketParticipantId = seriesElement.Element(ns + EnergySupplierNumberElementName)?.Value ?? string.Empty; + var balanceResponsiblePartyMarketParticipantId = seriesElement.Element(ns + BalanceResponsibleNumberElementName)?.Value ?? string.Empty; + var settlementVersion = seriesElement.Element(ns + SettlementVersionElementName)?.Value ?? string.Empty; + + result.Add(new RequestAggregatedMeasureDataMessageSeries( + id, + marketEvaluationPointType, + marketEvaluationSettlementMethod, + startDateAndOrTimeDateTime, + endDateAndOrTimeDateTime, + meteringGridAreaDomainId, + energySupplierMarketParticipantId, + balanceResponsiblePartyMarketParticipantId, + settlementVersion)); } - return new IncomingMarketMessageParserResult( - RequestAggregatedMeasureDataMessageFactory.Create(messageHeader, series.AsReadOnly())); + return result.AsReadOnly(); } - private static async IAsyncEnumerable ParseSeriesAsync(XmlReader reader, RootElement rootElement) + protected override IncomingMarketMessageParserResult CreateResult(MessageHeader header, IReadOnlyCollection transactions) { - var id = string.Empty; - var startDateAndOrTimeDateTime = string.Empty; - string? marketEvaluationPointType = null; - string? marketEvaluationSettlementMethod = null; - string? endDateAndOrTimeDateTime = null; - string? meteringGridAreaDomainId = null; - string? energySupplierMarketParticipantId = null; - string? balanceResponsiblePartyMarketParticipantId = null; - string? settlementVersion = null; - var ns = rootElement.DefaultNamespace; - - await reader.AdvanceToAsync(SeriesRecordElementName, ns).ConfigureAwait(false); - - while (!reader.EOF) - { - if (reader.Is(SeriesRecordElementName, ns, XmlNodeType.EndElement)) - { - var series = new RequestAggregatedMeasureDataMessageSeries( - id, - marketEvaluationPointType, - marketEvaluationSettlementMethod, - startDateAndOrTimeDateTime, - endDateAndOrTimeDateTime, - meteringGridAreaDomainId, - energySupplierMarketParticipantId, - balanceResponsiblePartyMarketParticipantId, - settlementVersion); - - id = string.Empty; - startDateAndOrTimeDateTime = string.Empty; - marketEvaluationPointType = null; - marketEvaluationSettlementMethod = null; - endDateAndOrTimeDateTime = null; - meteringGridAreaDomainId = null; - energySupplierMarketParticipantId = null; - balanceResponsiblePartyMarketParticipantId = null; - - yield return series; - } - - if (reader.NodeType == XmlNodeType.Element && reader.SchemaInfo?.Validity == XmlSchemaValidity.Invalid) - await reader.ReadToEndAsync().ConfigureAwait(false); - - if (reader.Is("mRID", ns)) - { - id = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("marketEvaluationPoint.type", ns)) - { - marketEvaluationPointType = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("marketEvaluationPoint.settlementMethod", ns)) - { - marketEvaluationSettlementMethod = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("start_DateAndOrTime.dateTime", ns)) - { - startDateAndOrTimeDateTime = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("end_DateAndOrTime.dateTime", ns)) - { - endDateAndOrTimeDateTime = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("meteringGridArea_Domain.mRID", ns)) - { - meteringGridAreaDomainId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("energySupplier_MarketParticipant.mRID", ns)) - { - energySupplierMarketParticipantId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("balanceResponsibleParty_MarketParticipant.mRID", ns)) - { - balanceResponsiblePartyMarketParticipantId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("settlement_Series.version", ns)) - { - settlementVersion = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else - { - await reader.ReadAsync().ConfigureAwait(false); - } - } + return new IncomingMarketMessageParserResult( + new RequestAggregatedMeasureDataMessage( + header.SenderId, + header.SenderRole, + header.ReceiverId, + header.ReceiverRole, + header.BusinessReason, + header.MessageType, + header.MessageId, + header.CreatedAt, + header.BusinessType, + transactions)); } } diff --git a/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/OldAggregatedMeasureDataXmlMessageParser.cs b/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/OldAggregatedMeasureDataXmlMessageParser.cs new file mode 100644 index 0000000000..1f1560092c --- /dev/null +++ b/source/IncomingMessages.Infrastructure/MessageParsers/AggregatedMeasureDataRequestMessageParsers/OldAggregatedMeasureDataXmlMessageParser.cs @@ -0,0 +1,39 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Xml; +using System.Xml.Schema; +using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; +using Energinet.DataHub.EDI.IncomingMessages.Domain; +using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.BaseParsers; +using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.BaseParsers.Xml; +using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Schemas.Cim.Xml; + +namespace Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.AggregatedMeasureDataRequestMessageParsers; + +public class OldAggregatedMeasureDataXmlMessageParser(IEnumerable messageParsers) : IMarketMessageParser +{ + private readonly IEnumerable _messageParsers = messageParsers; + + public DocumentFormat HandledFormat => DocumentFormat.Xml; + + public IncomingDocumentType DocumentType => IncomingDocumentType.RequestAggregatedMeasureData; + + public async Task ParseAsync(IIncomingMarketMessageStream incomingMarketMessageStream, CancellationToken cancellationToken) + { + var messageParser = _messageParsers + .Single(x => x.DocumentFormat == HandledFormat && x.DocumentType == DocumentType); + return await messageParser.ParseAsync(incomingMarketMessageStream, cancellationToken).ConfigureAwait(false); + } +} diff --git a/source/IncomingMessages.Infrastructure/MessageParsers/MeteredDateForMeasurementPointParsers/MeteredDateForMeasurementPointXmlMessageParser.cs b/source/IncomingMessages.Infrastructure/MessageParsers/MeteredDateForMeasurementPointParsers/MeteredDateForMeasurementPointXmlMessageParser.cs index bbc35c6be2..af6e953419 100644 --- a/source/IncomingMessages.Infrastructure/MessageParsers/MeteredDateForMeasurementPointParsers/MeteredDateForMeasurementPointXmlMessageParser.cs +++ b/source/IncomingMessages.Infrastructure/MessageParsers/MeteredDateForMeasurementPointParsers/MeteredDateForMeasurementPointXmlMessageParser.cs @@ -42,8 +42,6 @@ public class MeteredDateForMeasurementPointXmlMessageParser(CimXmlSchemaProvider public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint; - public override DocumentFormat DocumentFormat => DocumentFormat.Xml; - protected override string RootPayloadElementName => "NotifyValidatedMeasureData_MarketDocument"; protected override IReadOnlyCollection ParseTransactions(XDocument document, XNamespace ns, string senderNumber) @@ -73,7 +71,6 @@ protected override IReadOnlyCollection ParseTransactions ?.Value; var energyObservations = seriesElement - //.Element(ns + Period)? .Descendants(ns + PointElementName) .Select( e => new EnergyObservation( diff --git a/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/OldWholesaleSettlementXmlMessageParser.cs b/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/OldWholesaleSettlementXmlMessageParser.cs new file mode 100644 index 0000000000..47734f6196 --- /dev/null +++ b/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/OldWholesaleSettlementXmlMessageParser.cs @@ -0,0 +1,33 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; + +namespace Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.WholesaleSettlementMessageParsers; + +public class OldWholesaleSettlementXmlMessageParser(IEnumerable messageParsers) : IMarketMessageParser +{ + private readonly IEnumerable _messageParsers = messageParsers; + + public DocumentFormat HandledFormat => DocumentFormat.Xml; + + public IncomingDocumentType DocumentType => IncomingDocumentType.RequestWholesaleSettlement; + + public async Task ParseAsync(IIncomingMarketMessageStream incomingMarketMessageStream, CancellationToken cancellationToken) + { + var messageParser = _messageParsers + .Single(x => x.DocumentFormat == HandledFormat && x.DocumentType == DocumentType); + return await messageParser.ParseAsync(incomingMarketMessageStream, cancellationToken).ConfigureAwait(false); + } +} diff --git a/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/WholesaleSettlementXmlMessageParser.cs b/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/WholesaleSettlementXmlMessageParser.cs index b710263cac..6fe03e83ab 100644 --- a/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/WholesaleSettlementXmlMessageParser.cs +++ b/source/IncomingMessages.Infrastructure/MessageParsers/WholesaleSettlementMessageParsers/WholesaleSettlementXmlMessageParser.cs @@ -12,42 +12,71 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System.Xml; -using System.Xml.Schema; +using System.Xml.Linq; using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; using Energinet.DataHub.EDI.IncomingMessages.Domain; +using Energinet.DataHub.EDI.IncomingMessages.Domain.Abstractions; using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.BaseParsers; -using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.BaseParsers.Xml; using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Schemas.Cim.Xml; namespace Energinet.DataHub.EDI.IncomingMessages.Infrastructure.MessageParsers.WholesaleSettlementMessageParsers; -public class WholesaleSettlementXmlMessageParser : XmlBaseParser +public class WholesaleSettlementXmlMessageParser(CimXmlSchemaProvider schemaProvider) : XmlMessageParserBase(schemaProvider) { private const string SeriesElementName = "Series"; - private const string HeaderElementName = "RequestWholesaleSettlement_MarketDocument"; - - public WholesaleSettlementXmlMessageParser(CimXmlSchemaProvider schemaProvider) - : base(schemaProvider) - { - } + private const string MridElementName = "mRID"; + private const string StartElementName = "start_DateAndOrTime.dateTime"; + private const string EndElementName = "end_DateAndOrTime.dateTime"; + private const string GridAreaElementName = "meteringGridArea_Domain.mRID"; + private const string EnergySupplierElementName = "energySupplier_MarketParticipant.mRID"; + private const string ChargeOwnerElementName = "chargeTypeOwner_MarketParticipant.mRID"; + private const string SettlementVersionElementName = "settlement_Series.version"; + private const string ResolutionElementName = "aggregationSeries_Period.resolution"; + private const string ChargeElementName = "ChargeType"; + private const string ChargeTypeElementName = "type"; public override IncomingDocumentType DocumentType => IncomingDocumentType.RequestWholesaleSettlement; - protected override async Task ParseXmlDataAsync( - XmlReader reader) + protected override string RootPayloadElementName => "RequestWholesaleSettlement_MarketDocument"; + + protected override IReadOnlyCollection ParseTransactions(XDocument document, XNamespace ns, string senderNumber) { - var root = await reader.ReadRootElementAsync().ConfigureAwait(false); - var header = await MessageHeaderExtractor - .ExtractAsync(reader, root, HeaderElementName, SeriesElementName) - .ConfigureAwait(false); + var seriesElements = document.Descendants(ns + SeriesElementName); + var result = new List(); - var listOfSeries = new List(); - await foreach (var series in ParseSeriesAsync(reader, root)) + foreach (var seriesElement in seriesElements) { - listOfSeries.Add(series); + var id = seriesElement.Element(ns + MridElementName)?.Value ?? string.Empty; + var startDateAndOrTimeDateTime = seriesElement.Element(ns + StartElementName)?.Value ?? string.Empty; + var endDateAndOrTimeDateTime = seriesElement.Element(ns + EndElementName)?.Value; + var gridArea = seriesElement.Element(ns + GridAreaElementName)?.Value; + var energySupplierId = seriesElement.Element(ns + EnergySupplierElementName)?.Value; + var chargeTypeOwnerId = seriesElement.Element(ns + ChargeOwnerElementName)?.Value; + var settlementVersion = seriesElement.Element(ns + SettlementVersionElementName)?.Value; + var resolution = seriesElement.Element(ns + ResolutionElementName)?.Value; + + var chargeTypes = seriesElement.Descendants(ns + ChargeElementName) + .Select(e => new RequestWholesaleServicesChargeType( + e.Element(ns + MridElementName)?.Value, + e.Element(ns + ChargeTypeElementName)?.Value)); + + result.Add(new RequestWholesaleServicesSeries( + id, + startDateAndOrTimeDateTime, + endDateAndOrTimeDateTime, + gridArea, + energySupplierId, + settlementVersion, + resolution, + chargeTypeOwnerId, + chargeTypes.Select(a => a).ToList())); } + return result.AsReadOnly(); + } + + protected override IncomingMarketMessageParserResult CreateResult(MessageHeader header, IReadOnlyCollection transactions) + { return new IncomingMarketMessageParserResult(new RequestWholesaleServicesMessage( header.SenderId, header.SenderRole, @@ -58,120 +87,6 @@ protected override async Task ParseXmlDataAsy header.MessageId, header.CreatedAt, header.BusinessType, - listOfSeries.AsReadOnly())); - } - - private async IAsyncEnumerable ParseSeriesAsync( - XmlReader reader, - RootElement rootElement) - { - var id = string.Empty; - var startDateAndOrTimeDateTime = string.Empty; - string? endDateAndOrTimeDateTime = null; - string? gridArea = null; - string? energySupplierId = null; - string? chargeTypeOwnerId = null; - string? settlementVersion = null; - string? resolution = null; - string? chargeType = null; - string? chargeId = null; - List chargeTypes = new(); - var ns = rootElement.DefaultNamespace; - - await reader.AdvanceToAsync(SeriesElementName, ns).ConfigureAwait(false); - - while (!reader.EOF) - { - if (reader.Is(SeriesElementName, ns, XmlNodeType.EndElement)) - { - var series = new RequestWholesaleServicesSeries( - id, - startDateAndOrTimeDateTime, - endDateAndOrTimeDateTime, - gridArea, - energySupplierId, - settlementVersion, - resolution, - chargeTypeOwnerId, - // clones the list - chargeTypes.Select(a => a).ToList()); - - id = string.Empty; - startDateAndOrTimeDateTime = string.Empty; - endDateAndOrTimeDateTime = null; - gridArea = null; - energySupplierId = null; - chargeTypeOwnerId = null; - settlementVersion = null; - resolution = null; - chargeType = null; - chargeId = null; - chargeTypes.Clear(); - yield return series; - } - - if (reader.NodeType == XmlNodeType.Element && reader.SchemaInfo?.Validity == XmlSchemaValidity.Invalid) - await reader.ReadToEndAsync().ConfigureAwait(false); - - if (reader.Depth == 2 && reader.Is("mRID", ns)) - { - id = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("start_DateAndOrTime.dateTime", ns)) - { - startDateAndOrTimeDateTime = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("end_DateAndOrTime.dateTime", ns)) - { - endDateAndOrTimeDateTime = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("meteringGridArea_Domain.mRID", ns)) - { - gridArea = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("energySupplier_MarketParticipant.mRID", ns)) - { - energySupplierId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("chargeTypeOwner_MarketParticipant.mRID", ns)) - { - chargeTypeOwnerId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("settlement_Series.version", ns)) - { - settlementVersion = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Is("aggregationSeries_Period.resolution", ns)) - { - resolution = reader.ReadString(); - } - else if (reader.Depth == 3 && reader.Is("type", ns)) - { - chargeType = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - else if (reader.Depth == 3 && reader.Is("mRID", ns)) - { - chargeId = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false); - } - - // We're at the end of a charge type element - else if (reader.Is("ChargeType", ns, XmlNodeType.EndElement)) - { - // chargeId and chargeType are read, since these lives inside the ChargeType element - var chargeTypeOwner = new RequestWholesaleServicesChargeType(chargeId, chargeType); - chargeTypes.Add(chargeTypeOwner); - - // Reset the current values, since we're done with this chargeType element - chargeType = null; - chargeId = null; - - // Move to next element - await reader.ReadAsync().ConfigureAwait(false); - } - else - { - await reader.ReadAsync().ConfigureAwait(false); - } - } + transactions)); } } diff --git a/source/IncomingMessages.Infrastructure/MessageParsers/XmlMessageParserBase.cs b/source/IncomingMessages.Infrastructure/MessageParsers/XmlMessageParserBase.cs index 03cb05e6a9..1324d13b0d 100644 --- a/source/IncomingMessages.Infrastructure/MessageParsers/XmlMessageParserBase.cs +++ b/source/IncomingMessages.Infrastructure/MessageParsers/XmlMessageParserBase.cs @@ -37,6 +37,8 @@ public abstract class XmlMessageParserBase(CimXmlSchemaProvider schemaProvider) private const string BusinessSectorTypeElementName = "businessSector.type"; private readonly CimXmlSchemaProvider _schemaProvider = schemaProvider; + public override DocumentFormat DocumentFormat => DocumentFormat.Xml; + protected abstract string RootPayloadElementName { get; } private Collection ValidationErrors { get; } = []; diff --git a/source/Tests/CimMessageAdapter/Messages/RequestAggregatedMeasureData/MessageParserTests.cs b/source/Tests/CimMessageAdapter/Messages/RequestAggregatedMeasureData/MessageParserTests.cs index 3e374d7709..de9d28b0a1 100644 --- a/source/Tests/CimMessageAdapter/Messages/RequestAggregatedMeasureData/MessageParserTests.cs +++ b/source/Tests/CimMessageAdapter/Messages/RequestAggregatedMeasureData/MessageParserTests.cs @@ -45,7 +45,7 @@ public sealed class MessageParserTests private readonly MarketMessageParser _marketMessageParser = new( [ - new AggregatedMeasureDataXmlMessageParser(new CimXmlSchemaProvider(new CimXmlSchemas())), + new OldAggregatedMeasureDataXmlMessageParser(new List { new AggregatedMeasureDataXmlMessageParser(new CimXmlSchemaProvider(new CimXmlSchemas())) }), new AggregatedMeasureDataJsonMessageParser(new JsonSchemaProvider(new CimJsonSchemas())), new AggregatedMeasureDataB2CJsonMessageParser(new Serializer()), ]); diff --git a/source/Tests/CimMessageAdapter/Messages/WholesaleSettlementMessageParsers/MessageParserTests.cs b/source/Tests/CimMessageAdapter/Messages/WholesaleSettlementMessageParsers/MessageParserTests.cs index fa3f319cab..7ed8cc2a50 100644 --- a/source/Tests/CimMessageAdapter/Messages/WholesaleSettlementMessageParsers/MessageParserTests.cs +++ b/source/Tests/CimMessageAdapter/Messages/WholesaleSettlementMessageParsers/MessageParserTests.cs @@ -51,7 +51,7 @@ public MessageParserTests() { _marketMessageParser = new MarketMessageParser( [ - new WholesaleSettlementXmlMessageParser(new CimXmlSchemaProvider(new CimXmlSchemas())), + new OldWholesaleSettlementXmlMessageParser(new List() { new WholesaleSettlementXmlMessageParser(new CimXmlSchemaProvider(new CimXmlSchemas())) }), new WholesaleSettlementJsonMessageParser(new JsonSchemaProvider(new CimJsonSchemas())), new WholesaleSettlementB2CJsonMessageParser(_serializer), ]);