Files
2026-03-11 11:18:25 -05:00

48 lines
1.8 KiB
C#

using System.Xml.Linq;
using Serilog;
using CRIF.ACTion.Common;
using CRIF.ACTion.Common.Parsers;
namespace CRIF.ACTion.Configuration
{
public class ProductDetailsResponseParser : IResponseParser<Dictionary<string, string>>
{
private const string _productDetailsPath = "/actionAPI/getProducts/msg:maintExportResponse/msg:maintenanceEntities/maint:maintenanceEntity/maint:products/common:product/common:productCategory";
public ProductDetailsResponseParser()
{
}
public Dictionary<string, string> Parse(XElement xElement)
{
Dictionary<string, string> mappingList = [];
try
{
var namespaceManager = CrifNamespaces.GetNamespaceManager(xElement);
IEnumerable<XElement> channelNodeList = xElement.XElementXPathSelectElements(_productDetailsPath, namespaceManager);
foreach (XElement channelNode in channelNodeList)
{
try
{
string productId = channelNode.Parent.Attribute(CrifNamespaces.Common + "productID").Value;
string categoryId = channelNode.Attribute(CrifNamespaces.Common + "productCategoryID").Value;
mappingList.Add(productId, categoryId);
}
catch (Exception ex)
{
Log.Error("Error trying to parse CRIF Product information from node in Configuration Response", ex.Message, ex.StackTrace);
}
}
}
catch (Exception ex)
{
Log.Error("Error trying to parse CRIF Products Configuration Response", ex.Message, ex.StackTrace);
}
return mappingList;
}
}
}