first commit
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
using System.Xml.Linq;
|
||||
using Serilog;
|
||||
using CRIF.ACTion.Common;
|
||||
using CRIF.ACTion.Common.Parsers;
|
||||
|
||||
namespace CRIF.ACTion.Configuration
|
||||
{
|
||||
public class ConfigurationRequestResponseParser : IResponseParser<SortedList<int, string>>
|
||||
{
|
||||
private const string _channelsPath = "/actionAPI/getChannels/msg:maintExportResponse/msg:maintenanceEntities/maint:parties/common:channel/common:channelClassifications/common:channelClassification/common:channelClassificationItem";
|
||||
|
||||
public ConfigurationRequestResponseParser()
|
||||
{
|
||||
}
|
||||
|
||||
public SortedList<int, string> Parse(XElement xElement)
|
||||
{
|
||||
SortedList<int, string> mappingList = [];
|
||||
|
||||
try
|
||||
{
|
||||
var namespaceManager = CrifNamespaces.GetNamespaceManager(xElement);
|
||||
IEnumerable<XElement> channelNodeList = xElement.XElementXPathSelectElements(_channelsPath, namespaceManager);
|
||||
|
||||
foreach (XElement channelNode in channelNodeList)
|
||||
{
|
||||
try
|
||||
{
|
||||
string nodeAttributeValue = StandardizedStringValue(channelNode.Attribute(CrifNamespaces.Common + "name").Value);
|
||||
if (ChannelIsActive(nodeAttributeValue))
|
||||
{
|
||||
|
||||
string partyIdString = channelNode.Parent.Parent.Parent.Attribute(CrifNamespaces.Common + "partyID").Value;
|
||||
string name = channelNode.Parent.Parent.Parent.Attribute(CrifNamespaces.Common + "name").Value;
|
||||
_ = int.TryParse(partyIdString, out int partyId);
|
||||
mappingList.Add(partyId, name);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error trying to parse CRIF BranchName Configuration Response", ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error trying to parse CRIF BranchName Configuration Response", ex.Message, ex.StackTrace);
|
||||
}
|
||||
return mappingList;
|
||||
}
|
||||
|
||||
private static bool ChannelIsActive(string nodeAttributeValue)
|
||||
{
|
||||
bool channelIsActive = false;
|
||||
if (!string.IsNullOrWhiteSpace(nodeAttributeValue))
|
||||
{
|
||||
channelIsActive =
|
||||
(
|
||||
nodeAttributeValue.Equals("BRANCH") ||
|
||||
nodeAttributeValue.Equals("INTERNET") ||
|
||||
nodeAttributeValue.Equals("ON-LINE")
|
||||
);
|
||||
}
|
||||
return channelIsActive;
|
||||
}
|
||||
|
||||
private static string StandardizedStringValue(string InputString)
|
||||
{
|
||||
string standardizedString = "";
|
||||
if (!string.IsNullOrWhiteSpace(InputString))
|
||||
{
|
||||
standardizedString = InputString.Trim().ToUpper();
|
||||
}
|
||||
return standardizedString;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user