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");
        }
        public void AttributeWithLocalDictQNameIndex()
        {
            XmlDictionary dic = new XmlDictionary();

            dic.Add("xmlns");
            dic.Add("http://www.w3.org/2000/xmlns/");
            dic.Add("DictionaryValue");
            dic.Add("SomeDictionaryString");
            dic.Add("AdditionalDictionaryString");

            // <d a="QNameIndex(0,8)"></d>
            byte [] bytes = new byte [] { 0x40, 0x01, 0x64, 0x04, 0x01, 0x61, 0xbc, 0x00, 0x08, 0x01 };

            XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(
                new MemoryStream(bytes), dic, new XmlDictionaryReaderQuotas());

            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", "", "a:AdditionalDictionaryString", 1, reader, "#3");
            Assert.IsTrue(reader.ReadAttributeValue(), "#4");
            AssertNode(XmlNodeType.Text, "a", "", "a:AdditionalDictionaryString", 2, reader, "#5");
            Assert.IsFalse(reader.ReadAttributeValue(), "#6");
        }
        public void AttributeXmlns()
        {
            // equivalent to WriteXmlnsAttribute()
            XmlDictionaryString ds;
            XmlDictionary       dic = new XmlDictionary();

            dic.Add("xmlns");
            dic.Add("http://www.w3.org/2000/xmlns/");

            byte [] bytes = new byte [] {
                // 40 (root) 04 (a) A8
                // 09 (foo) (urn:foo) 08 (urn:bar)
                0x40, 4, 0x72, 0x6F, 0x6F, 0x74,
                0x04, 1, 0x61, 0xA8,
                0x09, 3, 0x66, 0x6F, 0x6F, 7, 0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F,
                0x08, 7, 0x75, 0x72, 0x6E, 0x3A, 0x62, 0x61, 0x72, 1
            };

            Read(bytes);

            XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(new MemoryStream(bytes), new XmlDictionaryReaderQuotas());

            Assert.IsTrue(reader.Read(), "#1-1");
            AssertNode(XmlNodeType.Element, "root", "urn:bar", "", 0, reader, "#1");
            reader.MoveToAttribute(0);
            if (reader.LocalName != "a")
            {
                reader.MoveToAttribute(1);
            }
            AssertNode(XmlNodeType.Attribute, "a", "", "", 1, reader, "#2");
            Assert.IsTrue(reader.ReadAttributeValue(), "#3");
            AssertNode(XmlNodeType.Text, "a", "", "", 2, reader, "#4");
            Assert.IsFalse(reader.ReadAttributeValue(), "#5");
        }
Example #4
0
        public void ReadObjectRuntimeTypeAsAttribute()
        {
            XmlDictionaryReader r = CreateReader("{\"__type\":\"System.Int32\"}");

            r.Read();
            AssertNode(0, "root", XmlNodeType.Element, String.Empty, "object", r, "#1");
            Assert.IsTrue(r.MoveToAttribute("type"), "#2");
            AssertNode(0, "type", XmlNodeType.Attribute, "object", "object", r, "#3");
            Assert.IsTrue(r.MoveToAttribute("__type"), "#4");
            AssertNode(0, "__type", XmlNodeType.Attribute, "System.Int32", "object", r, "#5");
            r.Read();
            Assert.AreEqual(XmlNodeType.EndElement, r.NodeType, "#6");
        }
Example #5
0
        void ReadBodyStart()
        {
            // read headers in advance.
            if (headers == null)
            {
                ReadHeaders();
            }

            // SOAP Body
            body_started = true;
            is_empty     = reader.IsEmptyElement;
            if (reader.MoveToAttribute("Id", Constants.WsuNamespace))
            {
                BodyId = reader.Value;
                reader.MoveToElement();
            }
            reader.ReadStartElement("Body", Version.Envelope.Namespace);
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                is_empty = true;
                reader.Read();
            }
            else
            {
                reader.MoveToContent();
                if (reader.NodeType == XmlNodeType.Element &&
                    reader.LocalName == "Fault" &&
                    reader.NamespaceURI == Version.Envelope.Namespace)
                {
                    is_fault = true;
                }
            }
        }
 public static bool WasHeaderNotUnderstood(MessageHeaders headers, string name, string ns)
 {
     if (headers == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("headers");
     }
     for (int i = 0; i < headers.Count; i++)
     {
         MessageHeaderInfo info = headers[i];
         if ((string.Compare(info.Name, "NotUnderstood", StringComparison.Ordinal) == 0) && (string.Compare(info.Namespace, "http://www.w3.org/2003/05/soap-envelope", StringComparison.Ordinal) == 0))
         {
             using (XmlDictionaryReader reader = headers.GetReaderAtHeader(i))
             {
                 string str;
                 string str2;
                 reader.MoveToAttribute("qname", "http://www.w3.org/2003/05/soap-envelope");
                 reader.ReadContentAsQualifiedName(out str, out str2);
                 if (((str != null) && (str2 != null)) && ((string.Compare(name, str, StringComparison.Ordinal) == 0) && (string.Compare(ns, str2, StringComparison.Ordinal) == 0)))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Example #7
0
        public static bool WasHeaderNotUnderstood(MessageHeaders headers, string name, string ns)
        {
            if (headers == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(headers));
            }

            for (int i = 0; i < headers.Count; i++)
            {
                MessageHeaderInfo headerInfo = headers[i];
                if ((String.Compare(headerInfo.Name, Message12Strings.NotUnderstood, StringComparison.Ordinal) == 0) &&
                    (String.Compare(headerInfo.Namespace, Message12Strings.Namespace, StringComparison.Ordinal) == 0))
                {
                    using (XmlDictionaryReader reader = headers.GetReaderAtHeader(i))
                    {
                        reader.MoveToAttribute(Message12Strings.QName, Message12Strings.Namespace);

                        string actualName;
                        string actualNamespace;
                        reader.ReadContentAsQualifiedName(out actualName, out actualNamespace);

                        if ((actualName != null) &&
                            (actualNamespace != null) &&
                            (String.Compare(name, actualName, StringComparison.Ordinal) == 0) &&
                            (String.Compare(ns, actualNamespace, StringComparison.Ordinal) == 0))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #8
0
 private object DeserializeParameter(XmlDictionaryReader reader, PartInfo part)
 {
     if (((reader.AttributeCount > 0) && reader.MoveToAttribute(this.xsiNilLocalName.Value, this.xsiNilNamespace.Value)) && reader.ReadContentAsBoolean())
     {
         reader.Skip();
         return(null);
     }
     return(part.ReadValue(reader));
 }
 internal static bool IsJsonLocalName(XmlDictionaryReader reader, string elementName)
 {
     if (reader.IsStartElement(JsonGlobals.itemDictionaryString, JsonGlobals.itemDictionaryString))
     {
         if (reader.MoveToAttribute(JsonGlobals.itemString))
         {
             return(reader.Value == elementName);
         }
     }
     return(false);
 }
        private static UniqueId GetAttributeAsUniqueId(XmlDictionaryReader reader, string name, string ns)
        {
            if (!reader.MoveToAttribute(name, ns))
            {
                return(null);
            }
            UniqueId id = reader.ReadContentAsUniqueId();

            reader.MoveToElement();
            return(id);
        }
 internal static byte[] GetRequiredBase64Attribute(XmlDictionaryReader reader, XmlDictionaryString name, XmlDictionaryString ns)
 {
     if (!reader.MoveToAttribute(name.Value, (ns == null) ? null : ns.Value))
     {
         OnRequiredAttributeMissing(name.Value, (ns == null) ? null : ns.Value);
     }
     byte[] buffer = reader.ReadContentAsBase64();
     if ((buffer == null) || (buffer.Length == 0))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("EmptyBase64Attribute", new object[] { name, ns })));
     }
     return(buffer);
 }
Example #12
0
        /// <summary>
        /// Jsonデータを読み込みます
        /// </summary>
        /// <param name="path">パス名</param>
        /// <param name="create">ファイルが存在しない場合、空ファイルを作成します。規定値はtrueです。</param>
        /// <returns>Directionaryオブジェクト</returns>
        static public JsonDictionary Load(string path, bool create = true)
        {
            var map = new Dictionary <string, string>();

            try
            {
                var file = new StreamReader(path, Encoding.UTF8);
                var json = file.ReadToEnd();

                XmlDictionaryReader xmlReader = JsonReaderWriterFactory.CreateJsonReader(
                    Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max);


                string key = "";

                while (xmlReader.Read())
                {
                    switch (xmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        // Depth = 0(rootノード)はスキップ
                        if (xmlReader.Depth == 0)
                        {
                            break;
                        }

                        // ノード名をmapのキー名にする
                        key = xmlReader.Name;

                        // itemアトリビュートに移動を試みる
                        if (xmlReader.MoveToAttribute("item"))
                        {
                            //移動できたらそこの値をmapのキーとして採用する
                            key = xmlReader.Value;
                        }
                        break;

                    case XmlNodeType.Text:
                        //mapに値を追加
                        map[key] = xmlReader.Value;
                        break;
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show(e.FileName + "が見つかりません。", "ファイル読み込みエラー");
            }

            return(map);
        }
Example #13
0
        internal static byte[] GetRequiredBase64Attribute(XmlDictionaryReader reader, XmlDictionaryString name, XmlDictionaryString ns)
        {
            if (!reader.MoveToAttribute(name.Value, ns == null ? null : ns.Value))
            {
                OnRequiredAttributeMissing(name.Value, ns == null ? null : ns.Value);
            }
            byte[] value = reader.ReadContentAsBase64();
            if (value == null || value.Length == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new XmlException(SR.Format(SR.EmptyBase64Attribute, name, ns)));
            }

            return(value);
        }
Example #14
0
 public override bool MoveToAttribute(string name, string ns)
 {
     return(innerReader.MoveToAttribute(name, ns));
 }
Example #15
0
        protected override byte [] EncodeSecurityState(byte [] src)
        {
            foreach (byte b in src)
            {
                Console.Write("{0:X02} ", b);
            }
            Console.WriteLine();
            // this show how it is LAMESPEC.
            //Array.Reverse (src);
            XmlDictionary dic = new XmlDictionary();

            for (int i = 0; i < 60; i++)
            {
                dic.Add("n" + i);
            }
            XmlDictionaryReaderQuotas quotas =
                new XmlDictionaryReaderQuotas();
            XmlDictionaryReader cr = XmlDictionaryReader.CreateBinaryReader(src, 0, src.Length, dic, quotas);

            cr.Read();
            XmlWriter w = XmlWriter.Create(Console.Out);

            while (!cr.EOF)
            {
                switch (cr.NodeType)
                {
                case XmlNodeType.Element:
                    int dummy;
                    w.WriteStartElement(cr.Prefix, cr.LocalName, cr.NamespaceURI);
                    for (int i = 0; i < cr.AttributeCount; i++)
                    {
                        cr.MoveToAttribute(i);
                        w.WriteStartAttribute(cr.Prefix, cr.LocalName, cr.NamespaceURI);
                        bool b64 = cr.LocalName == "n41";
                        while (cr.ReadAttributeValue())
                        {
                            if (b64)
                            {
                                foreach (byte b in Convert.FromBase64String(cr.Value))
                                {
                                    w.WriteString(String.Format("{0:X02}-", b));
                                }
                            }
                            else
                            {
                                w.WriteString(cr.Value);
                            }
                        }
                        w.WriteEndAttribute();
                    }
                    //w.WriteAttributes (cr, false);
                    cr.MoveToElement();
                    if (cr.IsEmptyElement)
                    {
                        w.WriteEndElement();
                    }
                    cr.Read();
                    break;

                case XmlNodeType.EndElement:
                    w.WriteEndElement();
                    cr.Read();
                    break;

                default:
                    if (cr.TryGetBase64ContentLength(out dummy))
                    {
                        foreach (byte b in cr.ReadContentAsBase64())
                        {
                            w.WriteString(String.Format("{0:X02} ", b));
                        }
                    }
                    else
                    {
                        w.WriteNode(cr, false);
                    }
                    break;
                }
            }
            w.Close();

            return(src);
        }
Example #16
0
        protected override BodyWriter OnCreateBufferedCopy(
            int maxBufferSize)
        {
#if true
            if (xml_bak == null)
            {
                if (consumed)
                {
                    throw new InvalidOperationException("Body xml reader is already consumed");
                }
                var sw = new StringWriter();
                var xw = XmlDictionaryWriter.CreateDictionaryWriter(XmlWriter.Create(sw));
                xw.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                for (int i = 0; i < reader.AttributeCount; i++)
                {
                    reader.MoveToAttribute(i);
                    if (reader.NamespaceURI != "http://www.w3.org/2000/xmlns/" || xw.LookupPrefix(reader.Value) == null)
                    {
                        xw.WriteAttributeString(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value);
                    }
                }
                reader.MoveToElement();

                var inr = reader as IXmlNamespaceResolver;
                if (inr != null)
                {
                    foreach (var p in inr.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
                    {
                        if (xw.LookupPrefix(p.Value) != p.Key)
                        {
                            xw.WriteXmlnsAttribute(p.Key, p.Value);
                        }
                    }
                }
                if (!reader.IsEmptyElement)
                {
                    reader.Read();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        xw.WriteNode(reader, false);
                    }
                }
                xw.WriteEndElement();

                xw.Close();
                xml_bak = sw.ToString();
                reader  = null;
            }
#else // FIXME: this should be better, but somehow doesn't work.
            if (xml_bak == null)
            {
                if (consumed)
                {
                    throw new InvalidOperationException("Body xml reader is already consumed");
                }
                var nss = new XmlNamespaceManager(reader.NameTable);
                var nsr = reader as IXmlNamespaceResolver;
                if (nsr != null)
                {
                    foreach (var p in nsr.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
                    {
                        nss.AddNamespace(p.Key, p.Value);
                    }
                }
                parser_context = new XmlParserContext(nss.NameTable, nss, reader.XmlLang, reader.XmlSpace);
                xml_bak        = reader.ReadOuterXml();
            }
#endif
            return(new XmlReaderBodyWriter(xml_bak, maxBufferSize, parser_context));
        }
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            try
            {
                do
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            writer.WriteAttributeString(reader.LocalName, reader.NamespaceURI, reader.Value.Replace(sourcePattern, targetPattern));
                        }
                        reader.MoveToElement();
                        if (reader.IsEmptyElement)
                        {
                            writer.WriteEndElement();
                        }
                        break;

                    case XmlNodeType.Text:
                        writer.WriteString(reader.Value.Replace(sourcePattern, targetPattern));
                        break;

                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        writer.WriteWhitespace(reader.Value);
                        break;

                    case XmlNodeType.CDATA:
                        writer.WriteCData(reader.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        writer.WriteEntityRef(reader.Name);
                        break;

                    case XmlNodeType.XmlDeclaration:
                    case XmlNodeType.ProcessingInstruction:
                        writer.WriteProcessingInstruction(reader.Name, reader.Value);
                        break;

                    case XmlNodeType.DocumentType:
                        writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                        break;

                    case XmlNodeType.Comment:
                        writer.WriteComment(reader.Value);
                        break;

                    case XmlNodeType.EndElement:
                        writer.WriteFullEndElement();
                        break;
                    }
                }while (reader.Read());
                writer.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
Example #18
0
        internal static void ReadAck(ReliableMessagingVersion reliableMessagingVersion, XmlDictionaryReader reader, out UniqueId sequenceId, out SequenceRangeCollection rangeCollection, out bool final)
        {
            WsrmFeb2005Dictionary dictionary   = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString   namespaceUri = WsrmIndex.GetNamespace(reliableMessagingVersion);

            reader.ReadStartElement(dictionary.SequenceAcknowledgement, namespaceUri);
            reader.ReadStartElement(dictionary.Identifier, namespaceUri);
            sequenceId = reader.ReadContentAsUniqueId();
            reader.ReadEndElement();
            bool allowZero = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005;

            rangeCollection = SequenceRangeCollection.Empty;
            while (reader.IsStartElement(dictionary.AcknowledgementRange, namespaceUri))
            {
                reader.MoveToAttribute("Lower");
                long lower = WsrmUtilities.ReadSequenceNumber(reader, allowZero);
                reader.MoveToAttribute("Upper");
                long upper = WsrmUtilities.ReadSequenceNumber(reader, allowZero);
                if ((((lower < 0L) || (lower > upper)) || (((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && (lower == 0L)) && (upper > 0L))) || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && (lower == 0L)))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidSequenceRange", new object[] { lower, upper })));
                }
                rangeCollection = rangeCollection.MergeWith(new SequenceRange(lower, upper));
                reader.MoveToElement();
                WsrmUtilities.ReadEmptyElement(reader);
            }
            bool flag2 = rangeCollection.Count > 0;

            final = false;
            if (reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11)
            {
                Wsrm11Dictionary dictionary2 = DXD.Wsrm11Dictionary;
                if (reader.IsStartElement(dictionary2.None, namespaceUri))
                {
                    if (flag2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, dictionary.SequenceAcknowledgement })));
                    }
                    WsrmUtilities.ReadEmptyElement(reader);
                    flag2 = true;
                }
                if (reader.IsStartElement(dictionary2.Final, namespaceUri))
                {
                    if (!flag2)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, dictionary.SequenceAcknowledgement })));
                    }
                    WsrmUtilities.ReadEmptyElement(reader);
                    final = true;
                }
            }
            bool flag4 = false;

            while (reader.IsStartElement(dictionary.Nack, namespaceUri))
            {
                if (flag2)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, "Body" })));
                }
                reader.ReadStartElement();
                WsrmUtilities.ReadSequenceNumber(reader, true);
                reader.ReadEndElement();
                flag4 = true;
            }
            if (!flag2 && !flag4)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("UnexpectedXmlChildNode", new object[] { reader.Name, reader.NodeType, "Body" })));
            }
        }
 public override bool MoveToAttribute(string name)
 {
     return(_reader.MoveToAttribute(name));
 }
 /// <summary>
 /// Moves to the attribute with the specified index.
 /// </summary>
 /// <param name="i">The index of the attribute.</param>
 public override void MoveToAttribute(int i)
 {
     _innerReader.MoveToAttribute(i);
 }