// // Class: Response // Current CLR: 4.0.30319.34209 // System: Microsoft Visual Studio 10.0 // Author: dani // Created: 5/5/2015 8:13:01 AM // // Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved. using System; using System.Collections.Generic; using System.IO; using System.Xml; using System.Xml.Serialization; using log4net; using bsmd.database; namespace bsmd.dakosy { public class Response { private static ILog _log = LogManager.GetLogger(typeof(Request)); public static bool Read(string fullPath) { bool retval = true; try { XmlSerializer serializer = new XmlSerializer(typeof(EdiResponse)); FileStream fs = new FileStream(fullPath, FileMode.Open); using (TextReader reader = new StreamReader(fs)) { EdiResponse ediResponse = (EdiResponse)serializer.Deserialize(reader); Guid localReferenceId, messageReferenceId; if (!Guid.TryParseExact(ediResponse.LocalReferenceNumber, "N", out localReferenceId)) { _log.ErrorFormat("unable to parse local reference number {0}", ediResponse.LocalReferenceNumber); } if(!Guid.TryParseExact(ediResponse.MessageHeader.MessageReferenceNumber, "N", out messageReferenceId)) { _log.ErrorFormat("unable to parse message reference id {0}", ediResponse.MessageHeader.MessageReferenceNumber); } // passendes Objekt in der DB finden: MessageCore core = DBManager.Instance.GetMessageCoreById(localReferenceId); DatabaseEntity dbEntity = DBManager.Instance.GetMessageById(messageReferenceId); // Objekte aktualisieren und speichern Message aMessage = null; if (dbEntity.GetType().IsAssignableFrom(typeof(Message))) aMessage = (Message)dbEntity; else aMessage = dbEntity.MessageHeader; //ediResponse.ResponseSubType == EdiResponseSubType.FUNCTIONAL // TECHNICAL switch (ediResponse.ResponseType) { case EdiResponseType.ACCEPTED: _log.Info("response message accepted"); break; case EdiResponseType.ERROR: _log.Info("response message error status"); break; case EdiResponseType.PART_ACCEPTED: _log.Info("response message part accepted"); break; case EdiResponseType.RECEIVED: _log.Info("response message received"); break; } //aMessage.Status = Message.MessageStatus. aMessage.InternalStatus = Message.BSMDStatus.RESPONDED; DBManager.Instance.Save(aMessage); } fs.Close(); } catch (Exception ex) { _log.ErrorFormat("error parsing response:{0}", ex.ToString()); retval = false; } return retval; } } }