public AggregateReportInfo Deserialise(AttachmentInfo attachment, EmailMetadata emailMetadata)
        {
            using (Stream stream = attachment.GetStream())
            {
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    using (XmlReader reader = XmlReader.Create(streamReader))
                    {
                        XDocument document = XDocument.Load(reader);

                        XElement feedback = document.Root;
                        if (document.Root.Name != "feedback")
                        {
                            throw new ArgumentException("Root of aggregate report must be feedback.");
                        }

                        ReportMetadata  reportMetadata  = _reportMetadataDeserialiser.Deserialise(feedback.Single("report_metadata"));
                        PolicyPublished policyPublished = _policyPublishedDeserialiser.Deserialise(feedback.Single("policy_published"));

                        IEnumerable <XElement> recordElements = feedback.Where("record").ToList();

                        if (!recordElements.Any())
                        {
                            throw new ArgumentException("Aggregate report must contain at least 1 record.");
                        }

                        Record[] records = _recordDeserialiser.Deserialise(recordElements);

                        Domain.Dmarc.AggregateReport aggregateReport = new Domain.Dmarc.AggregateReport(reportMetadata, policyPublished, records);
                        return(new AggregateReportInfo(aggregateReport, emailMetadata, attachment.AttachmentMetadata));
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void Persist(AttachmentInfo attachment)
 {
     using (var fileStream = File.Create($"{_location.FullName}/{attachment.AttachmentMetadata.Filename}.xml"))
     {
         using (var stream = attachment.GetStream())
         {
             stream.CopyTo(fileStream);
         }
     }
 }