/// <summary> /// Saves the attributes from the stream. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="encoder">The encoder wrapping the stream to write.</param> public override void Save(ISystemContext context, XmlEncoder encoder) { base.Save(context, encoder); encoder.PushNamespace(Namespaces.OpcUaXsd); if (m_executable) { encoder.WriteBoolean("Executable", m_executable); } if (m_userExecutable) { encoder.WriteBoolean("UserExecutable", m_executable); } encoder.PopNamespace(); }
/// <summary> /// Sets the value shown in the control. /// </summary> private void SetValue(Variant value) { ValueTB.ForeColor = Color.Empty; ValueTB.Font = new Font(ValueTB.Font, FontStyle.Regular); m_textChanged = false; // check for null. if (Variant.Null == value) { ValueTB.Text = String.Empty; m_value = Variant.Null; return; } // get the source type. TypeInfo sourceType = value.TypeInfo; if (sourceType == null) { sourceType = TypeInfo.Construct(value.Value); } m_value = new Variant(value.Value, sourceType); // display value as text. StringBuilder buffer = new StringBuilder(); XmlWriter writer = XmlWriter.Create(buffer, new XmlWriterSettings() { Indent = true, OmitXmlDeclaration = true }); XmlEncoder encoder = new XmlEncoder(new XmlQualifiedName("Value", Namespaces.OpcUaXsd), writer, m_session.MessageContext); encoder.WriteVariantContents(m_value.Value, m_value.TypeInfo); writer.Close(); ValueTB.Text = buffer.ToString(); // extract the encoding id from the value. ExpandedNodeId encodingId = null; ExtensionObjectEncoding encoding = ExtensionObjectEncoding.None; if (sourceType.BuiltInType == BuiltInType.ExtensionObject) { ExtensionObject extension = null; if (sourceType.ValueRank == ValueRanks.Scalar) { extension = (ExtensionObject)m_value.Value; } else { // only use the first item in the list for arrays. ExtensionObject[] list = (ExtensionObject[])m_value.Value; if (list.Length > 0) { extension = list[0]; } } encodingId = extension.TypeId; encoding = extension.Encoding; } if (encodingId == null) { StatusCTRL.Visible = false; return; } // check if the encoding is known. IObject encodingNode = m_session.NodeCache.Find(encodingId) as IObject; if (encodingNode == null) { StatusCTRL.Visible = false; return; } // update the encoding shown. if (encoding == ExtensionObjectEncoding.EncodeableObject) { EncodingCB.Text = "(Converted to XML by Client)"; } else { EncodingCB.Text = m_session.NodeCache.GetDisplayText(encodingNode); } m_encodingName = encodingNode.BrowseName; // find the data type for the encoding. IDataType dataTypeNode = null; foreach (INode node in m_session.NodeCache.Find(encodingNode.NodeId, Opc.Ua.ReferenceTypeIds.HasEncoding, true, false)) { dataTypeNode = node as IDataType; if (dataTypeNode != null) { break; } } if (dataTypeNode == null) { StatusCTRL.Visible = false; return; } // update data type display. DataTypeTB.Text = m_session.NodeCache.GetDisplayText(dataTypeNode); DataTypeTB.Tag = dataTypeNode; // update encoding drop down. EncodingCB.DropDownItems.Clear(); foreach (INode node in m_session.NodeCache.Find(dataTypeNode.NodeId, Opc.Ua.ReferenceTypeIds.HasEncoding, false, false)) { IObject encodingNode2 = node as IObject; if (encodingNode2 != null) { ToolStripMenuItem item = new ToolStripMenuItem(m_session.NodeCache.GetDisplayText(encodingNode2)); item.Tag = encodingNode2; item.Click += new EventHandler(EncodingCB_Item_Click); EncodingCB.DropDownItems.Add(item); } } StatusCTRL.Visible = true; }
/// <summary> /// Saves the attributes from the stream. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="encoder">The encoder wrapping the stream to write.</param> public override void Save(ISystemContext context, XmlEncoder encoder) { base.Save(context, encoder); encoder.PushNamespace(Namespaces.OpcUaXsd); if (!NodeId.IsNull(m_referenceTypeId)) { encoder.WriteNodeId("ReferenceTypeId", m_referenceTypeId); } if (!NodeId.IsNull(m_typeDefinitionId)) { encoder.WriteNodeId("TypeDefinitionId", m_typeDefinitionId); } if (!NodeId.IsNull(m_modellingRuleId)) { encoder.WriteNodeId("ModellingRuleId", m_modellingRuleId); } if (m_numericId != 0) { encoder.WriteUInt32("NumericId", m_numericId); } encoder.PopNamespace(); }
/// <summary> /// Saves the attributes from the stream. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="encoder">The encoder wrapping the stream to write.</param> public override void Save(ISystemContext context, XmlEncoder encoder) { base.Save(context, encoder); encoder.PushNamespace(Namespaces.OpcUaXsd); if (m_value != null) { encoder.WriteVariant("Value", WrappedValue); } if (!NodeId.IsNull(DataType)) { encoder.WriteNodeId("DataType", DataType); } if (ValueRank != ValueRanks.Any) { encoder.WriteInt32("ValueRank", ValueRank); } if (ArrayDimensions != null) { encoder.WriteString("ArrayDimensions", BaseVariableState.ArrayDimensionsToXml(ArrayDimensions)); } encoder.PopNamespace(); }
/// <summary> /// Saves the attributes from the stream. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="encoder">The encoder wrapping the stream to write.</param> public override void Save(ISystemContext context, XmlEncoder encoder) { base.Save(context, encoder); encoder.PushNamespace(Namespaces.OpcUaXsd); if (!LocalizedText.IsNullOrEmpty(m_inverseName)) { encoder.WriteLocalizedText("InverseName", m_inverseName); } if (m_symmetric) { encoder.WriteBoolean("Symmetric", m_symmetric); } encoder.PopNamespace(); }
/// <summary> /// Saves the attributes from the stream. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="encoder">The encoder wrapping the stream to write.</param> public override void Save(ISystemContext context, XmlEncoder encoder) { base.Save(context, encoder); encoder.PushNamespace(Namespaces.OpcUaXsd); if (m_eventNotifier != 0) { encoder.WriteByte("EventNotifier", m_eventNotifier); } if (m_containsNoLoops) { encoder.WriteBoolean("ContainsNoLoops", m_containsNoLoops); } encoder.PopNamespace(); }
/// <summary> /// Encodes the object in XML. /// </summary> public static XmlElement EncodeXml(IEncodeable encodeable, ServiceMessageContext context) { // create encoder. XmlEncoder encoder = new XmlEncoder(context); // write body. encoder.WriteExtensionObjectBody(encodeable); // create document from encoder. XmlDocument document = new XmlDocument(); document.InnerXml = encoder.Close(); // return root element. return document.DocumentElement; }
/// <summary> /// Saves the attributes from the stream. /// </summary> /// <param name="context">The context for the system being accessed.</param> /// <param name="encoder">The encoder wrapping the stream to write.</param> public override void Save(ISystemContext context, XmlEncoder encoder) { base.Save(context, encoder); encoder.PushNamespace(Namespaces.OpcUaXsd); if (!NodeId.IsNull(m_superTypeId)) { encoder.WriteNodeId("SuperTypeId", m_superTypeId); } if (m_isAbstract) { encoder.WriteBoolean("IsAbstract", m_isAbstract); } encoder.PopNamespace(); }