/// <summary> /// Updates the list control. /// </summary> private void UpdateList(Session session, Argument[] arguments, string browseName) { for (int ii = 0; ii < arguments.Length; ii++) { Argument argument = arguments[ii]; Variant defaultValue = new Variant(TypeInfo.GetDefaultValue(argument.DataType, argument.ValueRank)); ListViewItem item = new ListViewItem(arguments[ii].Name); if (browseName == BrowseNames.InputArguments) { item.SubItems.Add("IN"); m_firstOutputArgument++; } else { item.SubItems.Add("OUT"); } string dataType = session.NodeCache.GetDisplayText(arguments[ii].DataType); if (arguments[ii].ValueRank >= 0) { dataType += "[]"; } item.SubItems.Add(defaultValue.ToString()); item.SubItems.Add(dataType); item.SubItems.Add(Utils.Format("{0}", arguments[ii].Description)); item.Tag = defaultValue; ArgumentsLV.Items.Add(item); } }
/// <summary> /// Returns the default value for the output argument. /// </summary> /// <param name="context">The context to use.</param> /// <param name="outputArgument">The output argument description.</param> /// <returns>The default value.</returns> protected object GetArgumentDefaultValue( ISystemContext context, Argument outputArgument) { return TypeInfo.GetDefaultValue(outputArgument.DataType, outputArgument.ValueRank, context.TypeTable); }
/// <summary> /// Does any initialization required before the address space can be used. /// </summary> /// <remarks> /// The externalReferences is an out parameter that allows the node manager to link to nodes /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and /// should have a reference to the root folder node(s) exposed by this node manager. /// </remarks> public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences) { lock (Lock) { // create a object to represent the process being controlled. BaseObjectState process = new BaseObjectState(null); process.NodeId = new NodeId(1, NamespaceIndex); process.BrowseName = new QualifiedName("My Process", NamespaceIndex); process.DisplayName = process.BrowseName.Name; process.TypeDefinitionId = ObjectTypeIds.BaseObjectType; // ensure the process object can be found via the server object. IList<IReference> references = null; if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references)) { externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>(); } process.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder); references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, process.NodeId)); // a property to report the process state. PropertyState<uint> state = m_stateNode = new PropertyState<uint>(process); state.NodeId = new NodeId(2, NamespaceIndex); state.BrowseName = new QualifiedName("State", NamespaceIndex); state.DisplayName = state.BrowseName.Name; state.TypeDefinitionId = VariableTypeIds.PropertyType; state.ReferenceTypeId = ReferenceTypeIds.HasProperty; state.DataType = DataTypeIds.UInt32; state.ValueRank = ValueRanks.Scalar; process.AddChild(state); // a method to start the process. MethodState start = new MethodState(process); start.NodeId = new NodeId(3, NamespaceIndex); start.BrowseName = new QualifiedName("Start", NamespaceIndex); start.DisplayName = start.BrowseName.Name; start.ReferenceTypeId = ReferenceTypeIds.HasComponent; start.UserExecutable = true; start.Executable = true; // add input arguments. start.InputArguments = new PropertyState<Argument[]>(start); start.InputArguments.NodeId = new NodeId(4, NamespaceIndex); start.InputArguments.BrowseName = BrowseNames.InputArguments; start.InputArguments.DisplayName = start.InputArguments.BrowseName.Name; start.InputArguments.TypeDefinitionId = VariableTypeIds.PropertyType; start.InputArguments.ReferenceTypeId = ReferenceTypeIds.HasProperty; start.InputArguments.DataType = DataTypeIds.Argument; start.InputArguments.ValueRank = ValueRanks.OneDimension; Argument[] args = new Argument[2]; args[0] = new Argument(); args[0].Name = "Initial State"; args[0].Description = "The initialize state for the process."; args[0].DataType = DataTypeIds.UInt32; args[0].ValueRank = ValueRanks.Scalar; args[1] = new Argument(); args[1].Name = "Final State"; args[1].Description = "The final state for the process."; args[1].DataType = DataTypeIds.UInt32; args[1].ValueRank = ValueRanks.Scalar; start.InputArguments.Value = args; // add output arguments. start.OutputArguments = new PropertyState<Argument[]>(start); start.OutputArguments.NodeId = new NodeId(5, NamespaceIndex); start.OutputArguments.BrowseName = BrowseNames.OutputArguments; start.OutputArguments.DisplayName = start.OutputArguments.BrowseName.Name; start.OutputArguments.TypeDefinitionId = VariableTypeIds.PropertyType; start.OutputArguments.ReferenceTypeId = ReferenceTypeIds.HasProperty; start.OutputArguments.DataType = DataTypeIds.Argument; start.OutputArguments.ValueRank = ValueRanks.OneDimension; args = new Argument[2]; args[0] = new Argument(); args[0].Name = "Revised Initial State"; args[0].Description = "The revised initialize state for the process."; args[0].DataType = DataTypeIds.UInt32; args[0].ValueRank = ValueRanks.Scalar; args[1] = new Argument(); args[1].Name = "Revised Final State"; args[1].Description = "The revised final state for the process."; args[1].DataType = DataTypeIds.UInt32; args[1].ValueRank = ValueRanks.Scalar; start.OutputArguments.Value = args; process.AddChild(start); // save in dictionary. AddPredefinedNode(SystemContext, process); // set up method handlers. start.OnCallMethod = new GenericMethodCalledEventHandler(OnStart); } }
/// <summary> /// Updates the row with an argument and its value. /// </summary> private void UpdateRow(DataRow row, Argument argument, Variant value, bool isOutputArgument) { string dataType = m_session.NodeCache.GetDisplayText(argument.DataType); if (argument.ValueRank >= 0) { dataType += "[]"; } row[0] = argument; row[1] = ImageList.Images[ClientUtils.GetImageIndex(isOutputArgument, value.Value)]; row[2] = argument.Name; row[3] = dataType; row[4] = value; row[5] = String.Empty; }