Ejemplo n.º 1
0
 /// <summary>
 /// 和服务器建立链接
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 public void Connect(string ip, int port)
 {
     myReceiveBuffer = new MyMemoryStream();
     socket          = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     this.socket.BeginConnect(ip, port, connectCallback, null);
     Debug.Log("不阻塞");
 }
Ejemplo n.º 2
0
        [Test]         // https://bugzilla.novell.com/show_bug.cgi?id=322672
        public void BaseDisposeCalled()
        {
            MyMemoryStream ms = new MyMemoryStream();

            Assert.IsFalse(ms.DisposedCalled, "Before");
            ms.Close();
            Assert.IsTrue(ms.DisposedCalled, "After");
        }
Ejemplo n.º 3
0
        public async Task TestIssue321_AsyncBuffering()
        {
            var context    = new SerializationContext();
            var serializer = context.GetSerializer <string>();

            using (var stream = new MyMemoryStream())
            {
                await serializer.PackAsync(stream, "hello");

                await serializer.PackAsync(stream, "world");

                stream.Position = 0;
                var result1 = await serializer.UnpackAsync(stream);

                // Ensure no exceptions are thrown.
                var result2 = await serializer.UnpackAsync(stream);
            }
        }
Ejemplo n.º 4
0
 internal static void DoPreview(DocumentPaginator fd, Window owner, string title)
 {
     //FlowDocumentScrollViewer visual = (FlowDocumentScrollViewer)(_parent.FindName("fdsv1"));
     var ms = new MyMemoryStream();
     using (var pkg = System.IO.Packaging.Package.Open(ms, FileMode.Create))
     {
         using (XpsDocument doc = new XpsDocument(pkg))
         {
             XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
             writer.Write(fd);
         }
     }
     //ms.ToArray()
     ms.Position = 0;
     var pkg2 = System.IO.Packaging.Package.Open(ms);
     // Read the XPS document into a dynamically generated
     // preview Window 
     var url = new Uri("memorystream://printstream");
     PackageStore.AddPackage(url, pkg2);
     try
     {
         using (XpsDocument doc = new XpsDocument(pkg2, CompressionOption.SuperFast, url.AbsoluteUri))
         {
             FixedDocumentSequence fds = doc.GetFixedDocumentSequence();
             string s = _previewWindowXaml;
             s = s.Replace("@@TITLE", title.Replace("'", "&apos;"));
             using (var reader = new System.Xml.XmlTextReader(new StringReader(s)))
             {
                 Window preview = System.Windows.Markup.XamlReader.Load(reader) as Window;
                 DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(preview, "dv1") as DocumentViewer;
                 dv1.Document = fds as IDocumentPaginatorSource;
                 preview.Owner = owner;
                 preview.ShowDialog();
             }
         }
     }
     finally
     {
         PackageStore.RemovePackage(url);
     }
 }
Ejemplo n.º 5
0
    /// <summary>
    /// 封装数据包。
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    private byte[] makeData(byte[] data)
    {
        bool isCompress = false;

        if (data.Length > 200)
        {
            isCompress = true;
            data       = ZlibHelper.CompressBytes(data);
        }
        data = SecurityUtil.Xor(data);               //加密
        ushort crc     = Crc16.CalculateCrc16(data); //校验码。
        ushort bodyLen = (ushort)(data.Length + 3);  //包体长度

        MyMemoryStream m = new MyMemoryStream();

        m.WriteUShort(bodyLen);
        m.WriteBool(isCompress);
        m.WriteUShort(crc);
        m.Write(data, 0, data.Length);
        data = m.ToArray();
        m.Close();

        return(data);
    }
Ejemplo n.º 6
0
        public static byte[] m00000b(byte[] argBuffer)
        {
            //检查执行程序集是否与调用程序集相同,不同则退出
            Assembly callingAssembly = Assembly.GetCallingAssembly();
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            if ((callingAssembly != executingAssembly) && !IsAssemblyEqual(executingAssembly, callingAssembly))
            {
                return null;
            }

            MyMemoryStream myStream = new MyMemoryStream(argBuffer);
            byte[] buffer = new byte[0];
            int num = myStream.ReadFullByte();

            //如果以这个序列开头
            if (num == 0x4034b50)
            {
                short num2 = (short) myStream.ReadLowByte();
                int num3 = myStream.ReadLowByte();
                int num4 = myStream.ReadLowByte();
                if (((num != 0x4034b50) || (num2 != 20)) || ((num3 != 0) || (num4 != 8)))
                {
                    throw new FormatException("Wrong Header Signature");
                }
                myStream.ReadFullByte();
                myStream.ReadFullByte();
                myStream.ReadFullByte();
                int num5 = myStream.ReadFullByte();
                int count = myStream.ReadLowByte();
                int num7 = myStream.ReadLowByte();
                if (count > 0)
                {
                    byte[] buffer2 = new byte[count];
                    myStream.Read(buffer2, 0, count);
                }
                if (num7 > 0)
                {
                    byte[] buffer3 = new byte[num7];
                    myStream.Read(buffer3, 0, num7);
                }
                byte[] buffer4 = new byte[(uint) (myStream.Length - myStream.Position)];
                myStream.Read(buffer4, 0, buffer4.Length);

                c00000e ce = new c00000e(buffer4);
                buffer = new byte[num5];
                ce.m00000d(buffer, 0, buffer.Length);
                buffer4 = null;
            }
            else
            {
                int num8 = num >> 0x18;
                num -= num8 << 0x18;

                //如果以这个序列开头
                if (num == 0x7d7a7b)
                {
                    switch (num8)
                    {
                        case 1:
                        {
                            int num12;
                            int num9 = myStream.ReadFullByte();
                            buffer = new byte[num9];
                            for (int i = 0; i < num9; i += num12)
                            {
                                int num11 = myStream.ReadFullByte();
                                num12 = myStream.ReadFullByte();
                                byte[] buffer5 = new byte[num11];
                                myStream.Read(buffer5, 0, buffer5.Length);
                                new c00000e(buffer5).m00000d(buffer, i, num12);
                            }
                            break;
                        }
                        case 2:
                        {
                            byte[] buffer6 = new byte[] { 0x69, 140, 0x88, 0xa1, 0x68, 0xb9, 0xe3, 0xd3 };
                            byte[] buffer7 = new byte[] { 0x7d, 0xb0, 0xa8, 0x17, 0xda, 0x54, 0xc5, 0x3e };
                            using (DESCryptoHelper cc = new DESCryptoHelper())
                            {
                                using (ICryptoTransform transform = cc.m000009(buffer6, buffer7, true))
                                {
                                    buffer = m00000b(transform.TransformFinalBlock(argBuffer, 4, argBuffer.Length - 4));
                                }
                            }
                            break;
                        }
                    }
                    if (num8 != 3)
                    {
                        goto Label_02E3;
                    }
                    byte[] buffer9 = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
                    byte[] buffer10 = new byte[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
                    using (RijndaelCryptHelper cb = new RijndaelCryptHelper())
                    {
                        using (ICryptoTransform transform2 = cb.CreateCryptor(buffer9, buffer10, true))
                        {
                            buffer = m00000b(transform2.TransformFinalBlock(argBuffer, 4, argBuffer.Length - 4));
                        }
                        goto Label_02E3;
                    }
                }
                throw new FormatException("Unknown Header");
            }
            Label_02E3:
            myStream.Close();
            myStream = null;
            return buffer;
        }
Ejemplo n.º 7
0
		[Test] // https://bugzilla.novell.com/show_bug.cgi?id=322672
		public void BaseDisposeCalled ()
		{
			MyMemoryStream ms = new MyMemoryStream ();
			Assert.IsFalse (ms.DisposedCalled, "Before");
			ms.Close ();
			Assert.IsTrue (ms.DisposedCalled, "After");
		}