// Copyright (c) 2020-present schick Informatik // Description: Verarbeitung von empfangenen Rückmeldungen using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml.Serialization; using log4net; using bsmd.database; namespace bsmd.dbh { internal static class ResponseUtil { private static readonly ILog _log = LogManager.GetLogger(typeof(ResponseUtil)); private static readonly Regex _regexFilename = new Regex(@".*NSW\.DBH\.BSMD\.(.*)\.(.*)\.xml"); internal static bool Read(string inputFile) { bool result = false; if(!inputFile.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) { _log.ErrorFormat("no xml file: {0}", inputFile); return result; } Match m = _regexFilename.Match(inputFile); if(!m.Success) { _log.WarnFormat("returned file doesn't follow naming convention NSW.DBH.BSMD.*:{0}", inputFile); return result; } string guidString = m.Groups[0].Value; if(!Guid.TryParse(guidString, out Guid coreId)) { _log.ErrorFormat("matched Guid couldn't be parsed: {0}", guidString); return result; } string notificationClassString = m.Groups[1].Value; if(!Enum.TryParse(notificationClassString, out Message.NotificationClass notificationClass)) { _log.WarnFormat("Notification class couldn't be parsed: {0}", notificationClassString); return result; } MessageCore aCore = DBManager.Instance.GetMessageCoreById(coreId); if(aCore == null) { _log.ErrorFormat("There is no core with id {0}", coreId); return result; } bsmd.dbh.Response.Root root; try { XmlSerializer serializer = new XmlSerializer(typeof(bsmd.dbh.Response.Root)); using (Stream s = new FileStream(inputFile, FileMode.Open)) { root = (bsmd.dbh.Response.Root) serializer.Deserialize(s); } } catch(Exception ex) { _log.ErrorFormat("Failed to deserialize: {0}", ex.Message); return result; } return result; } } }