private void WriteReport(ZipStorer zipStorer, Report report)
        {
            using (var stream = new MemoryStream())
            {
                // Store the report as XML file
                try
                {
                    var serializer = report.CustomInfo != null
                                     ? new XmlSerializer(typeof(Report), new[] { report.CustomInfo.GetType() })
                                     : new XmlSerializer(typeof(Report));

                    serializer.Serialize(stream, report);
                }
                catch (Exception exception)
                {
                    if (report.CustomInfo != null)
                    {
                        Logger.Error(
                            string.Format(
                                "The given custom info of type [{0}] cannot be serialized. Make sure that given type and inner types are XML serializable.",
                                report.CustomInfo.GetType()), exception);
                    }
                    report.CustomInfo = null;
                    var serializer = new XmlSerializer(typeof(Report));
                    serializer.Serialize(stream, report);
                }

                stream.Position = 0;
                zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Report, stream, DateTime.UtcNow,
                                    string.Empty);
            }
        }
 private void WriteException(ZipStorer zipStorer, SerializableException serializableException)
 {
     using (var stream = new MemoryStream())
     {
         // Store the exception as separate file
         var serializer = new XmlSerializer(typeof(SerializableException));
         serializer.Serialize(stream, serializableException);
         stream.Position = 0;
         zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Exception, stream, DateTime.UtcNow,
                             string.Empty);
     }
 }
Example #3
0
        private void WriteReport(ZipStorer zipStorer, Report report)
        {
            using (var stream = new MemoryStream())
            {
                // Store the report as XML file
                try
                {
                    var serializer = report.CustomInfo != null
                                     ? new XmlSerializer(typeof(Report), new[] { report.CustomInfo.GetType() })
                                     : new XmlSerializer(typeof(Report));

                    serializer.Serialize(stream, report);
                }
                catch (Exception exception)
                {
                    if (report.CustomInfo != null)
                    {
                        Logger.Error(
                            string.Format(
                                "The given custom info of type [{0}] cannot be serialized. Make sure that given type and inner types are XML serializable.",
                                report.CustomInfo.GetType()), exception);
                    }
                    report.CustomInfo = null;
                    var serializer = new XmlSerializer(typeof(Report));
                    serializer.Serialize(stream, report);
                }

                stream.Position = 0;
                zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Report, stream, DateTime.UtcNow,
                                    string.Empty);
            }
        }
Example #4
0
 private void WriteException(ZipStorer zipStorer, SerializableException serializableException)
 {
     using (var stream = new MemoryStream())
     {
         // Store the exception as separate file
         var serializer = new XmlSerializer(typeof(SerializableException));
         serializer.Serialize(stream, serializableException);
         stream.Position = 0;
         zipStorer.AddStream(ZipStorer.Compression.Deflate, StoredItemFile.Exception, stream, DateTime.UtcNow,
                             string.Empty);
     }
 }