/// <summary> /// Updates the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="decoder">The decoder.</param> /// <param name="attributesToLoad">The attributes to load.</param> public override void Update(ISystemContext context, BinaryDecoder decoder, AttributesToSave attributesToLoad) { base.Update(context, decoder, attributesToLoad); if ((attributesToLoad & AttributesToSave.DataTypeDefinition) != 0) { DataTypeDefinition = decoder.ReadExtensionObject(null); } }
/// <summary> /// Converts a local value to a remote value. /// </summary> /// <param name="srcValue">The local value.</param> /// <param name="srcType">The data type of the local value.</param> /// <param name="dstType">The data type of the remote value.</param> /// <returns>The remote value.</returns> private object ConvertLocalToRemote(object srcValue, BuiltInType srcType, BuiltInType dstType) { // must determine the type from the source if the containing array is a variant. if (srcType == BuiltInType.Variant) { TypeInfo typeInfo = TypeInfo.Construct(srcValue); srcType = typeInfo.BuiltInType; } // no conversion by default. object dstValue = srcValue; // apply different conversions depending on the data type. switch (dstType) { case BuiltInType.Guid: { dstValue = new Uuid((string)srcValue); break; } case BuiltInType.XmlElement: { XmlDocument document = new XmlDocument(); document.InnerXml = (string)srcValue; dstValue = document.DocumentElement; break; } case BuiltInType.NodeId: { dstValue = GetRemoteNodeId((string)srcValue); break; } case BuiltInType.ExpandedNodeId: { ExpandedNodeId nodeId = ExpandedNodeId.Parse((string)srcValue); dstValue = GetRemoteExpandedNodeId(nodeId); break; } case BuiltInType.QualifiedName: { dstValue = GetRemoteBrowseName((string)srcValue); break; } case BuiltInType.LocalizedText: { dstValue = new LocalizedText((string)srcValue); break; } case BuiltInType.StatusCode: { dstValue = new StatusCode((uint)srcValue); break; } case BuiltInType.ExtensionObject: { BinaryDecoder decoder = new BinaryDecoder((byte[])srcValue, m_localMessageContext); dstValue = decoder.ReadExtensionObject(null); decoder.Close(); break; } default: { if (dstType != srcType && dstType != BuiltInType.Variant && dstType != BuiltInType.Null) { throw ComUtils.CreateComException(ResultIds.E_BADTYPE); } break; } } // all done. return(dstValue); }
/// <summary> /// Decode a scalar type /// </summary> /// <param name="binaryDecoder"></param> /// <param name="builtInType"></param> /// <returns>The decoded object</returns> private object DecodeRawScalar(BinaryDecoder binaryDecoder, byte builtInType) { switch ((BuiltInType)builtInType) { case BuiltInType.Boolean: return(binaryDecoder.ReadBoolean(null)); case BuiltInType.SByte: return(binaryDecoder.ReadSByte(null)); case BuiltInType.Byte: return(binaryDecoder.ReadByte(null)); case BuiltInType.Int16: return(binaryDecoder.ReadInt16(null)); case BuiltInType.UInt16: return(binaryDecoder.ReadUInt16(null)); case BuiltInType.Int32: return(binaryDecoder.ReadInt32(null)); case BuiltInType.UInt32: return(binaryDecoder.ReadUInt32(null)); case BuiltInType.Int64: return(binaryDecoder.ReadInt64(null)); case BuiltInType.UInt64: return(binaryDecoder.ReadUInt64(null)); case BuiltInType.Float: return(binaryDecoder.ReadFloat(null)); case BuiltInType.Double: return(binaryDecoder.ReadDouble(null)); case BuiltInType.String: return(binaryDecoder.ReadString(null)); case BuiltInType.DateTime: return(binaryDecoder.ReadDateTime(null)); case BuiltInType.Guid: return(binaryDecoder.ReadGuid(null)); case BuiltInType.ByteString: return(binaryDecoder.ReadByteString(null)); case BuiltInType.XmlElement: return(binaryDecoder.ReadXmlElement(null)); case BuiltInType.NodeId: return(binaryDecoder.ReadNodeId(null)); case BuiltInType.ExpandedNodeId: return(binaryDecoder.ReadExpandedNodeId(null)); case BuiltInType.StatusCode: return(binaryDecoder.ReadStatusCode(null)); case BuiltInType.QualifiedName: return(binaryDecoder.ReadQualifiedName(null)); case BuiltInType.LocalizedText: return(binaryDecoder.ReadLocalizedText(null)); case BuiltInType.DataValue: return(binaryDecoder.ReadDataValue(null)); case BuiltInType.Enumeration: return(binaryDecoder.ReadInt32(null)); case BuiltInType.Variant: return(binaryDecoder.ReadVariant(null)); case BuiltInType.ExtensionObject: return(binaryDecoder.ReadExtensionObject(null)); default: return(null); } }
/// <summary> /// Converts a local value to a remote value. /// </summary> /// <param name="srcValue">The local value.</param> /// <param name="srcType">The data type of the local value.</param> /// <param name="dstType">The data type of the remote value.</param> /// <returns>The remote value.</returns> private object ConvertLocalToRemote(object srcValue, BuiltInType srcType, BuiltInType dstType) { // must determine the type from the source if the containing array is a variant. if (srcType == BuiltInType.Variant) { TypeInfo typeInfo = TypeInfo.Construct(srcValue); srcType = typeInfo.BuiltInType; } // no conversion by default. object dstValue = srcValue; // apply different conversions depending on the data type. switch (dstType) { case BuiltInType.Guid: { dstValue = new Uuid((string)srcValue); break; } case BuiltInType.XmlElement: { XmlDocument document = new XmlDocument(); document.InnerXml = (string)srcValue; dstValue = document.DocumentElement; break; } case BuiltInType.NodeId: { dstValue = GetRemoteNodeId((string)srcValue); break; } case BuiltInType.ExpandedNodeId: { ExpandedNodeId nodeId = ExpandedNodeId.Parse((string)srcValue); dstValue = GetRemoteExpandedNodeId(nodeId); break; } case BuiltInType.QualifiedName: { dstValue = GetRemoteBrowseName((string)srcValue); break; } case BuiltInType.LocalizedText: { dstValue = new LocalizedText((string)srcValue); break; } case BuiltInType.StatusCode: { dstValue = new StatusCode((uint)srcValue); break; } case BuiltInType.ExtensionObject: { BinaryDecoder decoder = new BinaryDecoder((byte[])srcValue, m_localMessageContext); dstValue = decoder.ReadExtensionObject(null); decoder.Close(); break; } default: { if (dstType != srcType && dstType != BuiltInType.Variant && dstType != BuiltInType.Null) { throw ComUtils.CreateComException(ResultIds.E_BADTYPE); } break; } } // all done. return dstValue; }