Exemplo n.º 1
0
        public virtual void WriteNode(XmlDictionaryReader reader,
                                      bool defattr)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            switch (reader.NodeType)
            {
            case XmlNodeType.Element:
                // gratuitously copied from System.XML/System.Xml/XmlWriter.cs:WriteNode(XmlReader,bool)
                // as there doesn't seem to be a way to hook into attribute writing w/o handling Element.
                WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                // Well, I found that MS.NET took this way, since
                // there was a error-prone SgmlReader that fails
                // MoveToNextAttribute().
                if (reader.HasAttributes)
                {
                    for (int i = 0; i < reader.AttributeCount; i++)
                    {
                        reader.MoveToAttribute(i);
                        WriteAttribute(reader, defattr);
                    }
                    reader.MoveToElement();
                }
                if (reader.IsEmptyElement)
                {
                    WriteEndElement();
                }
                else
                {
                    int depth = reader.Depth;
                    reader.Read();
                    if (reader.NodeType != XmlNodeType.EndElement)
                    {
                        do
                        {
                            WriteNode(reader, defattr);
                        } while (depth < reader.Depth);
                    }
                    WriteFullEndElement();
                }
                reader.Read();
                break;

            case XmlNodeType.Attribute:
            case XmlNodeType.Text:
                WriteTextNode(reader, defattr);
                break;

            default:
                base.WriteNode(reader, defattr);
                break;
            }
        }
 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;
 }
Exemplo n.º 3
0
		public virtual void WriteNode (XmlDictionaryReader reader,
			bool defattr)
		{
			if (reader == null)
				throw new ArgumentNullException ("reader");

			switch (reader.NodeType) {
			case XmlNodeType.Element:
				// gratuitously copied from System.XML/System.Xml/XmlWriter.cs:WriteNode(XmlReader,bool)
				// as there doesn't seem to be a way to hook into attribute writing w/o handling Element.
				XmlDictionaryString ename, ens;
				if (reader.TryGetLocalNameAsDictionaryString (out ename) && reader.TryGetLocalNameAsDictionaryString (out ens))
					WriteStartElement (reader.Prefix, ename, ens);
				else
					WriteStartElement (reader.Prefix, reader.LocalName, reader.NamespaceURI);
				// Well, I found that MS.NET took this way, since
				// there was a error-prone SgmlReader that fails
				// MoveToNextAttribute().
				if (reader.HasAttributes) {
					for (int i = 0; i < reader.AttributeCount; i++) {
						reader.MoveToAttribute (i);
						WriteAttribute (reader, defattr);
					}
					reader.MoveToElement ();
				}
				if (reader.IsEmptyElement)
					WriteEndElement ();
				else {
					int depth = reader.Depth;
					reader.Read ();
					if (reader.NodeType != XmlNodeType.EndElement) {
						do {
							WriteNode (reader, defattr);
						} while (depth < reader.Depth);
					}
					WriteFullEndElement ();
				}
				reader.Read ();
				break;
			case XmlNodeType.Attribute:
			case XmlNodeType.Text:
				WriteTextNode (reader, defattr);
				break;
			default:
				base.WriteNode (reader, defattr);
				break;
			}
		}
Exemplo n.º 4
0
 private object DeserializeParameter(XmlDictionaryReader reader, PartInfo part)
 {
     if (reader.AttributeCount > 0 &&
         reader.MoveToAttribute(_xsiNilLocalName.Value, _xsiNilNamespace.Value) &&
         reader.ReadContentAsBoolean())
     {
         reader.Skip();
         return null;
     }
     return part.ReadValue(reader);
 }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
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;
        }
        // February 2005 - Reads Identifier, AcknowledgementRange, Nack
        // 1.1 - Reads Identifier, AcknowledgementRange, None, Final, Nack
        internal static void ReadAck(ReliableMessagingVersion reliableMessagingVersion,
            XmlDictionaryReader reader, out UniqueId sequenceId, out SequenceRangeCollection rangeCollection,
            out bool final)
        {
            WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary;
            XmlDictionaryString wsrmNs = WsrmIndex.GetNamespace(reliableMessagingVersion);

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

            rangeCollection = SequenceRangeCollection.Empty;
            while (reader.IsStartElement(wsrmFeb2005Dictionary.AcknowledgementRange, wsrmNs))
            {
                reader.MoveToAttribute(WsrmFeb2005Strings.Lower);
                Int64 lower = WsrmUtilities.ReadSequenceNumber(reader, allowZero);

                reader.MoveToAttribute(WsrmFeb2005Strings.Upper);
                Int64 upper = WsrmUtilities.ReadSequenceNumber(reader, allowZero);

                if (lower < 0 || lower > upper
                    || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessagingFebruary2005) && (lower == 0 && upper > 0))
                    || ((reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11) && (lower == 0)))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new XmlException(SR.GetString(SR.InvalidSequenceRange, lower, upper)));
                }

                rangeCollection = rangeCollection.MergeWith(new SequenceRange(lower, upper));

                reader.MoveToElement();

                WsrmUtilities.ReadEmptyElement(reader);
            }

            bool validAck = rangeCollection.Count > 0;
            final = false;
            bool wsrm11 = reliableMessagingVersion == ReliableMessagingVersion.WSReliableMessaging11;

            if (wsrm11)
            {
                Wsrm11Dictionary wsrm11Dictionary = DXD.Wsrm11Dictionary;

                if (reader.IsStartElement(wsrm11Dictionary.None, wsrmNs))
                {
                    if (validAck)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(
                            SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType,
                            wsrmFeb2005Dictionary.SequenceAcknowledgement)));
                    }

                    WsrmUtilities.ReadEmptyElement(reader);
                    validAck = true;
                }

                if (reader.IsStartElement(wsrm11Dictionary.Final, wsrmNs))
                {
                    if (!validAck)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(
                            SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType,
                            wsrmFeb2005Dictionary.SequenceAcknowledgement)));
                    }

                    WsrmUtilities.ReadEmptyElement(reader);
                    final = true;
                }
            }

            bool foundNack = false;
            while (reader.IsStartElement(wsrmFeb2005Dictionary.Nack, wsrmNs))
            {
                if (validAck)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(
                        SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType,
                        MessageStrings.Body)));
                }

                reader.ReadStartElement();
                WsrmUtilities.ReadSequenceNumber(reader, true);
                reader.ReadEndElement();
                foundNack = true;
            }

            if (!validAck && !foundNack)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(
                    SR.GetString(SR.UnexpectedXmlChildNode, reader.Name, reader.NodeType,
                    MessageStrings.Body)));
            }
        }
Exemplo n.º 8
0
 public override void MoveToAttribute(int index)
 {
     reader.MoveToAttribute(index);
 }
 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" })));
     }
 }