public object ReadValue(XmlDictionaryReader reader) { object value; if (_isArray) { switch (_typeCode) { case TypeCode.Byte: value = reader.ReadElementContentAsBase64(); break; case TypeCode.Boolean: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadBooleanArray(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<bool>(); } break; case TypeCode.DateTime: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadDateTimeArray(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<DateTime>(); } break; case TypeCode.Decimal: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadDecimalArray(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<Decimal>(); } break; case TypeCode.Int32: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadInt32Array(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<Int32>(); } break; case TypeCode.Int64: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadInt64Array(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<Int64>(); } break; case TypeCode.Single: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadSingleArray(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<Single>(); } break; case TypeCode.Double: if (!reader.IsEmptyElement) { reader.ReadStartElement(); value = reader.ReadDoubleArray(_itemName, _itemNamespace); reader.ReadEndElement(); } else { reader.Read(); value = Array.Empty<Double>(); } break; default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter)); } } else { switch (_typeCode) { case TypeCode.Boolean: value = reader.ReadElementContentAsBoolean(); break; case TypeCode.DateTime: value = reader.ReadElementContentAsDateTime(); break; case TypeCode.Decimal: value = reader.ReadElementContentAsDecimal(); break; case TypeCode.Double: value = reader.ReadElementContentAsDouble(); break; case TypeCode.Int32: value = reader.ReadElementContentAsInt(); break; case TypeCode.Int64: value = reader.ReadElementContentAsLong(); break; case TypeCode.Single: value = reader.ReadElementContentAsFloat(); break; case TypeCode.String: return reader.ReadElementContentAsString(); default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter)); } } return value; }
private static void ReadFrom(CoordinationContext that, XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionaryString ns, Microsoft.Transactions.Wsat.Protocol.ProtocolVersion protocolVersion) { try { Uri uri; CoordinationXmlDictionaryStrings strings = CoordinationXmlDictionaryStrings.Version(protocolVersion); AtomicTransactionStrings strings2 = AtomicTransactionStrings.Version(protocolVersion); reader.ReadFullStartElement(localName, strings.Namespace); reader.MoveToStartElement(strings.Identifier, strings.Namespace); that.unknownIdentifierAttributes = ReadOtherAttributes(reader, strings.Namespace); that.contextId = reader.ReadElementContentAsString().Trim(); if ((that.contextId.Length == 0) || (that.contextId.Length > 0x100)) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"))); } if (!Uri.TryCreate(that.contextId, UriKind.Absolute, out uri)) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"))); } if (reader.IsStartElement(strings.Expires, strings.Namespace)) { that.unknownExpiresAttributes = ReadOtherAttributes(reader, strings.Namespace); int num = reader.ReadElementContentAsInt(); if (num < 0) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"))); } that.expiration = (uint) num; that.expiresPresent = true; } reader.MoveToStartElement(strings.CoordinationType, strings.Namespace); if (reader.ReadElementContentAsString().Trim() != strings2.Namespace) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"))); } that.registrationRef = EndpointAddress.ReadFrom(MessagingVersionHelper.AddressingVersion(protocolVersion), reader, strings.RegistrationService, strings.Namespace); if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace)) { that.isoLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt(); if (((that.IsolationLevel < System.Transactions.IsolationLevel.Serializable) || (that.IsolationLevel > System.Transactions.IsolationLevel.Unspecified)) || (that.IsolationLevel == System.Transactions.IsolationLevel.Snapshot)) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"))); } } if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationFlags, XD.DotNetAtomicTransactionExternalDictionary.Namespace)) { that.isoFlags = (System.ServiceModel.Transactions.IsolationFlags) reader.ReadElementContentAsInt(); } if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.Description, XD.DotNetAtomicTransactionExternalDictionary.Namespace)) { that.description = reader.ReadElementContentAsString().Trim(); } if (reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.LocalTransactionId, XD.DotNetAtomicTransactionExternalDictionary.Namespace)) { that.localTxId = reader.ReadElementContentAsGuid(); } if (OleTxTransactionHeader.IsStartPropagationTokenElement(reader)) { that.propToken = OleTxTransactionHeader.ReadPropagationTokenElement(reader); } if (reader.IsStartElement()) { XmlDocument document = new XmlDocument(); that.unknownData = new List<System.Xml.XmlNode>(5); while (reader.IsStartElement()) { System.Xml.XmlNode item = document.ReadNode(reader); that.unknownData.Add(item); } } reader.ReadEndElement(); } catch (XmlException exception) { throw Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCoordinationContextException(Microsoft.Transactions.SR.GetString("InvalidCoordinationContext"), exception)); } }
public static object Deserialize(XmlDictionaryReader reader, Type targetType) { object returnValue = null; if (reader.IsStartElement()) { switch (reader.LocalName) { case XmlRpcProtocol.Nil: returnValue = null; break; case XmlRpcProtocol.Bool: returnValue = Convert.ChangeType((reader.ReadElementContentAsInt()==1),targetType); break; case XmlRpcProtocol.ByteArray: if (targetType == typeof(Stream)) { returnValue = new MemoryStream(reader.ReadElementContentAsBase64()); } else { returnValue = Convert.ChangeType(reader.ReadElementContentAsBase64(), targetType); } break; case XmlRpcProtocol.DateTime: returnValue = Convert.ChangeType(reader.ReadElementContentAsDateTime(),targetType); break; case XmlRpcProtocol.Double: returnValue = Convert.ChangeType(reader.ReadElementContentAsDouble(),targetType); break; case XmlRpcProtocol.Int32: case XmlRpcProtocol.Integer: returnValue = Convert.ChangeType(reader.ReadElementContentAsString(),targetType); break; case XmlRpcProtocol.String: if (targetType == typeof(Uri)) { returnValue = new Uri(reader.ReadElementContentAsString()); } else { returnValue = Convert.ChangeType(reader.ReadElementContentAsString(), targetType); } break; case XmlRpcProtocol.Struct: returnValue = DeserializeStruct(reader, targetType); break; case XmlRpcProtocol.Array: if (targetType.IsArray || targetType is IEnumerable || targetType is IList || targetType is ICollection) { reader.ReadStartElement(XmlRpcProtocol.Array); ArrayList arrayData = new ArrayList(); reader.ReadStartElement(XmlRpcProtocol.Data); reader.MoveToContent(); while (reader.IsStartElement(XmlRpcProtocol.Value)) { reader.ReadStartElement(); arrayData.Add(Deserialize(reader, targetType.GetElementType())); reader.ReadEndElement(); reader.MoveToContent(); } if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == XmlRpcProtocol.Data) { reader.ReadEndElement(); } reader.ReadEndElement(); if (targetType is IEnumerable || targetType is IList || targetType is ICollection) { returnValue = arrayData; } else { returnValue = arrayData.ToArray(targetType.GetElementType()); } } else { throw new InvalidOperationException(); } break; } } return returnValue; }
public object ReadValue(XmlDictionaryReader reader) { object obj2; if (!this.isArray) { switch (this.typeCode) { case TypeCode.Int32: return reader.ReadElementContentAsInt(); case TypeCode.Int64: return reader.ReadElementContentAsLong(); case TypeCode.Single: return reader.ReadElementContentAsFloat(); case TypeCode.Double: return reader.ReadElementContentAsDouble(); case TypeCode.Decimal: return reader.ReadElementContentAsDecimal(); case TypeCode.DateTime: return reader.ReadElementContentAsDateTime(); case TypeCode.String: return reader.ReadElementContentAsString(); case TypeCode.Boolean: return reader.ReadElementContentAsBoolean(); } throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidUseOfPrimitiveOperationFormatter"))); } switch (this.typeCode) { case TypeCode.Boolean: if (reader.IsEmptyElement) { reader.Read(); return new bool[0]; } reader.ReadStartElement(); obj2 = reader.ReadBooleanArray(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; case TypeCode.Byte: return reader.ReadElementContentAsBase64(); case TypeCode.Int32: if (reader.IsEmptyElement) { reader.Read(); return new int[0]; } reader.ReadStartElement(); obj2 = reader.ReadInt32Array(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; case TypeCode.Int64: if (reader.IsEmptyElement) { reader.Read(); return new long[0]; } reader.ReadStartElement(); obj2 = reader.ReadInt64Array(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; case TypeCode.Single: if (reader.IsEmptyElement) { reader.Read(); return new float[0]; } reader.ReadStartElement(); obj2 = reader.ReadSingleArray(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; case TypeCode.Double: if (reader.IsEmptyElement) { reader.Read(); return new double[0]; } reader.ReadStartElement(); obj2 = reader.ReadDoubleArray(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; case TypeCode.Decimal: if (reader.IsEmptyElement) { reader.Read(); return new decimal[0]; } reader.ReadStartElement(); obj2 = reader.ReadDecimalArray(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; case TypeCode.DateTime: if (reader.IsEmptyElement) { reader.Read(); return new DateTime[0]; } reader.ReadStartElement(); obj2 = reader.ReadDateTimeArray(this.itemName, this.itemNamespace); reader.ReadEndElement(); return obj2; } throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInvalidUseOfPrimitiveOperationFormatter"))); }
private void ReadFrom(XmlDictionaryReader reader) { try { reader.ReadFullStartElement(this.coordinationXmlDictionaryStrings.CreateCoordinationContext, this.coordinationXmlDictionaryStrings.Namespace); if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.Expires, this.coordinationXmlDictionaryStrings.Namespace)) { int num = reader.ReadElementContentAsInt(); if (num < 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"))); } this.expiration = (uint) num; this.expiresPresent = true; } if (reader.IsStartElement(this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace)) { this.CurrentContext = CoordinationContext.ReadFrom(reader, this.coordinationXmlDictionaryStrings.CurrentContext, this.coordinationXmlDictionaryStrings.Namespace, this.protocolVersion); } reader.MoveToStartElement(this.coordinationXmlDictionaryStrings.CoordinationType, this.coordinationXmlDictionaryStrings.Namespace); if (reader.ReadElementContentAsString().Trim() != this.atomicTransactionStrings.Namespace) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"))); } if (!reader.IsStartElement(XD.DotNetAtomicTransactionExternalDictionary.IsolationLevel, XD.DotNetAtomicTransactionExternalDictionary.Namespace)) { goto Label_016B; } this.IsolationLevel = (System.Transactions.IsolationLevel) reader.ReadElementContentAsInt(); if (((this.IsolationLevel >= System.Transactions.IsolationLevel.Serializable) && (this.IsolationLevel <= System.Transactions.IsolationLevel.Unspecified)) && (this.IsolationLevel != System.Transactions.IsolationLevel.Snapshot)) { goto Label_016B; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"))); Label_0165: reader.Skip(); Label_016B: if (reader.IsStartElement()) { goto Label_0165; } reader.ReadEndElement(); } catch (XmlException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception)); } catch (InvalidCoordinationContextException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidMessageException(Microsoft.Transactions.SR.GetString("InvalidMessageBody"), exception2)); } }