Example #1
0
        public static string Transform(string xsl, string xml)
        {
            XslCompiledTransform xslt         = new XslCompiledTransform();
            StringReader         stringReader = new StringReader(xsl);
            XmlReader            xmlReader    = XmlReader.Create(stringReader);

            xslt.Load(xmlReader);
            stringReader = new StringReader(xml);
            xmlReader    = XmlReader.Create(stringReader);
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            //xmlWriterSettings.Encoding = Encoding.UTF8;
            xmlWriterSettings.Indent             = true;
            xmlWriterSettings.OmitXmlDeclaration = true;
            Stream    stream    = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings);

            xslt.Transform
            (
                xmlReader
                , xmlWriter
            );
            byte[]   buffer = StreamDataHelper.ReadDataToBytes(stream);
            Encoding e      = EncodingHelper.IdentifyEncoding(stream, Encoding.Default);
            int      offset = e.GetPreamble().Length;
            string   s      = e.GetString(buffer, offset, buffer.Length - offset);

            return(s);
        }
Example #2
0
        public void CompressStream()
        {
            //压缩 响应
            Stream stream = CompressHelper.GZipCompress(_workStream);

            byte[] buffer = StreamDataHelper.ReadDataToBytes(stream);
            _originalStream.Write(buffer, 0, buffer.Length);
        }
Example #3
0
 public void DecompressStream()
 {
     //解压 请求
     byte[] bytes = StreamDataHelper.ReadDataToBytes(_originalStream);
     bytes = CompressHelper.GZipDecompress(bytes);
     _workStream.Write(bytes, 0, bytes.Length);
     _workStream.Position = 0;
 }
        public static byte[] GetBytes(this MailMessage mailMessage)
        {
            Assembly assembly        = typeof(SmtpClient).Assembly;
            Type     type            = assembly.GetType("System.Net.Mail.MailWriter");
            var      parametersTypes = new[]
            {
                typeof(Stream)
            };
            object x = null;

            using (Stream stream = new MemoryStream())
            {
                var constructorInfo = type.GetConstructor
                                      (
                    BindingFlags.Instance | BindingFlags.NonPublic
                    , null
                    , parametersTypes
                    , null
                                      );
                var func = DynamicCallMethodExpressionTreeInvokerHelper.CreateNewInstanceConstructorInvokerFunc <object>
                           (
                    type
                    , constructorInfo
                           );
                x = func(new[] { stream });
                var action = DynamicCallMethodExpressionTreeInvokerHelper.CreateMethodCallInvokerAction <MailMessage>
                             (
                    typeof(MailMessage)
                    , () =>
                {
                    var methodInfo = typeof(MailMessage).GetMethod
                                     (
                        "Send"
                        , BindingFlags.NonPublic | BindingFlags.Instance
                        , null
                        , new[] { type, typeof(bool) }
                        , null
                                     );
                    return(methodInfo);
                }
                             );
                action
                (
                    mailMessage
                    , new[]
                {
                    x
                    , true
                }
                );
                byte[] buffer = StreamDataHelper.ReadDataToBytes(stream);
                return(buffer);
            }
        }
        public static Stream GZipDecompress(Stream data)
        {
            byte[]       buffer = StreamDataHelper.ReadDataToBytes(data);
            MemoryStream ms     = new MemoryStream(buffer);
            GZipStream   stream = new GZipStream(ms, CompressionMode.Decompress);

            if (stream.CanSeek)
            {
                stream.Position = 0;
            }
            return(stream);
        }
        public static string DataContractSerializerObjectToXml <T>(T Object, DataContractSerializer serializer)
        {
            MemoryStream ms = new MemoryStream();

            serializer.WriteObject(ms, Object);
            byte[] buffer = StreamDataHelper.ReadDataToBytes(ms);
            string xml    = Encoding.UTF8.GetString(buffer);

            ms.Close();
            ms.Dispose();
            ms = null;
            return(xml);
        }
 public static Encoding IdentifyEncoding
 (
     Stream stream
     , Encoding defaultEncoding
 )
 {
     byte[] data = StreamDataHelper.ReadDataToBytes(stream);
     return(IdentifyEncoding
            (
                data
                , defaultEncoding
            ));
 }
        public static byte[] DeflateDecompress(byte[] data)
        {
            MemoryStream  ms     = new MemoryStream(data);
            DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress);

            byte[] buffer = StreamDataHelper.ReadDataToBytes(stream);
            ms.Close();
            ms.Dispose();
            ms = null;
            stream.Close();
            stream.Dispose();
            stream = null;
            return(buffer);
        }
        public static byte[] DeflateCompress(byte[] DATA)
        {
            MemoryStream  ms     = new MemoryStream();
            DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true);

            stream.Write(DATA, 0, DATA.Length);
            stream.Close();
            stream.Dispose();
            stream = null;
            byte[] buffer = StreamDataHelper.ReadDataToBytes(ms);
            ms.Close();
            ms.Dispose();
            ms = null;
            return(buffer);
        }
        public static byte[] GZipDecompress(byte[] data)
        {
            //Console.WriteLine("GZipDecompress");
            MemoryStream ms     = new MemoryStream(data);
            GZipStream   stream = new GZipStream(ms, CompressionMode.Decompress);

            byte[] buffer = StreamDataHelper.ReadDataToBytes(stream);
            ms.Close();
            ms.Dispose();
            ms = null;
            stream.Close();
            stream.Dispose();
            stream = null;
            return(buffer);
        }
        public static byte[] GZipCompress(byte[] DATA)
        {
            //Console.WriteLine("GZipCompress");
            MemoryStream ms     = new MemoryStream();
            GZipStream   stream = new GZipStream(ms, CompressionMode.Compress, true);

            stream.Write(DATA, 0, DATA.Length);
            stream.Close();
            stream.Dispose();
            stream = null;
            byte[] buffer = StreamDataHelper.ReadDataToBytes(ms);
            ms.Close();
            ms.Dispose();
            ms = null;
            return(buffer);
        }
        public static Stream DeflateCompress(Stream DATA)
        {
            byte[]        buffer = StreamDataHelper.ReadDataToBytes(DATA);
            MemoryStream  ms     = new MemoryStream();
            DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true);

            stream.Write(buffer, 0, buffer.Length);
            stream.Close();
            stream.Dispose();
            stream = null;
            if (ms.CanSeek)
            {
                ms.Position = 0;
            }
            return(ms);
        }
        public static Stream GZipCompress(Stream DATA)
        {
            Console.WriteLine("GZipCompress");
            byte[]       buffer = StreamDataHelper.ReadDataToBytes(DATA);
            MemoryStream ms     = new MemoryStream();
            GZipStream   stream = new GZipStream(ms, CompressionMode.Compress, true);

            stream.Write(buffer, 0, buffer.Length);
            stream.Close();
            stream.Dispose();
            stream = null;
            if (ms.CanSeek)
            {
                ms.Position = 0;
            }
            return(ms);
        }