/// <summary> /// Displays a dialog to edit a complex value. /// </summary> private void EditComplexValue(TsCCpxComplexValue complexValue) { object value = null; if (!complexValue.Value.GetType().IsArray) { value = new EditValueDlg().ShowDialog(complexValue.Value, true); } else if (complexValue.Value.GetType() == typeof(byte[])) { value = new EditBinaryDlg().ShowDialog((byte[])complexValue.Value); } else { if (complexValue.Value.GetType() != typeof(TsCCpxComplexValue[])) { value = new EditArrayDlg().ShowDialog(complexValue.Value, m_readOnly); } } if (value != null) { // update the complex value. complexValue.Value = value; // serialize the entire complex value starting with the root object. m_rawValue = m_binaryValue.Parse(m_complexValue); // update the diplay. UpdateView(); } }
/// <summary> /// Updates the controls with a new value. /// </summary> public void UpdateValue(object rawValue) { m_rawValue = rawValue; if (m_binaryValue != null && rawValue.GetType() == typeof(byte[])) { m_complexValue = m_binaryValue.Parse((byte[])rawValue); } UpdateView(); }
/// <summary> /// Adds a complex value to the a branch in the tree view. /// </summary> private void ShowFormattedValue(TreeNodeCollection nodes, TsCCpxComplexValue complexValue, int index) { if (complexValue == null) { nodes.Clear(); return; } TreeNode node = null; // check if the node already exists. if (nodes.Count > index) { node = nodes[index]; } // adds a new node. if (node == null) { node = new TreeNode(); node.Text = complexValue.Name; node.ImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER; node.SelectedImageIndex = Resources.IMAGE_CLOSED_YELLOW_FOLDER; nodes.Add(node); } node.Tag = complexValue; // check for nested structure. if (complexValue.Value.GetType() == typeof(TsCCpxComplexValue[])) { int ii = 0; foreach (TsCCpxComplexValue element in (Array)complexValue.Value) { ShowFormattedValue(node.Nodes, element, ii++); } } }
/// <summary> /// Updates the state of context menus based on the current selection. /// </summary> private void TypeTV_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { // ignore left button actions. if (e.Button != MouseButtons.Right) { return; } // selects the item that was right clicked on. TreeNode clickedNode = TypeTV.GetNodeAt(e.X, e.Y); // no item clicked on - do nothing. if (clickedNode == null) { return; } // force selection to clicked node. TypeTV.SelectedNode = clickedNode; // disable everything. EditMI.Enabled = false; if (clickedNode.Tag == null || clickedNode.Tag.GetType() != typeof(TsCCpxComplexValue)) { return; } TsCCpxComplexValue value = (TsCCpxComplexValue)clickedNode.Tag; if (value.Value.GetType() == typeof(TsCCpxComplexValue[])) { return; } EditMI.Enabled = !m_readOnly; }
/// <summary> /// Displays the value(s) of a complex value in the list view. /// </summary> void ShowComplexValue(TsCCpxComplexValue complexValue) { // check if the value is already displayed. if (complexValue == null || complexValue.Equals(FieldsLV.Tag)) { return; } FieldsLV.Items.Clear(); // display a simple value. if (!complexValue.Value.GetType().IsArray || complexValue.Value.GetType() == typeof(byte[])) { ListViewItem listItem = new ListViewItem(complexValue.Name, Resources.IMAGE_EXPLODING_BOX); listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(complexValue.Value.GetType())); listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(complexValue.Value)); listItem.Tag = complexValue; FieldsLV.Items.Add(listItem); AdjustColumns(); return; } // display an array value. ArrayList fields = new ArrayList((Array)complexValue.Value); for (int ii = 0; ii < fields.Count; ii++) { ListViewItem listItem = null; // display the fields in a complex value. if (fields[ii].GetType() == typeof(TsCCpxComplexValue)) { TsCCpxComplexValue elementValue = (TsCCpxComplexValue)fields[ii]; listItem = new ListViewItem(elementValue.Name, Resources.IMAGE_EXPLODING_BOX); // display a complex value field. if (elementValue.Value.GetType() == typeof(TsCCpxComplexValue[])) { listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(elementValue.Type)); listItem.SubItems.Add(String.Format("ComplexValue[{0}]", ((Array)elementValue.Value).Length)); } // display a simple type field. else { listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(elementValue.Type)); listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(elementValue.Value)); } listItem.Tag = elementValue; } // display simple value. else { listItem = new ListViewItem(String.Format("[{0}]", ii), Resources.IMAGE_EXPLODING_BOX); listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(fields[ii].GetType())); listItem.SubItems.Add(OpcClientSdk.OpcConvert.ToString(fields[ii])); listItem.Tag = fields[ii]; } // add item to list. FieldsLV.Items.Add(listItem); } AdjustColumns(); }
/// <summary> /// Displays the dialog with the specified complex item. /// </summary> public object ShowDialog(TsCCpxComplexItem item, object rawValue, bool readOnly, bool modal) { if (item == null) { throw new ArgumentNullException("item"); } try { m_readOnly = readOnly; m_item = item; m_rawValue = rawValue; // fetch complex type information for the item. string dictionary = TsCCpxComplexTypeCache.GetTypeDictionary(item); if (dictionary == null) { return(null); } // initialize dialog controls. TypeTV.Nodes.Clear(); FieldsLV.Items.Clear(); RawTB.Text = null; // display the dictionary and type description. TypeDictionaryTB.Text = FormatXml(dictionary); TypeDescriptionTB.Text = FormatXml(TsCCpxComplexTypeCache.GetTypeDescription(item)); if (rawValue == null) { ViewMI_Click(TypeDictionaryMI, null); } else { // parse binary value. if (rawValue.GetType() == typeof(byte[])) { m_binaryValue = new BinaryValue(); try { m_complexValue = m_binaryValue.Init(rawValue, dictionary, item.TypeID); } catch (Exception e) { MessageBox.Show(e.Message); m_complexValue = null; } } else { m_binaryValue = null; m_complexValue = null; } UpdateView(); if (TypeTV.SelectedNode != null) { TypeTV.SelectedNode = TypeTV.Nodes[0]; TypeTV.SelectedNode.Expand(); ViewMI_Click(FormattedMI, null); } else { ViewMI_Click(RawMI, null); } } if (modal) { // show dialog. if (ShowDialog() != DialogResult.OK) { return(null); } return(m_rawValue); } // display non-model window. Show(); return(null); } catch (Exception e) { MessageBox.Show(e.Message); return(null); } }
// serializes the buffer according to the schema. public byte[] Parse(TsCCpxComplexValue complexValue) { return(new OpcClientSdk.Cpx.TsCCpxBinaryWriter().Write(complexValue, m_dictionary, m_typeID)); }
// serializes the buffer according to the schema. public byte[] Parse(TsCCpxComplexValue complexValue) { return(new Technosoftware.DaAeHdaClient.Cpx.TsCCpxBinaryWriter().Write(complexValue, m_dictionary, m_typeID)); }