Add() public method

public Add ( int id, string value ) : System.Xml.XmlDictionaryString
id int
value string
return System.Xml.XmlDictionaryString
		public void ReadMessage ()
		{
			using (var ms = File.OpenRead ("Test/System.ServiceModel.Channels/binary-message.raw")) {

				var session = new XmlBinaryReaderSession ();
				byte [] rsbuf = new BinaryFrameSupportReader (ms).ReadSizedChunk ();
				int count = 0;
				using (var rms = new MemoryStream (rsbuf, 0, rsbuf.Length)) {
					var rbr = new BinaryReader (rms, Encoding.UTF8);
					while (rms.Position < rms.Length)
						session.Add (count++, rbr.ReadString ());
				}
				var xr = XmlDictionaryReader.CreateBinaryReader (ms, BinaryFrameSupportReader.soap_dictionary, new XmlDictionaryReaderQuotas (), session);

				string soapNS = "http://www.w3.org/2003/05/soap-envelope";
				string addrNS = "http://www.w3.org/2005/08/addressing";
				string xmlnsNS = "http://www.w3.org/2000/xmlns/";
				string peerNS = "http://schemas.microsoft.com/net/2006/05/peer";

				xr.MoveToContent ();
				AssertNode (xr, 0, XmlNodeType.Element, "s", "Envelope", soapNS, String.Empty, "#1");
				Assert.AreEqual (2, xr.AttributeCount, "#1-1-1");
				Assert.IsTrue (xr.MoveToAttribute ("s", xmlnsNS), "#1-2");
				AssertNode (xr, 1, XmlNodeType.Attribute, "xmlns", "s", xmlnsNS, soapNS, "#2");
				Assert.IsTrue (xr.MoveToAttribute ("a", xmlnsNS), "#2-2");
				AssertNode (xr, 1, XmlNodeType.Attribute, "xmlns", "a", xmlnsNS, addrNS, "#3");
				Assert.IsTrue (xr.Read (), "#3-2");
				AssertNode (xr, 1, XmlNodeType.Element, "s", "Header", soapNS, String.Empty, "#4");
				Assert.IsTrue (xr.Read (), "#4-2");
				AssertNode (xr, 2, XmlNodeType.Element, "a", "Action", addrNS, String.Empty, "#5");
				Assert.IsTrue (xr.MoveToAttribute ("mustUnderstand", soapNS), "#5-2");
				AssertNode (xr, 3, XmlNodeType.Attribute, "s", "mustUnderstand", soapNS, "1", "#6");
				Assert.IsTrue (xr.Read (), "#6-2");
				AssertNode (xr, 3, XmlNodeType.Text, "", "", "", "http://schemas.microsoft.com/net/2006/05/peer/resolver/Resolve", "#7");
				Assert.IsTrue (xr.Read (), "#7-2");
				AssertNode (xr, 2, XmlNodeType.EndElement, "a", "Action", addrNS, String.Empty, "#8");
				Assert.IsTrue (xr.Read (), "#8-2");
				AssertNode (xr, 2, XmlNodeType.Element, "a", "MessageID", addrNS, String.Empty, "#9");
				Assert.IsTrue (xr.Read (), "#9-2");
				Assert.AreEqual (XmlNodeType.Text, xr.NodeType, "#10");
				Assert.IsTrue (xr.Read (), "#10-2");
				AssertNode (xr, 2, XmlNodeType.EndElement, "a", "MessageID", addrNS, String.Empty, "#11");
				Assert.IsTrue (xr.Read (), "#11-2"); // -> a:ReplyTo
				AssertNode (xr, 2, XmlNodeType.Element, "a", "ReplyTo", addrNS, String.Empty, "#12");
				xr.Skip (); // -> a:To
				AssertNode (xr, 2, XmlNodeType.Element, "a", "To", addrNS, String.Empty, "#13");
				xr.Skip (); // -> /s:Header
				AssertNode (xr, 1, XmlNodeType.EndElement, "s", "Header", soapNS, String.Empty, "#14");

				Assert.IsTrue (xr.Read (), "#14-2");
				AssertNode (xr, 1, XmlNodeType.Element, "s", "Body", soapNS, String.Empty, "#15");
				Assert.IsTrue (xr.Read (), "#15-2");
				AssertNode (xr, 2, XmlNodeType.Element, "", "Resolve", peerNS, String.Empty, "#16");
				Assert.IsTrue (xr.MoveToAttribute ("xmlns"), "#16-2");
				AssertNode (xr, 3, XmlNodeType.Attribute, "", "xmlns", xmlnsNS, peerNS, "#17");
				Assert.IsTrue (xr.Read (), "#17-2");
				AssertNode (xr, 3, XmlNodeType.Element, "", "ClientId", peerNS, String.Empty, "#18");
/*
				while (!xr.EOF) {
					xr.Read ();
					Console.WriteLine ("{0}: {1}:{2} {3} {4}", xr.NodeType, xr.Prefix, xr.LocalName, xr.NamespaceURI, xr.Value);
					for (int i = 0; i < xr.AttributeCount; i++) {
						xr.MoveToAttribute (i);
						Console.WriteLine ("  Attribute: {0}:{1} {2} {3}", xr.Prefix, xr.LocalName, xr.NamespaceURI, xr.Value);
					}
				}
*/
			}
		}
Ejemplo n.º 2
0
        private static bool TryParseArgs(string[] args, out string binaryFileName, out IXmlDictionary xmlDictionary, out XmlBinaryReaderSession readerSession)
        {
            binaryFileName = null;
            xmlDictionary = null;
            readerSession = null;
            bool useDictionaries = true;
            string staticDictionaryFile = null;
            string dynamicDictionaryFile = null;
            int offset = 0;
            while (offset < args.Length)
            {
                if (args[offset] == "-static")
                {
                    if (offset + 1 >= args.Length)
                    {
                        return false;
                    }

                    staticDictionaryFile = args[offset + 1];
                    offset += 2;
                }
                if (args[offset] == "-session")
                {
                    if (offset + 1 >= args.Length)
                    {
                        return false;
                    }

                    dynamicDictionaryFile = args[offset + 1];
                    offset += 2;
                }
                else if (args[offset] == "-noDict")
                {
                    offset++;
                    useDictionaries = false;
                }
                else
                {
                    binaryFileName = args[offset];
                    offset++;
                    if (offset != args.Length)
                    {
                        return false;
                    }
                }
            }

            if (useDictionaries)
            {
                if (staticDictionaryFile == null)
                {
                    xmlDictionary = WcfDictionary.GetStaticDictionary();
                }
                else
                {
                    XmlDictionary temp = new XmlDictionary();
                    xmlDictionary = temp;
                    foreach (string entry in File.ReadAllLines(staticDictionaryFile))
                    {
                        temp.Add(entry);
                    }
                }

                readerSession = new XmlBinaryReaderSession();
                if (dynamicDictionaryFile == null)
                {
                    for (int i = 0; i < 200; i++)
                    {
                        readerSession.Add(i, "session_" + i);
                    }
                }
                else
                {
                    string[] lines = File.ReadAllLines(dynamicDictionaryFile);
                    for (int i = 0; i < lines.Length; i++)
                    {
                        readerSession.Add(i, lines[i]);
                    }
                }
            }
            else
            {
                readerSession = null;
                xmlDictionary = null;
            }

            return true;
        }
		public void Beyond128DictionaryEntries ()
		{
			XmlDictionaryString ds;
			MemoryStream ms = new MemoryStream ();
			XmlDictionary dic = new XmlDictionary ();
			for (int i = 0; i < 260; i++)
				Assert.AreEqual (i, dic.Add ("n" + i).Key, "dic");
			XmlDictionary dic2 = new XmlDictionary ();
			XmlBinaryReaderSession session = new XmlBinaryReaderSession ();
			int idx;
			for (int i = 0; i < 260; i++)
				Assert.AreEqual (i, session.Add (i, "s" + i).Key, "session");

			byte [] bytes = new byte [] {
				// so, when it went beyond 128, the index
				// becomes 2 bytes, where
				// - the first byte always becomes > 80, and
				// - the second byte becomes (n / 0x80) * 2.
				0x42, 0x80, 2, 0x0A, 0x82, 2,
				0x42, 0x85, 2, 0x0A, 0x87, 2,
				0x42, 0x88, 2, 0x0A, 0x8B, 2,
				0x42, 0x80, 4, 0x0A, 0x81, 4,
				1, 1, 1, 1};

			XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas (), session);
			Assert.IsTrue (reader.Read (), "#r1");
			Assert.AreEqual ("n128", reader.LocalName, "#l1");
			Assert.IsTrue (reader.Read (), "#r2");
			Assert.AreEqual ("s130", reader.LocalName, "#l1");
			Assert.IsTrue (reader.Read (), "#r3");
			Assert.AreEqual ("n132", reader.LocalName, "#l1");
			Assert.IsTrue (reader.Read (), "#r4");
			Assert.AreEqual ("n256", reader.LocalName, "#l1");
			for (int i = 0; i < 4; i++) {
				Assert.IsTrue (reader.Read (), "#re" + i);
				Assert.AreEqual (XmlNodeType.EndElement, reader.NodeType, "#ne" + i);
			}
			Assert.IsFalse (reader.Read ()); // EOF
		}
Ejemplo n.º 4
0
		public void AttributeWithSessionQNameIndex ()
		{
			XmlDictionaryString ds;
			XmlDictionary dic = new XmlDictionary ();
			XmlBinaryReaderSession ses = new XmlBinaryReaderSession();
			ses.Add(0, "SessionLookupValue");
			
			// <d a="QNameIndex(0x18,1)"></d>
			byte [] bytes = new byte [] { 0x40, 0x01, 0x64, 0x04, 0x01, 0x61, 0xbc, 0x18, 0x01, 0x01 };

			XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader (
							new MemoryStream (bytes), dic, new XmlDictionaryReaderQuotas (), ses);
			Assert.IsTrue (reader.Read (), "#1");
			AssertNode (XmlNodeType.Element, "d", "", "", 0, reader, "#2");
			reader.MoveToAttribute (0);
			if (reader.LocalName != "a")
				reader.MoveToAttribute (1);
			AssertNode (XmlNodeType.Attribute, "a", "", "y:SessionLookupValue", 1, reader, "#3");
			Assert.IsTrue (reader.ReadAttributeValue (), "#4");
			AssertNode (XmlNodeType.Text, "a", "", "y:SessionLookupValue", 2, reader, "#5");
			reader.MoveToContent ();
			Assert.IsFalse (reader.ReadAttributeValue (), "#6");
		}