当前位置: 首页>>代码示例>>C#>>正文


C# IO.MemoryStream类代码示例

本文整理汇总了C#中System.IO.MemoryStream的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream类的具体用法?C# MemoryStream怎么用?C# MemoryStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MemoryStream类属于System.IO命名空间,在下文中一共展示了MemoryStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Invoke

        public Task Invoke(IDictionary<string, object> environment)
        {
            if (!environment.Get<string>(OwinConstants.RequestMethodKey).EqualsIgnoreCase("GET"))
            {
                return _inner(environment);
            }

            var originalOutput = environment.Get<Stream>(OwinConstants.ResponseBodyKey);
            var recordedStream = new MemoryStream();
            environment.Set(OwinConstants.ResponseBodyKey, recordedStream);

            return _inner(environment).ContinueWith(t => {
                recordedStream.Position = 0;
                environment[OwinConstants.ResponseBodyKey] = originalOutput;

                var response = new OwinHttpResponse(environment);

                if (IsGetHtmlRequest(environment) && response.StatusCode < 500)
                {
                    injectContent(environment, recordedStream, response);
                }
                else
                {
                    response.StreamContents(recordedStream);
                }
            });
        }
开发者ID:joemcbride,项目名称:fubumvc,代码行数:27,代码来源:HtmlHeadInjectionMiddleware.cs

示例2: ToBytes

 /// <summary>
 /// 将一个对象序列化为字节数组
 /// </summary>
 /// <param name="data">要序列化的对象</param>
 /// <returns>序列化好的字节数组</returns>
 public static byte[] ToBytes(Object data)
 {
     MemoryStream ms = new MemoryStream();
     BinaryFormatter bf = new BinaryFormatter();
     bf.Serialize(ms, data);
     return ms.ToArray();
 }
开发者ID:burstinair,项目名称:burst.net,代码行数:12,代码来源:NetUtil.cs

示例3: Decrypt

        public static string Decrypt(string sourceData)
        {
            // set key and initialization vector values
              byte[] key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
              byte[] iv = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
              try
              {
            // convert data to byte array
            byte[] encryptedDataBytes =
               Convert.FromBase64String(sourceData);

            // get source memory stream and fill it
            MemoryStream tempStream =
               new MemoryStream(encryptedDataBytes, 0,
              encryptedDataBytes.Length);

            // get decryptor and decryption stream
            DESCryptoServiceProvider decryptor =
               new DESCryptoServiceProvider();
            CryptoStream decryptionStream =
               new CryptoStream(tempStream,
              decryptor.CreateDecryptor(key, iv),
              CryptoStreamMode.Read);

            // decrypt data
            StreamReader allDataReader =
               new StreamReader(decryptionStream);
            return allDataReader.ReadToEnd();
              }
              catch
              {
            throw new StringEncryptorException(
               "Unable to decrypt data.");
              }
        }
开发者ID:moacap,项目名称:BalloonShop-2-MVC,代码行数:35,代码来源:StringEncryptor.cs

示例4: Encrypt

        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="pToEncrypt">需要加密字符串</param>
        /// <param name="sKey">密钥</param>
        /// <returns>加密后的字符串</returns>
        public static string Encrypt(string pToEncrypt, string sKey)
        {
            try
            {
                DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                //把字符串放到byte数组中

                //原来使用的UTF8编码,我改成Unicode编码了,不行
                byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);

                //建立加密对象的密钥和偏移量

                //使得输入密码必须输入英文文本
                des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                MemoryStream ms = new MemoryStream();
                CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);

                cs.Write(inputByteArray, 0, inputByteArray.Length);
                cs.FlushFinalBlock();
                StringBuilder ret = new StringBuilder();
                foreach (byte b in ms.ToArray())
                {
                    ret.AppendFormat("{0:X2}", b);
                }
                ret.ToString();
                return ret.ToString();
            }
            catch (Exception ex)
            {

            }

            return "";
        }
开发者ID:SuperRay,项目名称:MoMoWeb,代码行数:41,代码来源:CommonFunction.cs

示例5: AllFieldsEmptyTest

        public void AllFieldsEmptyTest()
        {
            using( var stream = new MemoryStream() )
            using( var reader = new StreamReader( stream ) )
            using( var writer = new StreamWriter( stream ) )
            using( var parser = new CsvParser( reader ) )
            {
                writer.WriteLine( ";;;;" );
                writer.WriteLine( ";;;;" );
                writer.Flush();
                stream.Position = 0;

                parser.Configuration.Delimiter = ";;";
                parser.Configuration.HasHeaderRecord = false;

                var row = parser.Read();
                Assert.IsNotNull( row );
                Assert.AreEqual( 3, row.Length );
                Assert.AreEqual( "", row[0] );
                Assert.AreEqual( "", row[1] );
                Assert.AreEqual( "", row[2] );

                row = parser.Read();
                Assert.IsNotNull( row );
                Assert.AreEqual( 3, row.Length );
                Assert.AreEqual( "", row[0] );
                Assert.AreEqual( "", row[1] );
                Assert.AreEqual( "", row[2] );

                row = parser.Read();
                Assert.IsNull( row );
            }
        }
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:33,代码来源:CsvParserDelimiterTests.cs

示例6: Deserialize

            public static MessageBase Deserialize(byte[] data)
            {
                using (MemoryStream stream = new MemoryStream(data))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    // Ignore initial key
                    reader.ReadByte();
                    byte payloadLength = reader.ReadByte();
                    byte packageSequence = reader.ReadByte();
                    byte systemId = reader.ReadByte();
                    byte componentId = reader.ReadByte();
                    byte messageId = reader.ReadByte();

                    // Create instance based on message id
                    MessageBase message = null;
                    Type messageType;
                    if (_messageTypes.TryGetValue(messageId, out messageType))
                    {
                        message = (MessageBase)Activator.CreateInstance(messageType);

                        message._fields = new object[message._fieldTypes.Length];
                        for (int i = 0; i < message._fieldTypes.Length; ++i)
                        {
                            message.ReadField(reader, i);
                        }

                        // TODO: Verify CRC
                        byte LSBCRC = reader.ReadByte();
                        byte MSBCRC = reader.ReadByte();
                    }

                    return message;
                }
            }
开发者ID:Romout,项目名称:MavLinkGenerator,代码行数:34,代码来源:CSharpTemplate.cs

示例7: Encode

        public static string Encode(string str, string key)
        {
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();

            provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));

            provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));

            byte[] bytes = Encoding.UTF8.GetBytes(str);

            MemoryStream stream = new MemoryStream();

            CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write);

            stream2.Write(bytes, 0, bytes.Length);

            stream2.FlushFinalBlock();

            StringBuilder builder = new StringBuilder();

            foreach (byte num in stream.ToArray())
            {

                builder.AppendFormat("{0:X2}", num);

            }

            stream.Close();

            return builder.ToString();
        }
开发者ID:MrNor,项目名称:WxMp,代码行数:31,代码来源:CryptHelper.cs

示例8: getMAIN

        internal static byte[] getMAIN(byte[] ramsav)
        {
            byte[] main;
            uint[] offsets;
            uint[] lens;
            uint[] magics;
            uint[] skips;
            uint[] instances;
            uint val = BitConverter.ToUInt32(ramsav, 0);
            uint spos = 0;
            if (ramsav.Length == 0x80000) // ORAS
            {
                offsets = new uint[] { 0x00005400, 0x00005800, 0x00006400, 0x00006600, 0x00006800, 0x00006A00, 0x00006C00, 0x00006E00, 0x00007000, 0x00007200, 0x00007400, 0x00009600, 0x00009800, 0x00009E00, 0x0000A400, 0x0000F400, 0x00014400, 0x00019400, 0x00019600, 0x00019E00, 0x0001A400, 0x0001B600, 0x0001BE00, 0x0001C000, 0x0001C200, 0x0001C800, 0x0001CA00, 0x0001CE00, 0x0001D600, 0x0001D800, 0x0001DA00, 0x0001DC00, 0x0001DE00, 0x0001E000, 0x0001E800, 0x0001EE00, 0x0001F200, 0x00020E00, 0x00021000, 0x00021400, 0x00021800, 0x00022000, 0x00023C00, 0x00024000, 0x00024800, 0x00024C00, 0x00025600, 0x00025A00, 0x00026200, 0x00027000, 0x00027200, 0x00027400, 0x00028200, 0x00028A00, 0x00028E00, 0x00030A00, 0x00038400, 0x0006D000, 0x0007B200 };
                lens = new uint[] { 0x000002C8, 0x00000B90, 0x0000002C, 0x00000038, 0x00000150, 0x00000004, 0x00000008, 0x000001C0, 0x000000BE, 0x00000024, 0x00002100, 0x00000130, 0x00000440, 0x00000574, 0x00004E28, 0x00004E28, 0x00004E28, 0x00000170, 0x0000061C, 0x00000504, 0x000011CC, 0x00000644, 0x00000104, 0x00000004, 0x00000420, 0x00000064, 0x000003F0, 0x0000070C, 0x00000180, 0x00000004, 0x0000000C, 0x00000048, 0x00000054, 0x00000644, 0x000005C8, 0x000002F8, 0x00001B40, 0x000001F4, 0x000003E0, 0x00000216, 0x00000640, 0x00001A90, 0x00000400, 0x00000618, 0x0000025C, 0x00000834, 0x00000318, 0x000007D0, 0x00000C48, 0x00000078, 0x00000200, 0x00000C84, 0x00000628, 0x00000400, 0x00007AD0, 0x000078B0, 0x00034AD0, 0x0000E058, 0x00000200 };
                skips = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000004, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000000, 0x00000004, 0x00000004 };
                magics = new uint[] { 0x005E0BB8, 0x005E09C4, 0x005E0904, 0x005E0AA4, 0x005E0BF8, 0x005E05CC, 0x005E0B04, 0x005E0A44, 0x005E0AC4, 0x005E05AC, 0x005E064C, 0x005E0944, 0x005E0924, 0x005E0B78, 0x005E0884, 0x005E0884, 0x005E0884, 0x005E0AE4, 0x005E068C, 0x005DF40C, 0x005E0C18, 0x005E072C, 0x005E05EC, 0x005E0964, 0x005E06AC, 0x005E06EC, 0x005E062C, 0x005E0BD8, 0x005E0A64, 0x005E0B98, 0x005E07CC, 0x005E0A24, 0x005E058C, 0x005E04EC, 0x005E056C, 0x005E082C, 0x005E0984, 0x005E070C, 0x005E0B58, 0x005E054C, 0x005E050C, 0x005E080C, 0x005E076C, 0x005E07AC, 0x005E09E4, 0x005E08A4, 0x005E078C, 0x005E074C, 0x005E060C, 0x005E06CC, UNKNOWNVAL, 0x005E0864, 0x005E07EC, 0x005E0A04, 0x005E052C, 0x005E08C4, 0x005E04CC, 0x005E066C, 0x005E09A4 };
                instances = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 };
            }
            else
            {
                offsets = new uint[] { 0x00005400, 0x00005800, 0x00006400, 0x00006600, 0x00006800, 0x00006A00, 0x00006C00, 0x00006E00, 0x00007000, 0x00007200, 0x00007400, 0x00009600, 0x00009800, 0x00009E00, 0x0000A400, 0x0000F400, 0x00014400, 0x00019400, 0x00019600, 0x00019E00, 0x0001A400, 0x0001AC00, 0x0001B400, 0x0001B600, 0x0001B800, 0x0001BE00, 0x0001C000, 0x0001C400, 0x0001CC00, 0x0001CE00, 0x0001D000, 0x0001D200, 0x0001D400, 0x0001D600, 0x0001DE00, 0x0001E400, 0x0001E800, 0x00020400, 0x00020600, 0x00020800, 0x00020C00, 0x00021000, 0x00022C00, 0x00023000, 0x00023800, 0x00023C00, 0x00024600, 0x00024A00, 0x00025200, 0x00026000, 0x00026200, 0x00026400, 0x00027200, 0x00027A00, 0x0005C600, 0x0006A800 };
                lens = new uint[] { 0x000002C8, 0x00000B88, 0x0000002C, 0x00000038, 0x00000150, 0x00000004, 0x00000008, 0x000001C0, 0x000000BE, 0x00000024, 0x00002100, 0x00000140, 0x00000440, 0x00000574, 0x00004E28, 0x00004E28, 0x00004E28, 0x00000170, 0x0000061C, 0x00000504, 0x000006A0, 0x00000644, 0x00000104, 0x00000004, 0x00000420, 0x00000064, 0x000003F0, 0x0000070C, 0x00000180, 0x00000004, 0x0000000C, 0x00000048, 0x00000054, 0x00000644, 0x000005C8, 0x000002F8, 0x00001B40, 0x000001F4, 0x000001F0, 0x00000216, 0x00000390, 0x00001A90, 0x00000308, 0x00000618, 0x0000025C, 0x00000834, 0x00000318, 0x000007D0, 0x00000C48, 0x00000078, 0x00000200, 0x00000C84, 0x00000628, 0x00034AD0, 0x0000E058, 0x00000200 };
                skips = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000004, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000004 };
                magics = new uint[] { 0x0059AE94, 0x0059ACC0, 0x0059AC00, 0x0059AD80, 0x0059AED4, 0x0059A8E8, 0x0059ADE0, 0x0059AD20, 0x0059ADA0, 0x0059A8C8, 0x0059A968, 0x0059AC40, 0x0059AC20, 0x0059AE54, 0x0059ABA0, 0x0059ABA0, 0x0059ABA0, 0x0059ADC0, 0x0059A9A8, 0x00599734, 0x0059AEF4, 0x0059AA48, 0x0059A908, 0x0059AC60, 0x0059A9C8, 0x0059AA08, 0x0059A948, 0x0059AEB4, 0x0059AD40, 0x0059AE74, 0x0059AAE8, 0x0059AD00, 0x0059A8A8, 0x0059A800, 0x0059A888, 0x0059AB70, 0x0059AC80, 0x0059AA28, 0x0059AE34, 0x0059A868, 0x0059A820, 0x0059AB28, 0x0059AA88, 0x0059AAC8, 0x0059ACE0, 0x0059ABC0, 0x0059AAA8, 0x0059AA68, 0x0059A928, 0x0059A9E8, 0x0059AD60, 0x0059AB80, 0x0059AB08, 0x0059A7E0, 0x0059A988, 0x0059ACA0 };
                instances = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 };
                switch (val)
                {
                    case 0x0059E418:
                        magics = new uint[] { 0x0059E418, 0x0059E244, 0x0059E184, 0x0059E304, 0x0059E458, 0x0059DE6C, 0x0059E364, 0x0059E2A4, 0x0059E324, 0x0059DE4C, 0x0059DEEC, 0x0059E1C4, 0x0059E1A4, 0x0059E3D8, 0x0059E124, 0x0059E124, 0x0059E124, 0x0059E344, 0x0059DF2C, 0x0059CCB8, 0x0059E478, 0x0059DFCC, 0x0059DE8C, 0x0059E1E4, 0x0059DF4C, 0x0059DF8C, 0x0059DECC, 0x0059E438, 0x0059E2C4, 0x0059E3F8, 0x0059E06C, 0x0059E284, 0x0059DE2C, 0x0059DD84, 0x0059DE0C, 0x0059E0CC, 0x0059E204, 0x0059DFAC, 0x0059E3B8, 0x0059DDEC, 0x0059DDA4, 0x0059E0AC, 0x0059E00C, 0x0059E04C, 0x0059E264, 0x0059E144, 0x0059E02C, 0x0059DFEC, 0x0059DEAC, 0x0059DF6C, 0x0059E2E4, 0x0059E104, 0x0059E08C, 0x0059DD64, 0x0059DF0C, 0x0059E224 };
                        break;
                    case 0x0059E408:
                        magics = new uint[] { 0x0059E408, 0x0059E234, 0x0059E174, 0x0059E2F4, 0x0059E448, 0x0059DE5C, 0x0059E354, 0x0059E294, 0x0059E314, 0x0059DE3C, 0x0059DEDC, 0x0059E1B4, 0x0059E194, 0x0059E3C8, 0x0059E114, 0x0059E114, 0x0059E114, 0x0059E334, 0x0059DF1C, 0x0059CCA8, 0x0059E468, 0x0059DFBC, 0x0059DE7C, 0x0059E1D4, 0x0059DF3C, 0x0059DF7C, 0x0059DEBC, 0x0059E428, 0x0059E2B4, 0x0059E3E8, 0x0059E05C, 0x0059E274, 0x0059DE1C, 0x0059DD74, 0x0059DDFC, 0x0059E0BC, 0x0059E1F4, 0x0059DF9C, 0x0059E3A8, 0x0059DDDC, 0x0059DD94, 0x0059E09C, 0x0059DFFC, 0x0059E03C, 0x0059E254, 0x0059E134, 0x0059E01C, 0x0059DFDC, 0x0059DE9C, 0x0059DF5C, 0x0059E2D4, 0x0059E0F4, 0x0059E07C, 0x0059DD54, 0x0059DEFC, 0x0059E214 };
                        break;
                    case 0x0059BEC4:
                        magics = new uint[] { 0x0059BEC4, 0x0059BCF0, 0x0059BC30, 0x0059BDB0, 0x0059BF04, 0x0059B918, 0x0059BE10, 0x0059BD50, 0x0059BDD0, 0x0059B8F8, 0x0059B998, 0x0059BC70, 0x0059BC50, 0x0059BE84, 0x0059BBD0, 0x0059BBD0, 0x0059BBD0, 0x0059BDF0, 0x0059B9D8, 0x0059A764, 0x0059BF24, 0x0059BA78, 0x0059B938, 0x0059BC90, 0x0059B9F8, 0x0059BA38, 0x0059B978, 0x0059BEE4, 0x0059BD70, 0x0059BEA4, 0x0059BB18, 0x0059BD30, 0x0059B8D8, 0x0059B830, 0x0059B8B8, 0x0059BBA0, 0x0059BCB0, 0x0059BA58, 0x0059BE64, 0x0059B898, 0x0059B850, 0x0059BB58, 0x0059BAB8, 0x0059BAF8, 0x0059BD10, 0x0059BBF0, 0x0059BAD8, 0x0059BA98, 0x0059B958, 0x0059BA18, 0x0059BD90, 0x0059BBB0, 0x0059BB38, 0x0059B810, 0x0059B9B8, 0x0059BCD0 };
                        break;
                }
            }
            using (MemoryStream ms = new MemoryStream())
            {
                for (int i = 0; i < lens.Length; i++)
                {
                    int ofs = FindIndex(ramsav, magics[i], instances[i], spos);
                    ms.Seek(offsets[i] - 0x5400, SeekOrigin.Begin);
                    spos += lens[i];
                    if (ofs > 0)
                    {
                        new MemoryStream(ramsav.Skip(ofs + (int)skips[i]).Take((int)lens[i]).ToArray()).CopyTo(ms);
                        spos += 4;
                    }
                    else
                        new MemoryStream(new byte[(int)lens[i]]).CopyTo(ms);
                }
                if (ms.Length % 0x200 != 0)
                    new MemoryStream(new byte[0x200 - ms.Length % 0x200]).CopyTo(ms); // Pad out to 0x200

                main = ms.ToArray();
            }
            return main;
        }
开发者ID:deathsh3admoth,项目名称:Mass-Editor,代码行数:60,代码来源:ram2sav.cs

示例9: SaveAsync

        /// <summary>
        /// Save the current <see cref="SessionState"/>.  Any <see cref="Frame"/> instances
        /// registered with <see cref="RegisterFrame"/> will also preserve their current
        /// navigation stack, which in turn gives their active <see cref="Page"/> an opportunity
        /// to save its state.
        /// </summary>
        /// <returns>An asynchronous task that reflects when session state has been saved.</returns>
        public static async Task SaveAsync()
        {
            try
            {
                // Save the navigation state for all registered frames
                foreach (var weakFrameReference in _registeredFrames)
                {
                    Frame frame;
                    if (weakFrameReference.TryGetTarget(out frame))
                    {
                        SaveFrameNavigationState(frame);
                    }
                }

                // Serialize the session state synchronously to avoid asynchronous access to shared
                // state
                MemoryStream sessionData = new MemoryStream();
                DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<string, object>), _knownTypes);
                serializer.WriteObject(sessionData, _sessionState);

                // Get an output stream for the SessionState file and write the state asynchronously
                StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(sessionStateFilename, CreationCollisionOption.ReplaceExisting);
                using (Stream fileStream = await file.OpenStreamForWriteAsync())
                {
                    sessionData.Seek(0, SeekOrigin.Begin);
                    await sessionData.CopyToAsync(fileStream);
                }
            }
            catch (Exception e)
            {
                throw new SuspensionManagerException(e);
            }
        }
开发者ID:TREEDWELLER,项目名称:qtree-samples,代码行数:40,代码来源:SuspensionManager.cs

示例10: Read

 public Dictionary<string, object> Read(byte [] data, string rsaPrivKey, Dictionary<string, Type> objTypeMap, Func<byte[], byte[]> xmlFilter = null)
 {
     using (var ms = new MemoryStream(data))
     {
         return DecryptFileList(Util.Compression.UnZip(ms), rsaPrivKey, objTypeMap, xmlFilter);
     }
 }
开发者ID:danni95,项目名称:Core,代码行数:7,代码来源:EncryptedFileConfigProvider.cs

示例11: decodeBinary

 public static byte[] decodeBinary(Bitmap bmp)
 {
     byte[] bytes = null;
     try
     {
         int wSize = bmp.Width, hSize = bmp.Height;
         MemoryStream stream = new MemoryStream();
         for (int w = 0; w < wSize; w++)
         {
             for (int h = 0; h < hSize; h++)
             {
                 Color color = bmp.GetPixel(w, h);
                 if (color.R == 0 && color.G == 0 && color.B == 0) stream.WriteByte(color.A);
                 else break;
             }
         }
         bytes = stream.ToArray();
         stream = null;
     }
     catch (Exception e)
     {
         bytes = null;
     }
     return bytes;
 }
开发者ID:JhetoX,项目名称:PNGEncryption,代码行数:25,代码来源:Program.cs

示例12: UploadDB

        async Task<bool> UploadDB()
        {
            try
            {
            ServiceReference1.IService1 s = new ServiceReference1.Service1Client();
            Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync("SQLITEV2.sqlite");

            byte[] result;
            using (Stream stream = await sampleFile.OpenStreamForReadAsync())
            {
                using (var memoryStream = new MemoryStream())
                {
                    stream.CopyTo(memoryStream);
                    result = memoryStream.ToArray();
                }
            }

            await s.UploadFileAsync(result);

                return true;
            }
            catch (Exception)
            {
                return false;
                throw;
            }


        }
开发者ID:IIIArbiIII,项目名称:MedicineApp,代码行数:30,代码来源:App.xaml.cs

示例13: TestIncompleteRewind

 public void TestIncompleteRewind()
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms);
     bw.Write(1);
     bw.Write(2);
     bw.Write(3);
     bw.Write(4);
     bw.Write(5);
     bw.Write(6);
     bw.Write(7);
     bw.Flush();
     ms.Position = 0;
     RewindableStream stream = new RewindableStream(ms);
     stream.StartRecording();
     BinaryReader br = new BinaryReader(stream);
     Assert.AreEqual(br.ReadInt32(), 1);
     Assert.AreEqual(br.ReadInt32(), 2);
     Assert.AreEqual(br.ReadInt32(), 3);
     Assert.AreEqual(br.ReadInt32(), 4);
     stream.Rewind(true);
     Assert.AreEqual(br.ReadInt32(), 1);
     Assert.AreEqual(br.ReadInt32(), 2);
     stream.StartRecording();
     Assert.AreEqual(br.ReadInt32(), 3);
     Assert.AreEqual(br.ReadInt32(), 4);
     Assert.AreEqual(br.ReadInt32(), 5);
     stream.Rewind(true);
     Assert.AreEqual(br.ReadInt32(), 3);
     Assert.AreEqual(br.ReadInt32(), 4);
     Assert.AreEqual(br.ReadInt32(), 5);
     Assert.AreEqual(br.ReadInt32(), 6);
     Assert.AreEqual(br.ReadInt32(), 7);
 }
开发者ID:yaozd,项目名称:sharpcompress,代码行数:34,代码来源:RewindableStreamTest.cs

示例14: byteArrayToImage

 public Image<Gray, byte> byteArrayToImage(byte[] byteArrayIn)
 {
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image i = Image.FromStream(ms);
     Bitmap b = new Bitmap(i);
     return new Image<Gray, byte>(b);
 }
开发者ID:forkbomb,项目名称:pikto,代码行数:7,代码来源:PiktoViewDB.cs

示例15: CropImageFile

        private byte[] CropImageFile(Image imageFile, int targetW, int targetH, int targetX, int targetY)
        {
            var imgMemoryStream = new MemoryStream();
            Image imgPhoto = imageFile;

            var bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);
            bmPhoto.SetResolution(72, 72);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            try
            {
                grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH),
                                    targetX, targetY, targetW, targetH, GraphicsUnit.Pixel);
                bmPhoto.Save(imgMemoryStream, ImageFormat.Jpeg);
            }

            catch (Exception e)
            {
                throw e;
            }

            return imgMemoryStream.GetBuffer();
        }
开发者ID:kvkirthy,项目名称:Flock,代码行数:27,代码来源:ImageFacade.cs


注:本文中的System.IO.MemoryStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。