Exemplo n.º 1
0
 public void Export()
 {
     try
     {
         string fileName = filePathDelegate.Invoke();
         PsaTracesSerializer serializer =
             new PsaTracesSerializer(traces);
         using (MemoryStream serialized = new MemoryStream())
         {
             serializer.Serialize(serialized);
             serialized.Position = 0;
             ExportDataCompressor compressor =
                 new ExportDataCompressor(serialized);
             using (MemoryStream compressed = new MemoryStream())
             {
                 compressor.Compress(compressed);
                 compressed.Position = 0;
                 ExportDataEncryptor encryptor =
                     new ExportDataEncryptor(compressed);
                 using (MemoryStream encrypted = new MemoryStream())
                 {
                     encryptor.Encrypt(encrypted);
                     encrypted.Position = 0;
                     if (!String.IsNullOrEmpty(fileName))
                     {
                         using (FileStream output = new FileStream(fileName,
                                                                   FileMode.CreateNew))
                         {
                             encrypted.CopyTo(output);
                         }
                     }
                 }
             }
         }
         if (finishCallback != null)
         {
             finishCallback.Invoke(true, fileName);
         }
     }
     catch (Exception e)
     {
         if (finishCallback != null)
         {
             finishCallback.Invoke(false, e.Message);
         }
     }
 }
Exemplo n.º 2
0
        public void XmlCompressionDecompressionTest()
        {
            FileStream           stream     = new FileStream("./compression/XmlFile.xml", FileMode.Open);
            ExportDataCompressor compressor = new ExportDataCompressor(stream);
            MemoryStream         mems       = new MemoryStream();

            compressor.Compress(mems);
            mems.Position = 0;

            try
            {
                XDocument doc = XDocument.Load(mems);
                doc.ToString();
                Assert.IsFalse(true);
            }
            catch (Exception)
            {
                mems.Position = 0;
            }
            MemoryStream mems2 = new MemoryStream();

            mems.CopyTo(mems2);
            mems2.Flush();
            mems2.Position = 0;
            ExportDataCompressor compressor2  = new ExportDataCompressor(mems2);
            MemoryStream         decompressed = new MemoryStream();

            compressor2.Decompress(decompressed);
            decompressed.Position = 0;
            XDocument doc2 = XDocument.Load(decompressed);
            XElement  root = doc2.Root;

            Assert.IsTrue(root.HasElements);
            XElement xtag1 = root.Element("XmlTag1");

            Assert.IsTrue(xtag1.Value == "XML Value 1");
        }