예제 #1
0
 /// <inheritdoc/>
 public void WriteQualifiedName(string property, QualifiedName value)
 {
     if (QualifiedName.IsNull(value))
     {
         WriteNull(property);
     }
     else if (UseReversibleEncoding)
     {
         if (UseUriEncoding || UseAdvancedEncoding)
         {
             WriteString(property, value.AsString(Context));
         }
         else
         {
             // Back compat to json encoding
             PushObject(property);
             WriteString("Name", value.Name);
             if (value.NamespaceIndex > 0)
             {
                 WriteUInt16("Uri", value.NamespaceIndex);
             }
             PopObject();
         }
     }
     else
     {
         PushObject(property);
         WriteString("Name", value.Name);
         WriteNamespaceIndex(value.NamespaceIndex);
         PopObject();
     }
 }
예제 #2
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            // check if a specific browse name is requested.
            if (QualifiedName.IsNull(base.BrowseName))
            {
                return(NextChild(m_stage));
            }

            // keep fetching references until a matching browse name if found.
            NodeStateReference reference = null;

            do
            {
                reference = NextChild(m_stage);

                if (reference != null)
                {
                    // need to let the caller look up the browse name.
                    if (reference.Target == null)
                    {
                        return(reference);
                    }

                    // check for browse name match.
                    if (reference.Target.BrowseName == base.BrowseName)
                    {
                        return(reference);
                    }
                }
            }while (reference != null);

            // no match - need to go onto the next stage.
            return(null);
        }
 /// <summary>
 /// Finds the child with the specified browse name.
 /// </summary>
 /// <param name="context">The context for the system being accessed.</param>
 /// <param name="browseName">The browse name of the children to add.</param>
 /// <param name="createOrReplace">if set to <c>true</c> and the child could exist then the child is created.</param>
 /// <param name="replacement">The replacement to use if createOrReplace is true.</param>
 /// <returns>The child.</returns>
 protected virtual BaseInstanceState FindChild(ISystemContext context, QualifiedName browseName, bool createOrReplace, BaseInstanceState replacement)
 {
     if (QualifiedName.IsNull(browseName))
     {
         return(null);
     }
     for (int ii = 0; ii < m_children.Count; ii++)
     {
         BaseInstanceState child = m_children[ii];
         if (browseName == child.BrowseName)
         {
             if (createOrReplace && replacement != null)
             {
                 m_children[ii] = child = replacement;
             }
             return(child);
         }
     }
     if (createOrReplace)
     {
         if (replacement != null)
         {
             AddChild(replacement);
         }
     }
     return(null);
 }
예제 #4
0
        /// <summary>
        /// Adds a DataValue to a list of values to return.
        /// </summary>
        private void AddValue(
            TimestampsToReturn timestampsToReturn,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            DataValueCollection values,
            DataValue value)
        {
            // ignore invalid case.
            if (value == null)
            {
                return;
            }

            // save the last timestamp returned.
            m_lastTime = value.ServerTimestamp;

            // check if the index range or data encoding can be applied.
            if (StatusCode.IsGood(value.StatusCode))
            {
                object valueToReturn = value.Value;

                // apply the index range.
                if (indexRange != NumericRange.Empty)
                {
                    StatusCode error = indexRange.ApplyRange(ref valueToReturn);

                    if (StatusCode.IsBad(error))
                    {
                        value.Value      = null;
                        value.StatusCode = error;
                    }
                    else
                    {
                        value.Value = valueToReturn;
                    }
                }

                // apply the data encoding.
                if (!QualifiedName.IsNull(dataEncoding))
                {
                    value.Value      = null;
                    value.StatusCode = StatusCodes.BadDataEncodingUnsupported;
                }
            }

            // apply the timestamps filter.
            if (timestampsToReturn == TimestampsToReturn.Neither || timestampsToReturn == TimestampsToReturn.Server)
            {
                value.SourceTimestamp = DateTime.MinValue;
            }

            if (timestampsToReturn == TimestampsToReturn.Neither || timestampsToReturn == TimestampsToReturn.Source)
            {
                value.ServerTimestamp = DateTime.MinValue;
            }

            // add result.
            values.Add(value);
        }
예제 #5
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            // check if a specific browse name is requested.
            if (!QualifiedName.IsNull(base.BrowseName))
            {
                // check if match found previously.
                if (m_position == Int32.MaxValue)
                {
                    return(null);
                }

                // look for matching reference.
                if (m_stage != Stage.Done)
                {
                    do
                    {
                        while (m_references != null && m_position < m_references.Count)
                        {
                            ReferenceDescription reference = m_references[m_position++];

                            if (m_mapper.ToLocalName(reference.BrowseName) == this.BrowseName)
                            {
                                if (m_source != null || (reference.NodeId != ObjectIds.ObjectsFolder && reference.NodeId != ObjectIds.Server))
                                {
                                    return(ToReference(reference));
                                }
                            }
                        }
                    }while (BrowseNext());
                }
            }

            // return the child at the next position.
            else
            {
                if (m_stage != Stage.Done)
                {
                    do
                    {
                        while (m_references != null && m_position < m_references.Count)
                        {
                            ReferenceDescription reference = m_references[m_position++];

                            if (m_source != null || (reference.NodeId != ObjectIds.ObjectsFolder && reference.NodeId != ObjectIds.Server))
                            {
                                return(ToReference(reference));
                            }
                        }
                    }while (BrowseNext());
                }
            }

            return(null);
        }
예제 #6
0
        /// <summary>
        /// Handles the read operation for an invidual tag.
        /// </summary>
        public ServiceResult ReadTagValue(
#pragma warning disable RECS0154 // Parameter is never used
#pragma warning disable IDE0060  // Remove unused parameter
            ISystemContext context,
#pragma warning restore IDE0060  // Remove unused parameter
#pragma warning restore RECS0154 // Parameter is never used
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            if (!(node is MemoryTagState tag))
            {
                return(StatusCodes.BadNodeIdUnknown);
            }

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

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

            var offset = (int)tag.Offset;

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

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

                value = GetValueAtOffset(offset).Value;
            }

            statusCode = StatusCodes.Good;
            timestamp  = _lastScanTime;

            return(ServiceResult.Good);
        }
예제 #7
0
        /// <summary>
        /// Updates this instance in case the wrapped <see cref="UANode" /> is recognized in the model.
        /// </summary>
        /// <param name="node">The node <see cref="UANode" /> containing definition to be added to the model.</param>
        /// <param name="addReference">Used to add new reference to the common collection of references.</param>
        /// <exception cref="ArgumentException">node - Argument must not be null</exception>
        public void Update(UANode node, Action <UAReferenceContext> addReference)
        {
            if (node == null)
            {
                throw new ArgumentException(nameof(node), $"Argument must not be null at {nameof(Update)} ");
            }
            if (this.UANode != null)
            {
                Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NodeIdDuplicated, string.Format("The {0} is already defined and is removed from further processing.", node.NodeId.ToString())));
                return;
            }
            UANode          = node;
            this.BrowseName = node.BrowseName.Parse(Log.TraceEvent);
            if (QualifiedName.IsNull(this.BrowseName))
            {
                NodeId _id = NodeId.Parse(UANode.NodeId);
                this.BrowseName = new QualifiedName($"EmptyBrowseName_{_id.IdentifierPart}", _id.NamespaceIndex);
                Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, $"New identifier {this.BrowseName} is generated to proceed."));
            }
            if (node.References == null)
            {
                return;
            }
            foreach (Reference _reference in node.References)
            {
                UAReferenceContext _newReference = new UAReferenceContext(_reference, this.m_AddressSpaceContext, this);
                switch (_newReference.ReferenceKind)
                {
                case ReferenceKindEnum.Custom:
                case ReferenceKindEnum.HasComponent:
                case ReferenceKindEnum.HasProperty:
                    break;

                case ReferenceKindEnum.HasModellingRule:
                    ModelingRule = _newReference.GetModelingRule();
                    break;

                case ReferenceKindEnum.HasSubtype: //TODO Part 3 7.10 HasSubtype - add test cases #35
                    m_BaseTypeNode = _newReference.SourceNode;
                    break;

                case ReferenceKindEnum.HasTypeDefinition: //Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
                    m_BaseTypeNode = _newReference.TargetNode;
                    break;
                }
                addReference(_newReference);
            }
        }
예제 #8
0
        /// <summary>
        /// Reads the attributes.
        /// </summary>
        protected override void Read(
            RequestContext context,
            TransactionHandle transaction,
            IList <NodeAttributeOperationHandle> operationHandles,
            IList <ReadValueId> settings)
        {
            for (int ii = 0; ii < operationHandles.Count; ii++)
            {
                DataValue dv = null;

                // the data passed to CreateVariable is returned as the UserData in the handle.
                SystemAddress address = operationHandles[ii].NodeHandle.UserData as SystemAddress;

                if (address != null)
                {
                    // read the data from the underlying system.
                    object value = m_system.Read(address.Address, address.Offset);

                    if (value != null)
                    {
                        dv = new DataValue(new Variant(value, null), DateTime.UtcNow);

                        // apply any index range or encoding.
                        if (!String.IsNullOrEmpty(settings[ii].IndexRange) || !QualifiedName.IsNull(settings[ii].DataEncoding))
                        {
                            dv = ApplyIndexRangeAndEncoding(
                                operationHandles[ii].NodeHandle,
                                dv,
                                settings[ii].IndexRange,
                                settings[ii].DataEncoding);
                        }
                    }
                }

                // set an error if not found.
                if (dv == null)
                {
                    dv = new DataValue(new StatusCode(StatusCodes.BadNodeIdUnknown));
                }

                // return the data to the caller.
                ((ReadCompleteEventHandler)transaction.Callback)(
                    operationHandles[ii],
                    transaction.CallbackData,
                    dv,
                    false);
            }
        }
예제 #9
0
        /// <summary>
        /// Handles the read operation for an invidual tag.
        /// </summary>
        public ServiceResult ReadTagValue(
            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.BadDataEncodingInvalid);
            }

            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);
                }

                value = GetValueAtOffset(offset).Value;
            }

            statusCode = StatusCodes.Good;
            timestamp  = m_lastScanTime;

            return(ServiceResult.Good);
        }
예제 #10
0
        private ServiceResult ApplyIndexRangeAndDataEncoding(
            ISystemContext context,
            ReadValueId nodeToRead,
            DataValue value)
        {
            if (StatusCode.IsBad(value.StatusCode))
            {
                return(value.StatusCode);
            }

            if (nodeToRead.ParsedIndexRange != NumericRange.Empty || !QualifiedName.IsNull(nodeToRead.DataEncoding))
            {
                if (nodeToRead.AttributeId != Attributes.Value && !QualifiedName.IsNull(nodeToRead.DataEncoding))
                {
                    return(StatusCodes.BadDataEncodingInvalid);
                }

                object valueToUpdate = value.Value;

                ServiceResult result = BaseVariableState.ApplyIndexRangeAndDataEncoding(
                    context,
                    nodeToRead.ParsedIndexRange,
                    nodeToRead.DataEncoding,
                    ref valueToUpdate);

                if (ServiceResult.IsBad(result))
                {
                    bool useXml = nodeToRead.DataEncoding.Name == DefaultXml;

                    if (!useXml &&
                        !string.IsNullOrEmpty(nodeToRead.DataEncoding.Name) &&
                        nodeToRead.DataEncoding.Name != DefaultBinary)
                    {
                        result = StatusCodes.BadDataEncodingInvalid;
                    }

                    value.Value      = null;
                    value.StatusCode = result.StatusCode;
                    return(result);
                }

                value.Value = valueToUpdate;
            }

            return(value.StatusCode);
        }
        /// <summary>
        /// Updates this instance in case the wrapped <see cref="UANode"/> is recognized in the model.
        /// </summary>
        /// <param name="node">The node <see cref="UANode"/> containing definition to be added to the model.</param>
        /// <param name="traceEvent">A delegate <see cref="Action{TraceMessage}"/> encapsulates an action to report any errors and trace processing progress.</param>
        internal void Update(UANode node, Action <TraceMessage> traceEvent)
        {
            if (node == null)
            {
                return;
            }
            m_UAnode = node;
            QualifiedName _broseName = node.BrowseName.Parse(traceEvent);

            Debug.Assert(m_BrowseName != null);
            if (QualifiedName.IsNull(_broseName))
            {
                NodeId _id = NodeId.Parse(UANode.NodeId);
                _broseName = new QualifiedName(string.Format("EmptyBrowseName{0}", _id.IdentifierPart), _id.NamespaceIndex);
                traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, String.Format("New identifier {0} is generated to proceed.", _broseName)));
            }
            m_BrowseName = m_ModelContext.ImportQualifiedName(_broseName);
        }
예제 #12
0
        /// <summary>
        /// Updates this instance in case the wrapped <see cref="UANode"/> is recognized in the model.
        /// </summary>
        /// <param name="node">The node <see cref="UANode"/> containing definition to be added to the model.</param>
        void IUANodeContext.Update(UANode node)
        {
            if (node == null)
            {
                return;
            }
            UANode = node;
            QualifiedName _broseName = node.BrowseName.Parse(BuildErrorsHandling.Log.TraceEvent);

            Debug.Assert(BrowseName != null);
            if (QualifiedName.IsNull(_broseName))
            {
                NodeId _id = NodeId.Parse(UANode.NodeId);
                _broseName = new QualifiedName(string.Format("EmptyBrowseName{0}", _id.IdentifierPart), _id.NamespaceIndex);
                BuildErrorsHandling.Log.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.EmptyBrowseName, string.Format("New identifier {0} is generated to proceed.", _broseName)));
            }
            BrowseName = UAModelContext.ImportQualifiedName(_broseName);
        }
예제 #13
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case OpcUaChatServer.BrowseNames.ChatLog:
            {
                if (createOrReplace)
                {
                    if (ChatLog == null)
                    {
                        if (replacement == null)
                        {
                            ChatLog = new ChatLogState(this);
                        }
                        else
                        {
                            ChatLog = (ChatLogState)replacement;
                        }
                    }
                }

                instance = ChatLog;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
예제 #14
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case ITSOPCCourseCode.OPCUA.SampleServer.BrowseNames.CurrentSpeed:
            {
                if (createOrReplace)
                {
                    if (CurrentSpeed == null)
                    {
                        if (replacement == null)
                        {
                            CurrentSpeed = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            CurrentSpeed = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = CurrentSpeed;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Opc.Ua.CNC.BrowseNames.CncAxisList:
            {
                if (createOrReplace)
                {
                    if (CncAxisList == null)
                    {
                        if (replacement == null)
                        {
                            CncAxisList = new CncAxisListState(this);
                        }
                        else
                        {
                            CncAxisList = (CncAxisListState)replacement;
                        }
                    }
                }

                instance = CncAxisList;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
예제 #16
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case TutorialModel.BrowseNames.Input:
            {
                if (createOrReplace)
                {
                    if (Input == null)
                    {
                        if (replacement == null)
                        {
                            Input = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            Input = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = Input;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
예제 #17
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case VariableTypeTest.BrowseNames.VariableChild:
            {
                if (createOrReplace)
                {
                    if (VariableChild == null)
                    {
                        if (replacement == null)
                        {
                            VariableChild = new PropertyState <int>(this);
                        }
                        else
                        {
                            VariableChild = (PropertyState <int>)replacement;
                        }
                    }
                }

                instance = VariableChild;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case BoilerModel.BrowseNames.BoilerStatus:
            {
                if (createOrReplace)
                {
                    if (BoilerStatus == null)
                    {
                        if (replacement == null)
                        {
                            BoilerStatus = new BaseDataVariableState <BoilerDataType>(this);
                        }
                        else
                        {
                            BoilerStatus = (BaseDataVariableState <BoilerDataType>)replacement;
                        }
                    }
                }

                instance = BoilerStatus;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
예제 #19
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Quickstarts.SimpleEvents.BrowseNames.Error:
            {
                if (createOrReplace)
                {
                    if (Error == null)
                    {
                        if (replacement == null)
                        {
                            Error = new PropertyState <StatusCode>(this);
                        }
                        else
                        {
                            Error = (PropertyState <StatusCode>)replacement;
                        }
                    }
                }

                instance = Error;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case CAS.UA.Server.DataSource.Isotherm.Model.BrowseNames.ArrayVariableInstanceDeclaration:
            {
                if (createOrReplace)
                {
                    if (ArrayVariableInstanceDeclaration == null)
                    {
                        if (replacement == null)
                        {
                            ArrayVariableInstanceDeclaration = new BaseDataVariableState <StructureExample[]>(this);
                        }
                        else
                        {
                            ArrayVariableInstanceDeclaration = (BaseDataVariableState <StructureExample[]>)replacement;
                        }
                    }
                }

                instance = ArrayVariableInstanceDeclaration;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
예제 #21
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Quickstarts.SimpleEvents.BrowseNames.Steps:
            {
                if (createOrReplace)
                {
                    if (Steps == null)
                    {
                        if (replacement == null)
                        {
                            Steps = new PropertyState <CycleStepDataType[]>(this);
                        }
                        else
                        {
                            Steps = (PropertyState <CycleStepDataType[]>)replacement;
                        }
                    }
                }

                instance = Steps;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case animal.BrowseNames.Weight:
            {
                if (createOrReplace)
                {
                    if (Weight == null)
                    {
                        if (replacement == null)
                        {
                            Weight = new PropertyState <double>(this);
                        }
                        else
                        {
                            Weight = (PropertyState <double>)replacement;
                        }
                    }
                }

                instance = Weight;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case Opc.Ua.Di.BrowseNames.ParameterSet:
            {
                if (createOrReplace)
                {
                    if (ParameterSet == null)
                    {
                        if (replacement == null)
                        {
                            ParameterSet = new BaseObjectState(this);
                        }
                        else
                        {
                            ParameterSet = (BaseObjectState)replacement;
                        }
                    }
                }

                instance = ParameterSet;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
예제 #24
0
        /// <summary>
        /// Converts a remote QualifiedName to a local QualifiedName.
        /// </summary>
        private QualifiedName ToName(QualifiedName name, int[] namespaceIndexes)
        {
            if (QualifiedName.IsNull(name))
            {
                return(QualifiedName.Null);
            }

            if (name.NamespaceIndex == 0)
            {
                return(name);
            }

            if (namespaceIndexes.Length <= name.NamespaceIndex)
            {
                return(QualifiedName.Null);
            }

            return(new QualifiedName(name.Name, (ushort)namespaceIndexes[name.NamespaceIndex]));
        }
예제 #25
0
        /// <summary>
        /// Reads the attributes.
        /// </summary>
        protected override void Read(
            RequestContext context,
            TransactionHandle transaction,
            IList <NodeAttributeOperationHandle> operationHandles,
            IList <ReadValueId> settings)
        {
            for (int ii = 0; ii < operationHandles.Count; ii++)
            {
                DataValue dv = null;

                // the data passed to CreateVariable is returned as the UserData in the handle.
                if (operationHandles[ii].NodeHandle.UserData is Tuple <Func <object>, Action <object> > accessors)
                {
                    var getter = accessors.Item1;

                    dv = new DataValue(new Variant(getter(), null), DateTime.UtcNow);

                    // apply any index range or encoding.
                    if (!string.IsNullOrEmpty(settings[ii].IndexRange) || !QualifiedName.IsNull(settings[ii].DataEncoding))
                    {
                        dv = ApplyIndexRangeAndEncoding(
                            operationHandles[ii].NodeHandle,
                            dv,
                            settings[ii].IndexRange,
                            settings[ii].DataEncoding);
                    }
                }

                // set an error if not found.
                if (dv == null)
                {
                    dv = new DataValue(new StatusCode(StatusCodes.BadNodeIdUnknown));
                }

                // return the data to the caller.
                ((ReadCompleteEventHandler)transaction.Callback)(
                    operationHandles[ii],
                    transaction.CallbackData,
                    dv,
                    false);
            }
        }
        /// <summary>
        /// Gets the local name for the qualified name,
        /// </summary>
        /// <param name="browseName">The remote qualified name.</param>
        /// <returns></returns>
        public string GetLocalBrowseName(QualifiedName browseName)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(String.Empty);
            }

            ushort namespaceIndex = GetLocalNamespaceIndex(browseName.NamespaceIndex);
            string name           = browseName.Name;

            int index = name.IndexOfAny(s_BrowseNameEscapedChars);

            if (index != -1)
            {
                StringBuilder buffer = new StringBuilder(name.Length);
                buffer.Append(namespaceIndex);
                buffer.Append(':');

                for (int ii = 0; ii < name.Length; ii++)
                {
                    if (IsEscapedChar(name[ii]))
                    {
                        buffer.AppendFormat("{0:X2}", (int)name[ii]);
                    }
                    else
                    {
                        buffer.Append(name[ii]);
                    }
                }

                return(buffer.ToString());
            }

            // check if the namespace index changed.
            if (browseName.NamespaceIndex != namespaceIndex)
            {
                browseName = new QualifiedName(browseName.Name, namespaceIndex);
            }

            return(browseName.ToString());
        }
예제 #27
0
 /// <summary>
 /// Exports the browse name of the base type.
 /// </summary>
 /// <param name="traceEvent">The trace event.</param>
 /// <returns>XmlQualifiedName.</returns>
 public XmlQualifiedName ExportBrowseNameBaseType(Action <NodeId> traceEvent)
 {
     //TODO It cannot be the reference type
     if (this.NodeIdContext == ObjectTypeIds.BaseObjectType)
     {
         return(null);
     }
     if (this.NodeIdContext == VariableTypeIds.BaseDataVariableType)
     {
         return(null);
     }
     if (this.NodeIdContext == VariableTypeIds.PropertyType)
     {
         return(null);
     }
     if (QualifiedName.IsNull(BrowseName))
     {
         traceEvent(this.NodeIdContext);
         return(XmlQualifiedName.Empty);
     }
     return(ExportNodeBrowseName());
 }
// ***START***
    #region GetFieldValue
/// <summary>
/// Returns the valid of the field identified by the QualifiedName.
/// </summary>
    public override object GetFieldValue(
        NamespaceTable namespaceUris,
        QualifiedName propertyName)
    {
        if (QualifiedName.IsNull(propertyName))
        {
            return(null);
        }

        // The namespace qualifying the property name must be the same namespace used for the TypeId.
        NodeId typeId = ExpandedNodeId.ToNodeId(_NAME_.m_TypeId, namespaceUris);

        // select the value.
        if (propertyName.NamespaceIndex == typeId.NamespaceIndex)
        {
            switch (propertyName.Name)
            {
                // _FIELDNAMESWITCH_
            }
        }

        return(base.GetFieldValue(namespaceUris, propertyName));
    }
예제 #29
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext);

            // check if a specific browse name is requested.
            if (QualifiedName.IsNull(base.BrowseName))
            {
                return(NextChild(m_stage));
            }

            // keep fetching references until a matching browse name if found.
            NodeStateReference reference = null;

            do
            {
                reference = NextChild(m_stage);

                if (reference != null)
                {
                    // need to let the caller look up the browse name.
                    if (reference.Target == null)
                    {
                        return(reference);
                    }

                    // check for browse name match.
                    if (reference.Target.BrowseName == base.BrowseName)
                    {
                        return(reference);
                    }
                }
            }while (reference != null);

            // no match - need to go onto the next stage.
            return(null);
        }
예제 #30
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            // check if a specific browse name is requested.
            if (!QualifiedName.IsNull(base.BrowseName))
            {
                return(FindByBrowseName());
            }

            NodeState target = null;

            // process directories.
            if (m_stage == Stage.Directories)
            {
                if (m_position < 0 || m_directories == null || m_position >= m_directories.Length)
                {
                    return(null);
                }

                target = new AreaState(SystemContext, m_directories[m_position]);
                m_position++;
            }

            // process files.
            if (m_stage == Stage.Files)
            {
                if (m_position < 0 || m_files == null || m_position >= m_files.Length)
                {
                    return(null);
                }

                target = new ControllerState(SystemContext, m_files[m_position]);
                m_position++;
            }

            return(new NodeStateReference(ReferenceTypeIds.Organizes, false, target));
        }