Ejemplo n.º 1
0
        internal override DeserializeResponse Deserialize(string payload)
        {
            using (new MethodLogger(s_logger))
            {
                try
                {
                    var dr = base.Deserialize(payload);

                    if (dr.HasError || dr.IsRecoverySync)
                    {
                        return(dr);
                    }

                    if (dr.Phase != TransactionPhase.Initialisation)
                    {
                        return(dr);
                    }

                    _transactionId = dr.TransactionId;

                    var doc = XDocument.Parse(payload);
                    var xph = new XPathHelper(doc, Namespaces);

                    var decryptedOd = DecryptOrderData(xph);
                    var deflatedOd  = Decompress(decryptedOd);
                    var strResp     = Encoding.UTF8.GetString(deflatedOd);
                    var hpdrod      = XDocument.Parse(strResp);
                    var r           = new XPathHelper(hpdrod, Namespaces);

                    s_logger.LogDebug("Order data:\n{orderData}", hpdrod.ToString());

                    var urlList = new List <Url>();
                    var xmlUrls = r.GetAccessParamsUrls();
                    foreach (var xmlUrl in xmlUrls)
                    {
                        var validFrom = ParseISO8601Timestamp(xmlUrl.Attribute(XmlNames.valid_from)?.Value);
                        urlList.Add(new Url {
                            ValidFrom = validFrom, Address = xmlUrl.Value
                        });
                    }

                    var accessParams = new AccessParams
                    {
                        Urls      = urlList,
                        HostId    = r.GetAccessParamsHostId()?.Value,
                        Institute = r.GetAccessParamsInstitute()?.Value
                    };

                    var version = new Version
                    {
                        Protocols       = r.GetProtocolParamsProtocol()?.Value.Trim().Split(" ").ToList(),
                        Authentications = r.GetProtocolParamsAuthentication()?.Value.Trim().Split(" ").ToList(),
                        Encryptions     = r.GetProtocolParamsEncryption()?.Value.Trim().Split(" ").ToList(),
                        Signatures      = r.GetProtocolParamsSignature()?.Value.Trim().Split(" ").ToList()
                    };

                    bool.TryParse(r.GetProtocolParamsRecovery()?.Attribute(XmlNames.supported)?.Value,
                                  out var recoverySupp);
                    bool.TryParse(r.GetProtocolParamsPreValidation()?.Attribute(XmlNames.supported)?.Value,
                                  out var preValidationSupp);
                    bool.TryParse(r.GetProtocolParamsX509Data()?.Attribute(XmlNames.supported)?.Value,
                                  out var x509Supp);
                    bool.TryParse(r.GetProtocolParamsX509Data()?.Attribute(XmlNames.persistent)?.Value,
                                  out var x509Pers);
                    bool.TryParse(r.GetProtocolParamsClientDataDownload()?.Attribute(XmlNames.supported)?.Value,
                                  out var clientDataDownloadSupp);
                    bool.TryParse(r.GetProtocolParamsDownloadableOrderData()?.Attribute(XmlNames.supported)?.Value,
                                  out var downloadableOrderDataSupp);

                    var protocolParams = new ProtocolParams
                    {
                        Version                        = version,
                        RecoverySupported              = recoverySupp,
                        PreValidationSupported         = preValidationSupp,
                        X509DataSupported              = x509Supp,
                        X509DataPersistent             = x509Pers,
                        ClientDataDownloadSupported    = clientDataDownloadSupp,
                        DownloadableOrderDataSupported = downloadableOrderDataSupp
                    };

                    Response.AccessParams   = accessParams;
                    Response.ProtocolParams = protocolParams;

                    return(dr);
                }
                catch (EbicsException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new DeserializationException($"can't deserialize {OrderType} command", ex, payload);
                }
            }
        }