/// <summary> /// Creates a new instance. /// </summary> /// <param name="context">The current context.</param> /// <param name="parent">The parent.</param> /// <param name="nodeClass">The node class.</param> /// <param name="browseName">The browse name.</param> /// <param name="referenceTypeId">The reference type between the parent and the node.</param> /// <param name="typeDefinitionId">The type definition.</param> /// <returns>Returns null if the type is not known.</returns> public virtual NodeState CreateInstance( ISystemContext context, NodeState parent, NodeClass nodeClass, QualifiedName browseName, NodeId referenceTypeId, NodeId typeDefinitionId) { NodeState child = null; if (m_types != null && !NodeId.IsNull(typeDefinitionId)) { Type type = null; if (m_types.TryGetValue(typeDefinitionId, out type)) { return(Activator.CreateInstance(type, parent) as NodeState); } } switch (nodeClass) { case NodeClass.Variable: { if (context.TypeTable != null && context.TypeTable.IsTypeOf(referenceTypeId, ReferenceTypeIds.HasProperty)) { child = new PropertyState(parent); break; } child = new BaseDataVariableState(parent); break; } case NodeClass.Object: { child = new BaseObjectState(parent); break; } case NodeClass.Method: { child = new MethodState(parent); break; } case NodeClass.ReferenceType: { child = new ReferenceTypeState(); break; } case NodeClass.ObjectType: { child = new BaseObjectTypeState(); break; } case NodeClass.VariableType: { child = new BaseDataVariableTypeState(); break; } case NodeClass.DataType: { child = new DataTypeState(); break; } case NodeClass.View: { child = new ViewState(); break; } default: { child = null; break; } } return(child); }
/// <summary> /// Initializes the instance with its defalt attribute values. /// </summary> public MethodState(NodeState parent) : base(NodeClass.Method, parent) { m_executable = true; m_userExecutable = true; }
/// <summary> /// Constructs an instance of a node. /// </summary> /// <param name="parent">The parent.</param> /// <returns>The new node.</returns> public static NodeState Construct(NodeState parent) { return(new MethodState(parent)); }
/// <summary> /// Constructs an instance of a node. /// </summary> /// <param name="parent">The parent.</param> /// <returns>The new node.</returns> public static NodeState Construct(NodeState parent) { return(new BaseObjectTypeState()); }
/// <summary> /// Initializes the instance with its defalt attribute values. /// </summary> public FolderState(NodeState parent) : base(parent) { }
/// <summary> /// Returns true if the target node is required (used to apply view filters); /// </summary> public virtual bool IsRequired(NodeState target) { return(true); }
/// <summary> /// Initializes the instance with its defalt attribute values. /// </summary> protected BaseInstanceState(NodeClass nodeClass, NodeState parent) : base(nodeClass) { m_parent = parent; }
/// <summary> /// Initializes the instance from an event notification. /// </summary> /// <param name="context">The context.</param> /// <param name="fields">The fields selected for the event notification.</param> /// <param name="e">The event notification.</param> /// <remarks> /// This method creates components based on the browse paths in the event field and sets /// the NodeId or Value based on values in the event notification. /// </remarks> public void Update( ISystemContext context, SimpleAttributeOperandCollection fields, EventFieldList e) { for (int ii = 0; ii < fields.Count; ii++) { SimpleAttributeOperand field = fields[ii]; object value = e.EventFields[ii].Value; // check if value provided. if (value == null) { continue; } // extract the NodeId for the event. if (field.BrowsePath.Count == 0) { if (field.AttributeId == Attributes.NodeId) { this.NodeId = value as NodeId; continue; } } // extract the type definition for the event. if (field.BrowsePath.Count == 1) { if (field.AttributeId == Attributes.Value) { if (field.BrowsePath[0] == BrowseNames.EventType) { m_typeDefinitionId = value as NodeId; continue; } } } // save value for child node. NodeState parent = this; for (int jj = 0; jj < field.BrowsePath.Count; jj++) { // find a predefined child identified by the browse name. BaseInstanceState child = parent.CreateChild(context, field.BrowsePath[jj]); // create a placeholder for unknown children. if (child == null) { if (field.AttributeId == Attributes.Value) { child = new BaseDataVariableState(parent); } else { child = new BaseObjectState(parent); } parent.AddChild(child); } // ensure the browse name is set. if (QualifiedName.IsNull(child.BrowseName)) { child.BrowseName = field.BrowsePath[jj]; } // ensure the display name is set. if (LocalizedText.IsNullOrEmpty(child.DisplayName)) { child.DisplayName = child.BrowseName.Name; } // process next element in path. if (jj < field.BrowsePath.Count - 1) { parent = child; continue; } // save the variable value. if (field.AttributeId == Attributes.Value) { BaseVariableState variable = child as BaseVariableState; if (variable != null && field.AttributeId == Attributes.Value) { try { variable.WrappedValue = e.EventFields[ii]; } catch (Exception) { variable.Value = null; } } break; } // save the node id. child.NodeId = value as NodeId; } } }