/// <summary>
        /// Initializes the object as a collection of counters which change value on read.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            InitializeVariable(context, BooleanValue, TestData.Variables.UserScalarValueObjectType_BooleanValue);
            InitializeVariable(context, SByteValue, TestData.Variables.UserScalarValueObjectType_SByteValue);
            InitializeVariable(context, ByteValue, TestData.Variables.UserScalarValueObjectType_ByteValue);
            InitializeVariable(context, Int16Value, TestData.Variables.UserScalarValueObjectType_Int16Value);
            InitializeVariable(context, UInt16Value, TestData.Variables.UserScalarValueObjectType_UInt16Value);
            InitializeVariable(context, Int32Value, TestData.Variables.UserScalarValueObjectType_Int32Value);
            InitializeVariable(context, UInt32Value, TestData.Variables.UserScalarValueObjectType_UInt32Value);
            InitializeVariable(context, Int64Value, TestData.Variables.UserScalarValueObjectType_Int64Value);
            InitializeVariable(context, UInt64Value, TestData.Variables.UserScalarValueObjectType_UInt64Value);
            InitializeVariable(context, FloatValue, TestData.Variables.UserScalarValueObjectType_FloatValue);
            InitializeVariable(context, DoubleValue, TestData.Variables.UserScalarValueObjectType_DoubleValue);
            InitializeVariable(context, StringValue, TestData.Variables.UserScalarValueObjectType_StringValue);
            InitializeVariable(context, DateTimeValue, TestData.Variables.UserScalarValueObjectType_DateTimeValue);
            InitializeVariable(context, GuidValue, TestData.Variables.UserScalarValueObjectType_GuidValue);
            InitializeVariable(context, ByteStringValue, TestData.Variables.UserScalarValueObjectType_ByteStringValue);
            InitializeVariable(context, XmlElementValue, TestData.Variables.UserScalarValueObjectType_XmlElementValue);
            InitializeVariable(context, NodeIdValue, TestData.Variables.UserScalarValueObjectType_NodeIdValue);
            InitializeVariable(context, ExpandedNodeIdValue, TestData.Variables.UserScalarValueObjectType_ExpandedNodeIdValue);
            InitializeVariable(context, QualifiedNameValue, TestData.Variables.UserScalarValueObjectType_QualifiedNameValue);
            InitializeVariable(context, LocalizedTextValue, TestData.Variables.UserScalarValueObjectType_LocalizedTextValue);
            InitializeVariable(context, StatusCodeValue, TestData.Variables.UserScalarValueObjectType_StatusCodeValue);
            InitializeVariable(context, VariantValue, TestData.Variables.UserScalarValueObjectType_VariantValue);
        }
        /// <summary>
        /// Initializes the object as a collection of counters which change value on read.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            UpdateStateVariable(context, Objects.ProgramStateMachineType_Ready, CurrentState);
            UpdateTransitionVariable(context, 0, LastTransition);

            Start.OnCallMethod = OnStart;
            Start.OnReadExecutable = IsStartExecutable;
            Start.OnReadUserExecutable = IsStartUserExecutable;

            Suspend.OnCallMethod = OnSuspend;
            Suspend.OnReadExecutable = IsSuspendExecutable;
            Suspend.OnReadUserExecutable = IsSuspendUserExecutable;

            Resume.OnCallMethod = OnResume;
            Resume.OnReadExecutable = IsResumeExecutable;
            Resume.OnReadUserExecutable = IsResumeUserExecutable;

            Halt.OnCallMethod = OnHalt;
            Halt.OnReadExecutable = IsHaltExecutable;
            Halt.OnReadUserExecutable = IsHaltUserExecutable;

            Reset.OnCallMethod = OnReset;
            Reset.OnReadExecutable = IsResetExecutable;
            Reset.OnReadUserExecutable = IsResetUserExecutable;
        }
Пример #3
0
        /// <summary>
        /// Initializes the object as a collection of counters which change value on read.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            UpdateStateVariable(context, Objects.ShelvedStateMachineType_Unshelved, CurrentState);
            UpdateTransitionVariable(context, 0, LastTransition);
        }
Пример #4
0
 /// <summary>
 /// Creates a new browser object with a set of filters.
 /// </summary>
 public Browser(
     ISystemContext context,
     ViewDescription view,
     NodeId referenceType,
     bool includeSubtypes,
     BrowseDirection browseDirection,
     QualifiedName browseName,
     IEnumerable<IReference> additionalReferences,
     bool internalOnly,
     Opc.Ua.Client.Session client,
     NamespaceMapper mapper,
     NodeState source,
     NodeId rootId)
 :
     base(
         context,
         view,
         referenceType,
         includeSubtypes,
         browseDirection,
         browseName,
         additionalReferences,
         internalOnly)
 {
     m_client = client;
     m_mapper = mapper;
     m_source = source;
     m_rootId = rootId;
     m_stage = Stage.Begin;
 }
Пример #5
0
        /// <summary>
        /// Called after a node is created.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            if (this.ShelvingState != null)
            {
                if (this.ShelvingState.UnshelveTime != null)
                {
                    this.ShelvingState.UnshelveTime.OnSimpleReadValue = OnReadUnshelveTime;
                    this.ShelvingState.UnshelveTime.MinimumSamplingInterval = 1000;
                }

                this.ShelvingState.OneShotShelve.OnCallMethod = OnOneShotShelve;
                this.ShelvingState.OneShotShelve.OnReadExecutable = IsOneShotShelveExecutable;
                this.ShelvingState.OneShotShelve.OnReadUserExecutable = IsOneShotShelveExecutable;

                this.ShelvingState.TimedShelve.OnCall = OnTimedShelve;
                this.ShelvingState.TimedShelve.OnReadExecutable = IsTimedShelveExecutable;
                this.ShelvingState.TimedShelve.OnReadUserExecutable = IsTimedShelveExecutable;

                this.ShelvingState.Unshelve.OnCallMethod = OnUnshelve;
                this.ShelvingState.Unshelve.OnReadExecutable = IsTimedShelveExecutable;
                this.ShelvingState.Unshelve.OnReadUserExecutable = IsTimedShelveExecutable;
            }
        }
 public NodeComponent(string myLevelName,string myLevelID,NodeState myNodeState,List<string> myConnectedTo)
 {
     this.name = "NodeComponent";
     levelName = myLevelName;
     id = myLevelID;
     nodeState = myNodeState;
 }
        /// <summary>
        /// Initializes the object as a collection of counters which change value on read.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            UpdateStateVariable(context, Objects.ExclusiveLimitStateMachineType_High, CurrentState);
            UpdateTransitionVariable(context, 0, LastTransition);
        }
Пример #8
0
        /// <summary>
        /// Applies coulomb repulsion to both points
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="k">coefficient of attraction</param>
        /// <param name="f1">Force at point a</param>
        /// <param name="f2">Force at point b</param>
        public static void ApplyCoulombRepulsion(NodeState a, NodeState b, double k)
        {
            double dx = a.Position.X - b.Position.X;
            double dy = a.Position.Y - b.Position.Y;
            double sqDist = dx * dx + dy * dy;
            if (sqDist == 0)
                return;
            double d = Math.Sqrt(sqDist);

            double mag = 1.0 / sqDist; // Force magnitude

            mag -= AttractionConstant * d; // plus WEAK attraction

            mag *= k;

            if (mag > MAGNITUDE_MAX)
                mag = MAGNITUDE_MAX; // Clip maximum

            double tempX = mag * (dx / d);
            double tempY = mag * (dy / d);

            if (!a.IsFrozen)
            {
                a.Force.X += tempX;
                a.Force.Y += tempY;
            }

            if (!b.IsFrozen)
            {
                b.Force.X -= tempX;
                b.Force.Y -= tempY;
            }
        }
        /// <summary>
        /// Initializes the object as a collection of counters which change value on read.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            this.Simulation.OnAfterTransition = OnControlSimulation;
            m_random = new Random();
        }
			public float findMaxUtility(NodeState futureState)
			{
				float maxUtility = float.MinValue;
		

				if (futureState.RValue != 0 && futureState.RValue > maxUtility  /*&& x_diff != -1*/) {
					maxUtility = futureState.RValue;
				}
				if (futureState.LValue != 0 && futureState.LValue > maxUtility /*&& x_diff != 1*/) {
						maxUtility = futureState.LValue;
				}
				if (futureState.FValue != 0 &&futureState.FValue > maxUtility /*&& z_diff != -1*/  ) {
						maxUtility = futureState.FValue;
				}
				if (futureState.BValue != 0 &&futureState.BValue > maxUtility/*  && z_diff != 1 */) {
						maxUtility = futureState.BValue;
				}

				if (maxUtility == float.MinValue) {
					maxUtility = float.Epsilon;
				}

				return maxUtility;

			}
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.Controllers.AStar.Node"/> class. 
 /// It set the positionI of the Node, set the node state to open and calculate the travel cost to the destination tile.
 /// </summary>
 /// <param name="location">Current PositionI of the Node.</param>
 /// <param name="endLocation">PositionI of the destination tile.</param>
 public Node(PositionI location, PositionI endLocation)
 {
     Location = location;
     State = NodeState.Open;
     H = GetTraversalCost(Location, endLocation);
     G = 0;
 }
Пример #12
0
        internal Node(string id, string name, NodeState state,	List<IPAddress> public_ips,
				List<IPAddress> private_ips, NodeDriver driver)
            : base(id, name, driver)
        {
            State = state;
            PublicIPs = public_ips;
            PrivateIPs = private_ips;
        }
Пример #13
0
 public PathNode(Vector2 point, bool isWalkable, Vector2 destination)
 {
     Point = point;
     this.State = NodeState.Untested;
     this.IsWalkable = isWalkable;
     this.H = GetTransversalCost(this.Point, destination);
     this.G = 0;
 }
Пример #14
0
		void AttachedNode_StateChanged(Node node, NodeState oldState)
		{
			if(!node.IsConnected)
			{
				_Parent._ConnectedNodes.Remove(AttachedNode);
				_Parent.StartConnecting();
			}
		}
        /// <summary>
        /// Called after a node is created.
        /// </summary>
        protected override void OnAfterCreate(ISystemContext context, NodeState node)
        {
            base.OnAfterCreate(context, node);

            if (this.Respond != null)
            {
                this.Respond.OnCall = OnRespondCalled;
            }
        }
Пример #16
0
        /// <summary>
        /// Initializes the instance with its defalt attribute values.
        /// </summary>
        public BaseObjectState(NodeState parent) : base(NodeClass.Object, parent)
        {
            m_eventNotifier = EventNotifiers.None;

            if (parent != null)
            {
                ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasComponent;
            }
        }
 /// <summary>
 /// Initializes the instance with the context for the node being monitored.
 /// </summary>
 public MonitoredNode(
     IServerInternal server,
     INodeManager nodeManager,
     NodeState node)
 {
     m_server = server;
     m_nodeManager = nodeManager;
     m_node = node;
 }
Пример #18
0
 void Update()
 {
     if(timeToLoneliness > 0) {
         timeToLoneliness -= Time.deltaTime;
         if(timeToLoneliness <= 0) {
             nodeState = NodeState.visited;
         }
     }
 }
Пример #19
0
 public NodeDescriptor(IAcDomain acDomain, NodeState node)
 {
     this._acDomain = acDomain;
     if (node == null)
     {
         throw new ArgumentNullException("node");
     }
     this.Node = node;
 }
Пример #20
0
 public OctreeNode(Vect3 center, Double size, NodeState state, int level, int maxLevel)
 {
     Center = center;
     Size = size;
     State = state;
     Level = level;
     MaxLevel = maxLevel;
     Children = Enumerable.Empty<OctreeNode>();
     Color = Color.Purple;
 }
Пример #21
0
 /// <summary>
 /// </summary>
 protected Node(string key, object value = null)
 {
     if (String.IsNullOrWhiteSpace(key))
     {
         throw new ArgumentNullException("key");
     }
     _key = key;
     _val = value;
     _state = value != null ? NodeState.Resolved : NodeState.Unresolved;
 }
        public void CreateNode(string myLevelName, string myLevelID, Vector2 myPosition, List<string> myConnectedTo, NodeState myNodeState, Texture2D myTexture)
        {
            Entity nodeEntity = new Entity(5, State.ScreenState.WORLD_MAP);
            nodeEntity.AddComponent(new SpriteComponent(true, myPosition, myTexture));
            nodeEntity.AddComponent(new ClickableComponent(myPosition,myTexture.Width,myTexture.Height));
            nodeEntity.AddComponent(new NodeComponent(myLevelName, myLevelID, myNodeState, myConnectedTo));

            AddNode(nodeEntity);
            EntityManager.AddEntity(nodeEntity);
        }
Пример #23
0
        /// <summary>
        /// Initializes the instance from another instance.
        /// </summary>
        protected override void Initialize(ISystemContext context, NodeState source)
        {
            BaseObjectState instance = source as BaseObjectState;

            if (instance != null)
            {
                m_eventNotifier = instance.m_eventNotifier;
            }

            base.Initialize(context, source);
        }
Пример #24
0
 public NodeStatus(string name, NodeState state, int tasksCount, DateTime timestamp, string machineName, int processId, long memory, NodeSettings nodeSettings)
 {
     Name = name;
     State = state;
     TasksCount = tasksCount;
     Timestamp = timestamp;
     MachineName = machineName;
     ProcessId = processId;
     Memory = memory;
     NodeSettings = nodeSettings;
 }
 private NodeDefinition CreateNodeFromSolutionFileData(SolutionFileData data, NodeState state)
 {
     return new NodeDefinition()
     {
         Id = "project.solution." + data.FileName,
         Name = Path.GetFileNameWithoutExtension(data.FileName),
         Path = data.FileName,
         State = state,
         Type = "project.solution"
     };
 }
Пример #26
0
 public Node(Guid connectionId, Guid nodeId, string host, int port, NodeState state, PersistentSubscriptionClient client, int maximumInFlightMessages, int assignmentCount)
 {
     ConnectionId = connectionId;
     NodeId = nodeId;
     Host = host;
     Port = port;
     State = state;
     Client = client;
     MaximumInFlightMessages = maximumInFlightMessages;
     AssignmentCount = assignmentCount;
 }
Пример #27
0
        /// <summary>
        /// Initializes the instance from another instance.
        /// </summary>
        protected override void Initialize(ISystemContext context, NodeState source)
        {
            MethodState method = source as MethodState;

            if (method != null)
            {
                m_executable = method.m_executable;
                m_userExecutable = method.m_userExecutable;
            }
            
            base.Initialize(context, source);
        }
Пример #28
0
        /// <summary>
        /// Initializes the instance from another instance.
        /// </summary>
        protected override void Initialize(ISystemContext context, NodeState source)
        {
            ReferenceTypeState type = source as ReferenceTypeState;

            if (type != null)
            {
                m_inverseName = type.m_inverseName;
                m_symmetric = type.m_symmetric;
            }

            base.Initialize(context, source);
        }
Пример #29
0
        /// <summary>
        /// Creates the NodeId for the specified node.
        /// </summary>
        public override NodeId New(ISystemContext context, NodeState node)
        {
            // generate a numeric node id if the node has a parent and no node id assigned.
            BaseInstanceState instance = node as BaseInstanceState;

            if (instance != null && instance.Parent != null)
            {
                return GenerateNodeId();
            }

            return node.NodeId;
        }
        /// <summary>
        /// Initializes the instance from another instance.
        /// </summary>
        protected override void Initialize(ISystemContext context, NodeState source)
        {
            ViewState instance = source as ViewState;

            if (instance != null)
            {
                m_eventNotifier = instance.m_eventNotifier;
                m_containsNoLoops = instance.m_containsNoLoops;
            }

            base.Initialize(context, source);
        }
Пример #31
0
 /// <summary>
 /// Removes all children from this node and modifies this node to be a UNIT
 /// node that is biddable.
 /// </summary>
 /// <returns>This node, updated to a biddable node.</returns>
 public ProductPartitionNode AsBiddableUnit()
 {
     nodeState = nodeState.TransitionTo(NodeType.BIDDABLE_UNIT);
     RemoveAllChildren();
     return(this);
 }
Пример #32
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private NodeStateReference NextChild(Stage stage)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext, false);

            DaElement element = null;

            if (stage == Stage.Children)
            {
                if (m_browser == null)
                {
                    return(null);
                }

                element = m_browser.Next();

                if (element == null)
                {
                    return(null);
                }

                // construct the node.
                NodeState node = DaModelUtils.ConstructElement(SystemContext, element, m_namespaceIndex);

                // return the reference.
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, node));
            }

            if (stage == Stage.Properties)
            {
                if (m_properties == null)
                {
                    return(null);
                }

                for (int ii = m_position; ii < m_properties.Length; ii++)
                {
                    if (m_properties[ii].PropertyId <= PropertyIds.TimeZone)
                    {
                        continue;
                    }

                    m_position = ii + 1;

                    // construct the node.
                    NodeState node = DaModelUtils.ConstructProperty(SystemContext, m_itemId, m_properties[ii], m_namespaceIndex);

                    // return the reference.
                    return(new NodeStateReference(ReferenceTypeIds.HasProperty, false, node));
                }

                // all done.
                return(null);
            }

            if (stage == Stage.Parents)
            {
                if (m_parentId != null)
                {
                    NodeId parentId = DaModelUtils.ConstructIdForDaElement(m_parentId, -1, m_namespaceIndex);
                    m_parentId = null;
                    return(new NodeStateReference(ReferenceTypeIds.Organizes, true, parentId));
                }
            }

            return(null);
        }
Пример #33
0
 /// <summary>
 /// Initializes the type with its default attribute values.
 /// </summary>
 public BikeState(NodeState parent) : base(parent)
 {
 }
Пример #34
0
        /// <summary>
        /// Collects instance declarations nodes from with a type.
        /// </summary>
        public static void CollectInstanceDeclarations(
            Session session,
            ComNamespaceMapper mapper,
            NodeState node,
            AeEventAttribute parent,
            List <AeEventAttribute> instances,
            IDictionary <string, AeEventAttribute> map)
        {
            List <BaseInstanceState> children = new List <BaseInstanceState>();

            node.GetChildren(session.SystemContext, children);

            if (children.Count == 0)
            {
                return;
            }

            // process the children.
            for (int ii = 0; ii < children.Count; ii++)
            {
                BaseInstanceState instance = children[ii];

                // only interested in objects and variables.
                if (instance.NodeClass != NodeClass.Object && instance.NodeClass != NodeClass.Variable)
                {
                    return;
                }

                // ignore instances without a modelling rule.
                if (NodeId.IsNull(instance.ModellingRuleId))
                {
                    return;
                }

                // create a new declaration.
                AeEventAttribute declaration = new AeEventAttribute();

                declaration.RootTypeId  = (parent != null)?parent.RootTypeId:node.NodeId;
                declaration.NodeId      = (NodeId)instance.NodeId;
                declaration.BrowseName  = instance.BrowseName;
                declaration.NodeClass   = instance.NodeClass;
                declaration.Description = (instance.Description != null)?instance.Description.ToString():null;

                // get data type information.
                BaseVariableState variable = instance as BaseVariableState;

                if (variable != null)
                {
                    declaration.DataType  = variable.DataType;
                    declaration.ValueRank = variable.ValueRank;

                    if (!NodeId.IsNull(variable.DataType))
                    {
                        declaration.BuiltInType = DataTypes.GetBuiltInType(declaration.DataType, session.TypeTree);
                    }
                }

                if (!LocalizedText.IsNullOrEmpty(instance.DisplayName))
                {
                    declaration.DisplayName = instance.DisplayName.Text;
                }
                else
                {
                    declaration.DisplayName = instance.BrowseName.Name;
                }

                if (parent != null)
                {
                    declaration.BrowsePath            = new QualifiedNameCollection(parent.BrowsePath);
                    declaration.BrowsePathDisplayText = Utils.Format("{0}/{1}", parent.BrowsePathDisplayText, mapper.GetLocalBrowseName(instance.BrowseName));
                    declaration.DisplayPath           = Utils.Format("{0}/{1}", parent.DisplayPath, instance.DisplayName);
                }
                else
                {
                    declaration.BrowsePath            = new QualifiedNameCollection();
                    declaration.BrowsePathDisplayText = Utils.Format("{0}", instance.BrowseName);
                    declaration.DisplayPath           = Utils.Format("{0}", instance.DisplayName);
                }

                declaration.BrowsePath.Add(instance.BrowseName);

                // check if reading an overridden declaration.
                AeEventAttribute overriden = null;

                if (map.TryGetValue(declaration.BrowsePathDisplayText, out overriden))
                {
                    declaration.OverriddenDeclaration = overriden;
                }

                map[declaration.BrowsePathDisplayText] = declaration;

                // only interested in variables.
                if (instance.NodeClass == NodeClass.Variable)
                {
                    instances.Add(declaration);
                }

                // recusively build tree.
                CollectInstanceDeclarations(session, mapper, instance, declaration, instances, map);
            }
        }
Пример #35
0
        /// <summary>
        /// Handles a write operation for an individual tag.
        /// </summary>
        public ServiceResult WriteTagValue(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            MemoryTagState tag = node as MemoryTagState;

            if (tag == null)
            {
                return(StatusCodes.BadNodeIdUnknown);
            }

            if (NumericRange.Empty != indexRange)
            {
                return(StatusCodes.BadIndexRangeInvalid);
            }

            if (!QualifiedName.IsNull(dataEncoding))
            {
                return(StatusCodes.BadDataEncodingUnsupported);
            }

            if (statusCode != StatusCodes.Good)
            {
                return(StatusCodes.BadWriteNotSupported);
            }

            if (timestamp != DateTime.MinValue)
            {
                return(StatusCodes.BadWriteNotSupported);
            }

            bool changed = false;
            int  offset  = (int)tag.Offset;

            lock (m_dataLock)
            {
                if (offset < 0 || offset >= m_buffer.Length)
                {
                    return(StatusCodes.BadNodeIdUnknown);
                }

                if (m_buffer == null)
                {
                    return(StatusCodes.BadOutOfService);
                }

                byte[] bytes = null;

                switch (m_elementType)
                {
                case BuiltInType.UInt32:
                {
                    uint?valueToWrite = value as uint?;

                    if (valueToWrite == null)
                    {
                        return(StatusCodes.BadTypeMismatch);
                    }

                    bytes = BitConverter.GetBytes(valueToWrite.Value);
                    break;
                }

                case BuiltInType.Double:
                {
                    double?valueToWrite = value as double?;

                    if (valueToWrite == null)
                    {
                        return(StatusCodes.BadTypeMismatch);
                    }

                    bytes = BitConverter.GetBytes(valueToWrite.Value);
                    break;
                }

                default:
                {
                    return(StatusCodes.BadNodeIdUnknown);
                }
                }

                for (int ii = 0; ii < bytes.Length; ii++)
                {
                    if (!changed)
                    {
                        if (m_buffer[offset + ii] != bytes[ii])
                        {
                            changed = true;
                        }
                    }

                    m_buffer[offset + ii] = bytes[ii];
                }
            }

            if (changed)
            {
                OnBufferChanged(offset);
            }

            return(ServiceResult.Good);
        }
Пример #36
0
 /// <summary>
 /// Initializes the type with its default attribute values.
 /// </summary>
 public MemoryTagState(NodeState parent) : base(parent)
 {
 }
 public void SetStatusOnNextUpdate(NodeState status)
 {
     statusOverride    = status;
     useStatusOverride = true;
 }
        private void fillCollector(NodeStateCollection nodes)
        {
            if (nodes.Equals(null))
            {
                createCollectorObject();
                return;
            }

            Dictionary <NodeId, NodeState> nodeDic = new Dictionary <NodeId, NodeState>();

            foreach (NodeState node in nodes)
            {
                nodeDic.Add(node.NodeId, node);
            }
            NodeState Controller = nodeDic[new NodeId((int)Collector.ObjectsIDs.ObjectController, NamespaceIndex)];

            //properties for addNamespace methodes

            Collector.ObjectsIDs[] methodsid =
            {
                Collector.ObjectsIDs.ObjectControlleraddNamespace,
                Collector.ObjectsIDs.ObjectControlleraddObjectNode,
                Collector.ObjectsIDs.ObjectControllergetObjectRootNode,
                Collector.ObjectsIDs.ObjectControllerauthenticate,
                Collector.ObjectsIDs.ObjectControllerregisterServer
            };
            foreach (Collector.ObjectsIDs n in methodsid)
            {
                GenericMethodCalledEventHandler m;
                MethodState addNamespaceMethod = (MethodState)nodeDic[new NodeId((ushort)n, NamespaceIndex)];
                NodeState   input  = nodeDic[new NodeId((ushort)(n + 1), NamespaceIndex)];
                NodeState   output = nodeDic[new NodeId((ushort)(n + 2), NamespaceIndex)];
                switch (n)
                {
                case Collector.ObjectsIDs.ObjectControlleraddNamespace:
                    m = method_addNamespace;
                    break;

                case Collector.ObjectsIDs.ObjectControlleraddObjectNode:
                    m = method_addObjectNode;
                    break;

                case Collector.ObjectsIDs.ObjectControllergetObjectRootNode:
                    m = method_getObjectRootNode;
                    break;

                case Collector.ObjectsIDs.ObjectControllerauthenticate:
                    m = method_authenticate;
                    break;

                case Collector.ObjectsIDs.ObjectControllerregisterServer:
                    m = method_registerServer;
                    break;

                default:
                    m = method_ControllerMethodStandard;
                    break;
                }
                createMethod(Controller, addNamespaceMethod, (PropertyState)input, (PropertyState)output, m);
            }
            //machines Folder
            machines = (BaseObjectState)nodeDic[new NodeId((int)Collector.ObjectsIDs.FolderMachines, NamespaceIndex)];
        }
Пример #39
0
 /// <summary>
 /// Initializes the type with its default attribute values.
 /// </summary>
 public MemoryBufferState(NodeState parent) : base(parent)
 {
 }
Пример #40
0
 void AttachedNode_StateChanged(Node node, NodeState oldState)
 {
     TrySync();
 }
Пример #41
0
 public FixedStateNode(NodeState returnState)
 {
     Status = returnState;
 }
Пример #42
0
        /// <summary>
        /// Checks if the node is in the view.
        /// </summary>
        protected override bool IsNodeInView(ServerSystemContext context, ContinuationPoint continuationPoint, NodeState node)
        {
            if (continuationPoint.View != null)
            {
                if (continuationPoint.View.ViewId == new NodeId(Model.Views.Engineering, NamespaceIndex))
                {
                    // suppress operations properties.
                    if (node != null && node.BrowseName.NamespaceIndex == NamespaceIndexes[2])
                    {
                        return(false);
                    }
                }

                if (continuationPoint.View.ViewId == new NodeId(Model.Views.Operations, NamespaceIndex))
                {
                    // suppress engineering properties.
                    if (node != null && node.BrowseName.NamespaceIndex == NamespaceIndexes[1])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #43
0
 public void SafeStart()
 {
     currentState = NodeState.RUNNING;
     node.Start();
 }
Пример #44
0
        /// <summary>
        /// Replaces the generic node with a node specific to the model.
        /// </summary>
        protected override NodeState AddBehaviourToPredefinedNode(
            ISystemContext context,
            NodeState predefinedNode)
        {
            BaseObjectState passiveNode = predefinedNode as BaseObjectState;

            if (passiveNode != null)
            {
                NodeId typeId = passiveNode.TypeDefinitionId;
                if (IsNodeIdInNamespace(typeId) && typeId.IdType == IdType.Numeric)
                {
                    switch ((uint)typeId.Identifier)
                    {
                    case ObjectTypes.ServerConfigurationType:
                    {
                        ServerConfigurationState activeNode = new ServerConfigurationState(passiveNode.Parent);
                        activeNode.Create(context, passiveNode);

                        m_serverConfigurationNode = activeNode;

                        // replace the node in the parent.
                        if (passiveNode.Parent != null)
                        {
                            passiveNode.Parent.ReplaceChild(context, activeNode);
                        }
                        return(activeNode);
                    }

                    case ObjectTypes.CertificateGroupFolderType:
                    {
                        CertificateGroupFolderState activeNode = new CertificateGroupFolderState(passiveNode.Parent);
                        activeNode.Create(context, passiveNode);

                        // delete unsupported groups
                        if (m_certificateGroups.All(group => group.BrowseName != activeNode.DefaultHttpsGroup?.BrowseName))
                        {
                            activeNode.DefaultHttpsGroup = null;
                        }
                        if (m_certificateGroups.All(group => group.BrowseName != activeNode.DefaultUserTokenGroup?.BrowseName))
                        {
                            activeNode.DefaultUserTokenGroup = null;
                        }
                        if (m_certificateGroups.All(group => group.BrowseName != activeNode.DefaultApplicationGroup?.BrowseName))
                        {
                            activeNode.DefaultApplicationGroup = null;
                        }

                        // replace the node in the parent.
                        if (passiveNode.Parent != null)
                        {
                            passiveNode.Parent.ReplaceChild(context, activeNode);
                        }
                        return(activeNode);
                    }

                    case ObjectTypes.CertificateGroupType:
                    {
                        var result = m_certificateGroups.FirstOrDefault(group => group.BrowseName == passiveNode.BrowseName);
                        if (result != null)
                        {
                            CertificateGroupState activeNode = new CertificateGroupState(passiveNode.Parent);
                            activeNode.Create(context, passiveNode);

                            result.NodeId = activeNode.NodeId;
                            result.Node   = activeNode;

                            // replace the node in the parent.
                            if (passiveNode.Parent != null)
                            {
                                passiveNode.Parent.ReplaceChild(context, activeNode);
                            }
                            return(activeNode);
                        }
                    }
                    break;
                    }
                }
            }
            return(base.AddBehaviourToPredefinedNode(context, predefinedNode));
        }
Пример #45
0
 private void Initialize()
 {
     currentState = NodeState.IDLE;
 }
Пример #46
0
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary <NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return(null);
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return(handle.Node);
            }

            NodeState target = null;

            // check if already in the cache.
            if (cache != null)
            {
                if (cache.TryGetValue(handle.NodeId, out target))
                {
                    // nulls mean a NodeId which was previously found to be invalid has been referenced again.
                    if (target == null)
                    {
                        return(null);
                    }

                    handle.Node      = target;
                    handle.Validated = true;
                    return(handle.Node);
                }

                target = null;
            }

            try
            {
                // check if the node id has been parsed.
                if (handle.ParsedNodeId == null)
                {
                    return(null);
                }

                NodeState root = null;

                // validate area.
                if (handle.ParsedNodeId.RootType == ModelUtils.Area)
                {
                    AreaState area = null;

                    if (!m_areas.TryGetValue(handle.ParsedNodeId.RootId, out area))
                    {
                        return(null);
                    }

                    root = area;
                }

                // validate soucre.
                else if (handle.ParsedNodeId.RootType == ModelUtils.Source)
                {
                    SourceState source = null;

                    if (!m_sources.TryGetValue(handle.ParsedNodeId.RootId, out source))
                    {
                        return(null);
                    }

                    root = source;
                }

                // unknown root type.
                else
                {
                    return(null);
                }

                // all done if no components to validate.
                if (String.IsNullOrEmpty(handle.ParsedNodeId.ComponentPath))
                {
                    handle.Validated = true;
                    handle.Node      = target = root;
                    return(handle.Node);
                }

                // validate component.
                NodeState component = root.FindChildBySymbolicName(context, handle.ParsedNodeId.ComponentPath);

                // component does not exist.
                if (component == null)
                {
                    return(null);
                }

                // found a valid component.
                handle.Validated = true;
                handle.Node      = target = component;
                return(handle.Node);
            }
            finally
            {
                // store the node in the cache to optimize subsequent lookups.
                if (cache != null)
                {
                    cache.Add(handle.NodeId, target);
                }
            }
        }
 public AdjustableStateNode(NodeState defaultState)
 {
     Status = defaultState;
 }
 public override void OnAfterNodeExecution(BT bt, NodeState state)
 {
     bt.BlackBoard.SetValue(key, value());
 }
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary <NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return(null);
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return(handle.Node);
            }

            NodeState target = null;

            // check if already in the cache.
            if (cache != null)
            {
                if (cache.TryGetValue(handle.NodeId, out target))
                {
                    // nulls mean a NodeId which was previously found to be invalid has been referenced again.
                    if (target == null)
                    {
                        return(null);
                    }

                    handle.Node      = target;
                    handle.Validated = true;
                    return(handle.Node);
                }

                target = null;
            }

            try {
                // check if the node id has been parsed.
                if (!(handle.ParsedNodeId is ParsedNodeId parsedNodeId))
                {
                    return(null);
                }

                NodeState root = null;

                // validate a segment.
                if (parsedNodeId.RootType == ModelUtils.Segment)
                {
                    var segment = _system.FindSegment(parsedNodeId.RootId);

                    // segment does not exist.
                    if (segment == null)
                    {
                        return(null);
                    }

                    var rootId = ModelUtils.ConstructIdForSegment(segment.Id, NamespaceIndex);

                    // create a temporary object to use for the operation.
                    root = new SegmentState(context, rootId, segment);
                }

                // validate segment.
                else if (parsedNodeId.RootType == ModelUtils.Block)
                {
                    // validate the block.
                    var block = _system.FindBlock(parsedNodeId.RootId);

                    // block does not exist.
                    if (block == null)
                    {
                        return(null);
                    }

                    var rootId = ModelUtils.ConstructIdForBlock(block.Id, NamespaceIndex);

                    // check for check for blocks that are being currently monitored.

                    if (_blocks.TryGetValue(rootId, out var node))
                    {
                        root = node;
                    }

                    // create a temporary object to use for the operation.
                    else
                    {
                        root = new BlockState(this, rootId, block);
                    }
                }

                // unknown root type.
                else
                {
                    return(null);
                }

                // all done if no components to validate.
                if (string.IsNullOrEmpty(parsedNodeId.ComponentPath))
                {
                    handle.Validated = true;
                    handle.Node      = target = root;
                    return(handle.Node);
                }

                // validate component.
                NodeState component = root.FindChildBySymbolicName(context, parsedNodeId.ComponentPath);

                // component does not exist.
                if (component == null)
                {
                    return(null);
                }

                // found a valid component.
                handle.Validated = true;
                handle.Node      = target = component;
                return(handle.Node);
            }
            finally {
                // store the node in the cache to optimize subsequent lookups.
                cache?.Add(handle.NodeId, target);
            }
        }
Пример #50
0
 /// <summary>
 /// Initializes the instance with a node.
 /// </summary>
 protected override void Initialize(ISystemContext context, NodeState source)
 {
     InitializeOptionalChildren(context);
     base.Initialize(context, source);
 }
Пример #51
0
 /// <summary>
 /// Creates the NodeId for the specified node.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="node">The node.</param>
 /// <returns>The new NodeId.</returns>
 /// <remarks>
 /// This method is called by the NodeState.Create() method which initializes a Node from
 /// the type model. During initialization a number of child nodes are created and need to
 /// have NodeIds assigned to them. This implementation constructs NodeIds by constructing
 /// strings. Other implementations could assign unique integers or Guids and save the new
 /// Node in a dictionary for later lookup.
 /// </remarks>
 public override NodeId New(ISystemContext context, NodeState node)
 {
     return(ModelUtils.ConstructIdForComponent(node, NamespaceIndex));
 }
Пример #52
0
        /// <summary>
        /// Adds a node to the set.
        /// </summary>
        public void Export(ISystemContext context, NodeState node, bool outputRedundantNames = true)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (Opc.Ua.NodeId.IsNull(node.NodeId))
            {
                throw new ArgumentException("A non-null NodeId must be specified.");
            }

            UANode exportedNode = null;

            switch (node.NodeClass)
            {
            case NodeClass.Object:
            {
                BaseObjectState o     = (BaseObjectState)node;
                UAObject        value = new UAObject();
                value.EventNotifier = o.EventNotifier;

                if (o.Parent != null)
                {
                    value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                }

                exportedNode = value;
                break;
            }

            case NodeClass.Variable:
            {
                BaseVariableState o     = (BaseVariableState)node;
                UAVariable        value = new UAVariable();
                value.DataType                = ExportAlias(o.DataType, context.NamespaceUris);
                value.ValueRank               = o.ValueRank;
                value.ArrayDimensions         = Export(o.ArrayDimensions);
                value.AccessLevel             = o.AccessLevelEx;
                value.MinimumSamplingInterval = o.MinimumSamplingInterval;
                value.Historizing             = o.Historizing;

                if (o.Parent != null)
                {
                    value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                }

                if (o.Value != null)
                {
                    XmlEncoder encoder = CreateEncoder(context);

                    Variant variant = new Variant(o.Value);
                    encoder.WriteVariantContents(variant.Value, variant.TypeInfo);

                    XmlDocument document = new XmlDocument();
                    document.InnerXml = encoder.Close();
                    value.Value       = document.DocumentElement;
                }

                exportedNode = value;
                break;
            }

            case NodeClass.Method:
            {
                MethodState o     = (MethodState)node;
                UAMethod    value = new UAMethod();
                value.Executable = o.Executable;

                if (o.TypeDefinitionId != o.NodeId)
                {
                    value.MethodDeclarationId = Export(o.TypeDefinitionId, context.NamespaceUris);
                }

                if (o.Parent != null)
                {
                    value.ParentNodeId = ExportAlias(o.Parent.NodeId, context.NamespaceUris);
                }

                exportedNode = value;
                break;
            }

            case NodeClass.View:
            {
                ViewState o     = (ViewState)node;
                UAView    value = new UAView();
                value.ContainsNoLoops = o.ContainsNoLoops;
                exportedNode          = value;
                break;
            }

            case NodeClass.ObjectType:
            {
                BaseObjectTypeState o     = (BaseObjectTypeState)node;
                UAObjectType        value = new UAObjectType();
                value.IsAbstract = o.IsAbstract;
                exportedNode     = value;
                break;
            }

            case NodeClass.VariableType:
            {
                BaseVariableTypeState o     = (BaseVariableTypeState)node;
                UAVariableType        value = new UAVariableType();
                value.IsAbstract      = o.IsAbstract;
                value.DataType        = ExportAlias(o.DataType, context.NamespaceUris);
                value.ValueRank       = o.ValueRank;
                value.ArrayDimensions = Export(o.ArrayDimensions);

                if (o.Value != null)
                {
                    XmlEncoder encoder = CreateEncoder(context);

                    Variant variant = new Variant(o.Value);
                    encoder.WriteVariantContents(variant.Value, variant.TypeInfo);

                    XmlDocument document = new XmlDocument();
                    document.InnerXml = encoder.Close();
                    value.Value       = document.DocumentElement;
                }

                exportedNode = value;
                break;
            }

            case NodeClass.DataType:
            {
                DataTypeState o     = (DataTypeState)node;
                UADataType    value = new UADataType();
                value.IsAbstract = o.IsAbstract;
                value.Definition = Export(o, o.DataTypeDefinition, context.NamespaceUris, outputRedundantNames);
                value.Purpose    = o.Purpose;
                exportedNode     = value;
                break;
            }

            case NodeClass.ReferenceType:
            {
                ReferenceTypeState o     = (ReferenceTypeState)node;
                UAReferenceType    value = new UAReferenceType();
                value.IsAbstract = o.IsAbstract;

                if (!Opc.Ua.LocalizedText.IsNullOrEmpty(o.InverseName))
                {
                    value.InverseName = Export(new Opc.Ua.LocalizedText[] { o.InverseName });
                }

                value.Symmetric = o.Symmetric;
                exportedNode    = value;
                break;
            }
            }

            exportedNode.NodeId     = Export(node.NodeId, context.NamespaceUris);
            exportedNode.BrowseName = Export(node.BrowseName, context.NamespaceUris);

            if (outputRedundantNames || node.DisplayName.Text != node.BrowseName.Name)
            {
                exportedNode.DisplayName = Export(new Opc.Ua.LocalizedText[] { node.DisplayName });
            }
            else
            {
                exportedNode.DisplayName = null;
            }

            if (node.Description != null && !String.IsNullOrEmpty(node.Description.Text))
            {
                exportedNode.Description = Export(new Opc.Ua.LocalizedText[] { node.Description });
            }
            else
            {
                exportedNode.Description = new LocalizedText[0];
            }

            exportedNode.Category      = (node.Categories != null && node.Categories.Count > 0) ? new List <string>(node.Categories).ToArray() : null;
            exportedNode.ReleaseStatus = node.ReleaseStatus;
            exportedNode.WriteMask     = (uint)node.WriteMask;
            exportedNode.UserWriteMask = (uint)node.UserWriteMask;

            if (!String.IsNullOrEmpty(node.SymbolicName) && node.SymbolicName != node.BrowseName.Name)
            {
                exportedNode.SymbolicName = node.SymbolicName;
            }

            // export references.
            INodeBrowser     browser            = node.CreateBrowser(context, null, null, true, BrowseDirection.Both, null, null, true);
            List <Reference> exportedReferences = new List <Reference>();
            IReference       reference          = browser.Next();

            while (reference != null)
            {
                if (node.NodeClass == NodeClass.Method)
                {
                    if (!reference.IsInverse && reference.ReferenceTypeId == ReferenceTypeIds.HasTypeDefinition)
                    {
                        reference = browser.Next();
                        continue;
                    }
                }

                Reference exportedReference = new Reference();

                exportedReference.ReferenceType = ExportAlias(reference.ReferenceTypeId, context.NamespaceUris);
                exportedReference.IsForward     = !reference.IsInverse;
                exportedReference.Value         = Export(reference.TargetId, context.NamespaceUris, context.ServerUris);
                exportedReferences.Add(exportedReference);

                reference = browser.Next();
            }

            exportedNode.References = exportedReferences.ToArray();

            // add node to list.
            UANode[] nodes = null;

            int count = 1;

            if (this.Items == null)
            {
                nodes = new UANode[count];
            }
            else
            {
                count += this.Items.Length;
                nodes  = new UANode[count];
                Array.Copy(this.Items, nodes, this.Items.Length);
            }

            nodes[count - 1] = exportedNode;

            this.Items = nodes;

            // recusively process children.
            List <BaseInstanceState> children = new List <BaseInstanceState>();

            node.GetChildren(context, children);

            for (int ii = 0; ii < children.Count; ii++)
            {
                Export(context, children[ii], outputRedundantNames);
            }
        }
Пример #53
0
 public virtual void Reset()
 {
     currentState = NodeState.RUNNING;
 }
Пример #54
0
 public void FinishWithFailure()
 {
     currentState = NodeState.FAILURE;
 }
Пример #55
0
 public void AddPredefinedNodeExt(ISystemContext context, NodeState node)
 {
     base.AddPredefinedNode(context, node);
 }
Пример #56
0
 public void FinishWithSuccess()
 {
     currentState = NodeState.SUCCESS;
 }
Пример #57
0
 public EnteringState(NodeState nodeState)
 {
     NodeState = nodeState;
 }
Пример #58
0
 public void SafeEnd()
 {
     currentState = NodeState.IDLE;
     node.End();
 }
Пример #59
0
        /// <summary>
        /// Imports a node from the set.
        /// </summary>
        private NodeState Import(ISystemContext context, UANode node)
        {
            NodeState importedNode = null;

            NodeClass nodeClass = NodeClass.Unspecified;

            if (node is UAObject)
            {
                nodeClass = NodeClass.Object;
            }
            else if (node is UAVariable)
            {
                nodeClass = NodeClass.Variable;
            }
            else if (node is UAMethod)
            {
                nodeClass = NodeClass.Method;
            }
            else if (node is UAObjectType)
            {
                nodeClass = NodeClass.ObjectType;
            }
            else if (node is UAVariableType)
            {
                nodeClass = NodeClass.VariableType;
            }
            else if (node is UADataType)
            {
                nodeClass = NodeClass.DataType;
            }
            else if (node is UAReferenceType)
            {
                nodeClass = NodeClass.ReferenceType;
            }
            else if (node is UAView)
            {
                nodeClass = NodeClass.View;
            }

            switch (nodeClass)
            {
            case NodeClass.Object:
            {
                UAObject        o     = (UAObject)node;
                BaseObjectState value = new BaseObjectState(null);
                value.EventNotifier = o.EventNotifier;
                importedNode        = value;
                break;
            }

            case NodeClass.Variable:
            {
                UAVariable o = (UAVariable)node;

                NodeId typeDefinitionId = null;

                if (node.References != null)
                {
                    for (int ii = 0; ii < node.References.Length; ii++)
                    {
                        Opc.Ua.NodeId         referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true);
                        bool                  isInverse       = !node.References[ii].IsForward;
                        Opc.Ua.ExpandedNodeId targetId        = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris);

                        if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse)
                        {
                            typeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            break;
                        }
                    }
                }

                BaseVariableState value = null;

                if (typeDefinitionId == Opc.Ua.VariableTypeIds.PropertyType)
                {
                    value = new PropertyState(null);
                }
                else
                {
                    value = new BaseDataVariableState(null);
                }

                value.DataType                = ImportNodeId(o.DataType, context.NamespaceUris, true);
                value.ValueRank               = o.ValueRank;
                value.ArrayDimensions         = ImportArrayDimensions(o.ArrayDimensions);
                value.AccessLevelEx           = o.AccessLevel;
                value.UserAccessLevel         = (byte)(o.AccessLevel & 0xFF);
                value.MinimumSamplingInterval = o.MinimumSamplingInterval;
                value.Historizing             = o.Historizing;

                if (o.Value != null)
                {
                    XmlDecoder decoder  = CreateDecoder(context, o.Value);
                    TypeInfo   typeInfo = null;
                    value.Value = decoder.ReadVariantContents(out typeInfo);
                    decoder.Close();
                }

                importedNode = value;
                break;
            }

            case NodeClass.Method:
            {
                UAMethod    o     = (UAMethod)node;
                MethodState value = new MethodState(null);
                value.Executable       = o.Executable;
                value.UserExecutable   = o.Executable;
                value.TypeDefinitionId = ImportNodeId(o.MethodDeclarationId, context.NamespaceUris, true);
                importedNode           = value;
                break;
            }

            case NodeClass.View:
            {
                UAView    o     = (UAView)node;
                ViewState value = new ViewState();
                value.ContainsNoLoops = o.ContainsNoLoops;
                importedNode          = value;
                break;
            }

            case NodeClass.ObjectType:
            {
                UAObjectType        o     = (UAObjectType)node;
                BaseObjectTypeState value = new BaseObjectTypeState();
                value.IsAbstract = o.IsAbstract;
                importedNode     = value;
                break;
            }

            case NodeClass.VariableType:
            {
                UAVariableType        o     = (UAVariableType)node;
                BaseVariableTypeState value = new BaseDataVariableTypeState();
                value.IsAbstract      = o.IsAbstract;
                value.DataType        = ImportNodeId(o.DataType, context.NamespaceUris, true);
                value.ValueRank       = o.ValueRank;
                value.ArrayDimensions = ImportArrayDimensions(o.ArrayDimensions);

                if (o.Value != null)
                {
                    XmlDecoder decoder  = CreateDecoder(context, o.Value);
                    TypeInfo   typeInfo = null;
                    value.Value = decoder.ReadVariantContents(out typeInfo);
                    decoder.Close();
                }

                importedNode = value;
                break;
            }

            case NodeClass.DataType:
            {
                UADataType    o     = (UADataType)node;
                DataTypeState value = new DataTypeState();
                value.IsAbstract = o.IsAbstract;
                Opc.Ua.DataTypeDefinition dataTypeDefinition = Import(o, o.Definition, context.NamespaceUris);
                value.DataTypeDefinition = new ExtensionObject(dataTypeDefinition);
                value.Purpose            = o.Purpose;
                value.DataTypeModifier   = DataTypeModifier.None;

                if (o.Definition != null)
                {
                    if (o.Definition.IsOptionSet)
                    {
                        value.DataTypeModifier = DataTypeModifier.OptionSet;
                    }
                    else if (o.Definition.IsUnion)
                    {
                        value.DataTypeModifier = DataTypeModifier.Union;
                    }
                }

                importedNode = value;
                break;
            }

            case NodeClass.ReferenceType:
            {
                UAReferenceType    o     = (UAReferenceType)node;
                ReferenceTypeState value = new ReferenceTypeState();
                value.IsAbstract  = o.IsAbstract;
                value.InverseName = Import(o.InverseName);
                value.Symmetric   = o.Symmetric;
                importedNode      = value;
                break;
            }
            }

            importedNode.NodeId      = ImportNodeId(node.NodeId, context.NamespaceUris, false);
            importedNode.BrowseName  = ImportQualifiedName(node.BrowseName, context.NamespaceUris);
            importedNode.DisplayName = Import(node.DisplayName);

            if (importedNode.DisplayName == null)
            {
                importedNode.DisplayName = new Ua.LocalizedText(importedNode.BrowseName.Name);
            }

            importedNode.Description   = Import(node.Description);
            importedNode.Categories    = (node.Category != null && node.Category.Length > 0) ? node.Category : null;
            importedNode.ReleaseStatus = node.ReleaseStatus;
            importedNode.WriteMask     = (AttributeWriteMask)node.WriteMask;
            importedNode.UserWriteMask = (AttributeWriteMask)node.UserWriteMask;

            if (!String.IsNullOrEmpty(node.SymbolicName))
            {
                importedNode.SymbolicName = node.SymbolicName;
            }

            if (node.References != null)
            {
                BaseInstanceState instance = importedNode as BaseInstanceState;
                BaseTypeState     type     = importedNode as BaseTypeState;

                for (int ii = 0; ii < node.References.Length; ii++)
                {
                    Opc.Ua.NodeId         referenceTypeId = ImportNodeId(node.References[ii].ReferenceType, context.NamespaceUris, true);
                    bool                  isInverse       = !node.References[ii].IsForward;
                    Opc.Ua.ExpandedNodeId targetId        = ImportExpandedNodeId(node.References[ii].Value, context.NamespaceUris, context.ServerUris);

                    if (instance != null)
                    {
                        if (referenceTypeId == ReferenceTypeIds.HasModellingRule && !isInverse)
                        {
                            instance.ModellingRuleId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            continue;
                        }

                        if (referenceTypeId == ReferenceTypeIds.HasTypeDefinition && !isInverse)
                        {
                            instance.TypeDefinitionId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            continue;
                        }
                    }

                    if (type != null)
                    {
                        if (referenceTypeId == ReferenceTypeIds.HasSubtype && isInverse)
                        {
                            type.SuperTypeId = Opc.Ua.ExpandedNodeId.ToNodeId(targetId, context.NamespaceUris);
                            continue;
                        }
                    }

                    importedNode.AddReference(referenceTypeId, isInverse, targetId);
                }
            }

            return(importedNode);
        }
Пример #60
0
 /// <summary>
 /// Modifies this node to be a SUBDIVISION node.
 /// </summary>
 /// <returns>This node, updated to a subdivision node.</returns>
 public ProductPartitionNode AsSubdivision()
 {
     nodeState = nodeState.TransitionTo(NodeType.SUBDIVISION);
     return(this);
 }