/// <summary>
        /// Parses a relative path formatted as a string. 
        /// </summary>
        public static RelativePath Parse(string browsePath, ITypeTable typeTree)
        {
            if (typeTree == null) throw new ArgumentNullException("typeTree");

            // parse the string.
            RelativePathFormatter formatter = RelativePathFormatter.Parse(browsePath);

            // convert the browse names to node ids.
            RelativePath relativePath = new RelativePath();

            foreach (RelativePathFormatter.Element element in formatter.Elements)
            {
                RelativePathElement parsedElement = new RelativePathElement();

                parsedElement.ReferenceTypeId = null;
                parsedElement.IsInverse = false;
                parsedElement.IncludeSubtypes = element.IncludeSubtypes;
                parsedElement.TargetName = element.TargetName;

                switch (element.ElementType)
                {
                    case RelativePathFormatter.ElementType.AnyHierarchical:
                    {
                        parsedElement.ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences;
                        break;
                    }

                    case RelativePathFormatter.ElementType.AnyComponent:
                    {
                        parsedElement.ReferenceTypeId = ReferenceTypeIds.Aggregates;
                        break;
                    }

                    case RelativePathFormatter.ElementType.ForwardReference:
                    {
                        parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                        break;
                    }

                    case RelativePathFormatter.ElementType.InverseReference:
                    {
                        parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                        parsedElement.IsInverse = true;
                        break;
                    }
                }

                if (NodeId.IsNull(parsedElement.ReferenceTypeId))
                {
                    throw ServiceResultException.Create(
                        StatusCodes.BadSyntaxError,
                        "Could not convert BrowseName to a ReferenceTypeId: {0}",
                        element.ReferenceTypeName);
                }

                relativePath.Elements.Add(parsedElement);
            }

            return relativePath;
        }
 /// <summary>
 /// Returns the BuiltInType type for the DataTypeId.
 /// </summary>
 public static BuiltInType GetBuiltInType(NodeId datatypeId, ITypeTable typeTree)
 {
     return TypeInfo.GetBuiltInType(datatypeId, typeTree);
 }
 /// <summary>
 /// Formats the relative path as a string.
 /// </summary>
 public string Format(ITypeTable typeTree)
 {
     RelativePathFormatter formatter = new RelativePathFormatter(this, typeTree);
     return formatter.ToString();
 }
        /// <summary>
        /// Initializes the object the default values.
        /// </summary>
        public RelativePathFormatter(RelativePath relativePath, ITypeTable typeTree)
        {
            m_elements = new List<Element>();

            if (relativePath != null)
            {              
                foreach (RelativePathElement element in relativePath.Elements)
                {
                    m_elements.Add(new Element(element, typeTree));
                }
            }
        }
            /// <summary>
            /// Initializes the object from a RelativePathElement
            /// </summary>
            public Element(RelativePathElement element, ITypeTable typeTree)
            {                
                if (element == null) throw new ArgumentNullException("element");
                if (typeTree == null) throw new ArgumentNullException("typeTree");

                m_referenceTypeName = null;
                m_targetName = element.TargetName;
                m_elementType = RelativePathFormatter.ElementType.ForwardReference;
                m_includeSubtypes = element.IncludeSubtypes;

                if (!element.IsInverse && element.IncludeSubtypes)
                {
                    if (element.ReferenceTypeId == ReferenceTypeIds.HierarchicalReferences)
                    {
                        m_elementType = RelativePathFormatter.ElementType.AnyHierarchical;
                    }
                    else if (element.ReferenceTypeId == ReferenceTypeIds.Aggregates)
                    {
                        m_elementType = RelativePathFormatter.ElementType.AnyComponent;
                    }
                    else
                    {
                        m_referenceTypeName = typeTree.FindReferenceTypeName(element.ReferenceTypeId);
                    }
                }
                else
                {
                    if (element.IsInverse)
                    {
                        m_elementType = RelativePathFormatter.ElementType.InverseReference;
                    }

                    m_referenceTypeName = typeTree.FindReferenceTypeName(element.ReferenceTypeId);
                }
            }
 /// <summary>
 /// Initializes the context.
 /// </summary>
 /// <param name="namespaceUris">The namespace URIs.</param>
 /// <param name="typeTree">The type tree.</param>
 public FilterContext(NamespaceTable namespaceUris, ITypeTable typeTree)
 :
     this(namespaceUris, typeTree, (IList<string>)null)
 {
 }
        /// <summary>
        /// Initializes the context.
        /// </summary>
        /// <param name="namespaceUris">The namespace URIs.</param>
        /// <param name="typeTree">The type tree.</param>
        /// <param name="preferredLocales">The preferred locales.</param>
        public FilterContext(NamespaceTable namespaceUris, ITypeTable typeTree, IList<string> preferredLocales)
        {
            if (namespaceUris == null) throw new ArgumentNullException("namespaceUris");
            if (typeTree == null) throw new ArgumentNullException("typeTree");

            m_namespaceUris = namespaceUris;
            m_typeTree = typeTree;
            m_context = null;
            m_preferredLocales = preferredLocales;
        }
Пример #8
0
        /// <summary>
        /// Returns the supertype for the Node if one exists.
        /// </summary>
        /// <param name="typeTree">The type tree.</param>
        /// <returns>The supertype for the Node if one exists.</returns>
        /// <remarks>
        /// Includes subtypes of HasSubtype if typeTree != null.
        /// </remarks>
        public ExpandedNodeId GetSuperType(ITypeTable typeTree)
        {
             if (m_referenceTable != null)
             {
                 return m_referenceTable.FindTarget(ReferenceTypeIds.HasSubtype, true, typeTree != null, typeTree, 0);
             }

             return null; 
        }
        /// <summary>
        /// Initializes the context.
        /// </summary>
        /// <param name="namespaceUris">The namespace URIs.</param>
        /// <param name="typeTree">The type tree.</param>
        /// <param name="context">The context.</param>
        public FilterContext(NamespaceTable namespaceUris, ITypeTable typeTree, IOperationContext context)
        {
            if (namespaceUris == null) throw new ArgumentNullException("namespaceUris");
            if (typeTree == null) throw new ArgumentNullException("typeTree");

            m_namespaceUris = namespaceUris;
            m_typeTree = typeTree;
            m_context = context;
        }
Пример #10
0
        /// <summary>
        /// Returns a random value of the specified built-in type.
        /// </summary>
        public object GetRandom(NodeId dataType, int valueRank, IList <uint> arrayDimensions, ITypeTable typeTree)
        {
            BuiltInType expectedType = TypeInfo.GetBuiltInType(dataType, typeTree);

            // calculate total number of dimensions.
            int dimensions = 0;

            switch (valueRank)
            {
            case ValueRanks.Any:
            {
                if (arrayDimensions != null && arrayDimensions.Count > 0)
                {
                    dimensions = arrayDimensions.Count;
                    break;
                }

                dimensions = this.GetRandomRange(0, 1);
                break;
            }

            case ValueRanks.ScalarOrOneDimension:
            {
                dimensions = this.GetRandomRange(0, 1);
                break;
            }

            case ValueRanks.OneOrMoreDimensions:
            {
                if (arrayDimensions != null && arrayDimensions.Count > 0)
                {
                    dimensions = arrayDimensions.Count;
                    break;
                }

                dimensions = this.GetRandomRange(1, 1);
                break;
            }

            case ValueRanks.Scalar:
            {
                dimensions = 0;
                break;
            }

            default:
            {
                dimensions = valueRank;
                break;
            }
            }

            // return a random scalar.
            if (dimensions == 0)
            {
                if (expectedType == BuiltInType.Variant)
                {
                    // randomly choose a built-in type.
                    BuiltInType builtInType = BuiltInType.Variant;

                    while (builtInType == BuiltInType.Variant || builtInType == BuiltInType.DataValue)
                    {
                        builtInType = (BuiltInType)m_random.NextInt32((int)BuiltInType.Variant);
                    }

                    return(GetRandomVariant(builtInType, false));
                }

                return(GetRandom(expectedType));
            }

            // calculate the length of each dimension.
            int[] actualDimensions = new int[dimensions];

            for (int ii = 0; ii < dimensions; ii++)
            {
                if (arrayDimensions != null && arrayDimensions.Count > ii)
                {
                    actualDimensions[ii] = (int)arrayDimensions[ii];
                }

                if (actualDimensions[ii] == 0)
                {
                    actualDimensions[ii] = m_random.NextInt32(m_maxArrayLength);
                }
            }

            // create an array.
            Array output = TypeInfo.CreateArray(expectedType, actualDimensions);

            // generate random values for each element in the array.
            int length = output.Length;

            int[] indexes = new int[actualDimensions.Length];

            for (int ii = 0; ii < length; ii++)
            {
                int divisor = output.Length;

                for (int jj = 0; jj < indexes.Length; jj++)
                {
                    divisor    /= actualDimensions[jj];
                    indexes[jj] = (ii / divisor) % actualDimensions[jj];
                }

                object value = GetRandom(dataType, ValueRanks.Scalar, null, typeTree);

                if (value != null)
                {
                    if (expectedType == BuiltInType.Guid)
                    {
                        value = new Uuid((Guid)value);
                    }

                    output.SetValue(value, indexes);
                }
            }

            // return array value.
            return(output);
        }
Пример #11
0
 /// <summary>
 /// Initializes the context.
 /// </summary>
 /// <param name="namespaceUris">The namespace URIs.</param>
 /// <param name="typeTree">The type tree.</param>
 public FilterContext(NamespaceTable namespaceUris, ITypeTable typeTree)
     :
     this(namespaceUris, typeTree, (IList <string>)null)
 {
 }
Пример #12
0
 /// <summary>
 /// Returns the BuiltInType type for the DataTypeId.
 /// </summary>
 public static BuiltInType GetBuiltInType(NodeId datatypeId, ITypeTable typeTree)
 {
     return(TypeInfo.GetBuiltInType(datatypeId, typeTree));
 }
Пример #13
0
        /// <summary>
        /// Updates the browse element with the properties return in the read results.
        /// </summary>
        /// <param name="typeTree">The type tree.</param>
        /// <param name="element">The element.</param>
        /// <param name="nodesToRead">The nodes to read.</param>
        /// <param name="values">The values.</param>        
        /// <param name="nodeClass">The node class - passed only if all of the information in the ReferenceDescription is available.</param>
        /// <param name="onlyEssentialProperties">If true the only properties essential for browing were fetched.</param>
        /// <param name="first">The first.</param>
        /// <returns></returns>
        private bool UpdateBrowseElement(
            ITypeTable typeTree,
            BrowseElement element,
            ReadValueIdCollection nodesToRead,
            DataValueCollection values,
            NodeClass nodeClass,
            bool onlyEssentialProperties,
            int first)
        {
            // check for a valid range within the collection.
            if (first < 0 || first >= nodesToRead.Count)
            {
                return false;
            }

            if (nodeClass == NodeClass.Unspecified)
            {
                // verify node class.
                NodeClass actualNodeClass = (NodeClass)values[first++].GetValue<int>((int)NodeClass.Unspecified);

                if (actualNodeClass != NodeClass.Variable && actualNodeClass != NodeClass.Object)
                {
                    return false;
                }

                element.NodeClass = actualNodeClass;

                // verify browse name.
                QualifiedName browseName = values[first++].GetValue<QualifiedName>(null);

                if (QualifiedName.IsNull(browseName))
                {
                    return false;
                }

                element.BrowseName = element.UaBrowseName = m_mapper.GetLocalBrowseName(browseName);

                // verify display name.
                LocalizedText displayName = values[first++].GetValue<LocalizedText>(null);

                if (LocalizedText.IsNullOrEmpty(displayName))
                {
                    return false;
                }

                element.BrowseName = displayName.Text;
            }

            if (!onlyEssentialProperties)
            {
                // check if long description exists.
                LocalizedText description = values[first++].GetValue<LocalizedText>(null);

                if (!LocalizedText.IsNullOrEmpty(description))
                {
                    element.UaDescription = description.Text;
                }
                else
                {
                    element.UaDescription = "";
                }
            }

            // update the masks.
            SetElementMasks(element);

            // nothing more to do.
            if (nodeClass == NodeClass.Object)
            {
                return true;
            }

            // verify data type.
            NodeId dataTypeId = values[first++].GetValue<NodeId>(null);

            if (dataTypeId == null && element.NodeClass == NodeClass.Variable)
            {
                return false;
            }

            int valueRank = values[first++].GetValue<int>(ValueRanks.Scalar);

            // update data type information.
            if (dataTypeId != null)
            {
                element.BuiltInType = DataTypes.GetBuiltInType(dataTypeId, typeTree);
                element.DataTypeId = m_mapper.GetLocalItemId(dataTypeId);
                element.ValueRank = valueRank;
                element.CanonicalDataType = (short)ComUtils.GetVarType(new TypeInfo(element.BuiltInType, element.ValueRank));
            }

            if (!onlyEssentialProperties)
            {
                // update scan rate.
                element.ScanRate = (float)values[first++].GetValue<double>(MinimumSamplingIntervals.Indeterminate);

                // update access rights.
                byte userAccessLevel = values[first++].GetValue<byte>(0);

                if ((userAccessLevel & AccessLevels.CurrentRead) != 0)
                {
                    element.AccessRights |= OpcRcw.Da.Constants.OPC_READABLE;
                }

                if ((userAccessLevel & AccessLevels.CurrentWrite) != 0)
                {
                    element.AccessRights |= OpcRcw.Da.Constants.OPC_WRITEABLE;
                }

                if ((userAccessLevel & AccessLevels.HistoryRead) != 0)
                {
                    element.IsHistoricalItem = true;
                }

                // cache the latest value.
                DataValue value = values[first++];

                if (element.NodeClass == NodeClass.Variable)
                {
                    element.LastValue = m_mapper.GetLocalDataValue(value);
                }

                // update HighEU and LowEU
                element.EuType = (int)OpcRcw.Da.OPCEUTYPE.OPC_NOENUM;
                element.HighEU = Double.MaxValue;
                element.LowEU = Double.MaxValue;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.EURange))
                {
                    Range euRange = values[first++].GetValue<Range>(null);

                    if (euRange != null)
                    {
                        element.EuType = (int)OpcRcw.Da.OPCEUTYPE.OPC_ANALOG;
                        element.HighEU = euRange.High;
                        element.LowEU = euRange.Low;
                    }
                }

                // update HighIR and LowIR
                element.HighIR = Double.MaxValue;
                element.LowIR = Double.MaxValue;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.InstrumentRange))
                {
                    Range instrumentRange = values[first++].GetValue<Range>(null);

                    if (instrumentRange != null)
                    {
                        element.HighIR = instrumentRange.High;
                        element.LowIR = instrumentRange.Low;
                    }
                }

                // update EngineeringUnits
                element.EngineeringUnits = null;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.EngineeringUnits))
                {
                    EUInformation engineeringUnits = values[first++].GetValue<EUInformation>(null);

                    if (engineeringUnits != null && engineeringUnits.DisplayName != null)
                    {
                        element.EngineeringUnits = engineeringUnits.DisplayName.Text;
                    }
                }

                // update EUInfo
                element.EuInfo = null;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.EnumStrings))
                {
                    LocalizedText[] enumStrings = values[first++].GetValue<LocalizedText[]>(null);

                    if (enumStrings != null)
                    {
                        string[] strings = new string[enumStrings.Length];

                        for (int ii = 0; ii < enumStrings.Length; ii++)
                        {
                            if (enumStrings[ii] != null)
                            {
                                strings[ii] = enumStrings[ii].Text;
                            }
                        }

                        element.EuType = (int)OpcRcw.Da.OPCEUTYPE.OPC_ENUMERATED;
                        element.EuInfo = strings;
                    }
                }

                // update CloseLabel
                element.CloseLabel = null;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.TrueState))
                {
                    LocalizedText trueState = values[first++].GetValue<LocalizedText>(null);

                    if (trueState != null)
                    {
                        element.CloseLabel = trueState.Text;
                    }
                }

                // update OpenLabel
                element.OpenLabel = null;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.FalseState))
                {
                    LocalizedText falseState = values[first++].GetValue<LocalizedText>(null);

                    if (falseState != null)
                    {
                        element.OpenLabel = falseState.Text;
                    }
                }

                // update TimeZone
                element.TimeZone = Int32.MaxValue;

                if (element.ReferencesByName.ContainsKey(Opc.Ua.BrowseNames.LocalTime))
                {
                    TimeZoneDataType timeZone = values[first++].GetValue<TimeZoneDataType>(null);

                    if (timeZone != null)
                    {
                        element.TimeZone = timeZone.Offset;
                    }
                }
            }

            return true;
        }
Пример #14
0
        /// <summary>
        /// Parses a relative path formatted as a string.
        /// </summary>
        public static RelativePath Parse(string browsePath, ITypeTable typeTree)
        {
            if (typeTree == null)
            {
                throw new ArgumentNullException(nameof(typeTree));
            }

            // parse the string.
            RelativePathFormatter formatter = RelativePathFormatter.Parse(browsePath);

            // convert the browse names to node ids.
            RelativePath relativePath = new RelativePath();

            foreach (RelativePathFormatter.Element element in formatter.Elements)
            {
                RelativePathElement parsedElement = new RelativePathElement();

                parsedElement.ReferenceTypeId = null;
                parsedElement.IsInverse       = false;
                parsedElement.IncludeSubtypes = element.IncludeSubtypes;
                parsedElement.TargetName      = element.TargetName;

                switch (element.ElementType)
                {
                case RelativePathFormatter.ElementType.AnyHierarchical:
                {
                    parsedElement.ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences;
                    break;
                }

                case RelativePathFormatter.ElementType.AnyComponent:
                {
                    parsedElement.ReferenceTypeId = ReferenceTypeIds.Aggregates;
                    break;
                }

                case RelativePathFormatter.ElementType.ForwardReference:
                {
                    parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                    break;
                }

                case RelativePathFormatter.ElementType.InverseReference:
                {
                    parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                    parsedElement.IsInverse       = true;
                    break;
                }
                }

                if (NodeId.IsNull(parsedElement.ReferenceTypeId))
                {
                    throw ServiceResultException.Create(
                              StatusCodes.BadSyntaxError,
                              "Could not convert BrowseName to a ReferenceTypeId: {0}",
                              element.ReferenceTypeName);
                }

                relativePath.Elements.Add(parsedElement);
            }

            return(relativePath);
        }
Пример #15
0
        /// <summary>
        /// Formats the relative path as a string.
        /// </summary>
        public string Format(ITypeTable typeTree)
        {
            RelativePathFormatter formatter = new RelativePathFormatter(this, typeTree);

            return(formatter.ToString());
        }
Пример #16
0
        /// <summary>
        /// Get random data
        /// </summary>
        /// <param name="dataType"></param>
        /// <param name="valueRank"></param>
        /// <param name="arrayDimensions"></param>
        /// <param name="typeTree"></param>
        /// <returns></returns>
        public object GetRandom(NodeId dataType, int valueRank, IList <uint> arrayDimensions,
                                ITypeTable typeTree)
        {
            var builtInType = Ua.TypeInfo.GetBuiltInType(dataType, typeTree);
            var num         = 0;

            switch (valueRank)
            {
            case -2:
                num = (arrayDimensions == null || arrayDimensions.Count <= 0) ?
                      GetRandomRange(0, 1) : arrayDimensions.Count;
                break;

            case -3:
                num = GetRandomRange(0, 1);
                break;

            case 0:
                num = (arrayDimensions == null || arrayDimensions.Count <= 0) ?
                      GetRandomRange(1, 1) : arrayDimensions.Count;
                break;

            case -1:
                num = 0;
                break;

            default:
                num = valueRank;
                break;
            }
            if (num == 0)
            {
                if (builtInType == BuiltInType.Variant)
                {
                    var builtInType2 = BuiltInType.Variant;
                    while (builtInType2 == BuiltInType.Variant || builtInType2 == BuiltInType.DataValue)
                    {
                        builtInType2 = (BuiltInType)_random.NextInt32(24);
                    }
                    return(GetRandomVariant(builtInType2, isArray: false));
                }
                return(GetRandom(builtInType));
            }
            var array = new int[num];

            for (var i = 0; i < num; i++)
            {
                if (arrayDimensions != null && arrayDimensions.Count > i)
                {
                    array[i] = (int)arrayDimensions[i];
                }
                while (array[i] == 0)
                {
                    array[i] = _random.NextInt32(MaxArrayLength);
                }
            }
            var array2 = Ua.TypeInfo.CreateArray(builtInType, array);
            var length = array2.Length;
            var array3 = new int[array.Length];

            for (var j = 0; j < length; j++)
            {
                var num2 = array2.Length;
                for (var k = 0; k < array3.Length; k++)
                {
                    num2     /= array[k];
                    array3[k] = j / num2 % array[k];
                }
                var obj = GetRandom(dataType, -1, null, typeTree);
                if (obj != null)
                {
                    if (builtInType == BuiltInType.Guid)
                    {
                        obj = new Uuid((Guid)obj);
                    }
                    array2.SetValue(obj, array3);
                }
            }
            return(array2);
        }