示例#1
0
        /// <summary>
        /// Returns the NodeClass for the node.
        /// </summary>
        public static NodeClass GetNodeClass(this NodeDesign node)
        {
            switch (node)
            {
            case ObjectDesign _:
                return(NodeClass.Object);

            case ObjectTypeDesign _:
                return(NodeClass.ObjectType);

            case DataTypeDesign _:
                return(NodeClass.DataType);

            case ReferenceTypeDesign _:
                return(NodeClass.ReferenceType);

            case MethodDesign _:
                return(NodeClass.Method);

            case VariableDesign _:
                return(NodeClass.Variable);

            case VariableTypeDesign _:
                return(NodeClass.VariableType);

            case ViewDesign _:
                return(NodeClass.View);
            }
            return(NodeClass.Unspecified);
        }
示例#2
0
        /// <summary>
        /// Returns the NodeClass for the node.
        /// </summary>
        public static string GetNodeClassText(this NodeDesign node)
        {
            switch (node)
            {
            case PropertyDesign _:
                return("Property");

            case ObjectDesign _:
                return("Object");

            case ObjectTypeDesign _:
                return("ObjectType");

            case DataTypeDesign _:
                return("DataType");

            case ReferenceTypeDesign _:
                return("ReferenceType");

            case MethodDesign _:
                return("Method");

            case VariableDesign _:
                return("Variable");

            case VariableTypeDesign _:
                return("VariableType");

            case ViewDesign _:
                return("View");
            }
            return("node");
        }
示例#3
0
        /// <summary>
        /// Merge node design into the instance
        /// </summary>
        /// <param name="mergedInstance"></param>
        /// <param name="source"></param>
        public static void MergeIn(this InstanceDesign mergedInstance, NodeDesign source)
        {
            if (source.DisplayName != null && !source.DisplayName.IsAutogenerated)
            {
                mergedInstance.DisplayName = source.DisplayName;
            }
            if (source.Description != null && !source.Description.IsAutogenerated)
            {
                mergedInstance.Description = source.Description;
            }

            if (source is InstanceDesign instance)
            {
                if (mergedInstance.SymbolicName != source.SymbolicName)
                {
                    mergedInstance.SymbolicName = source.SymbolicName;
                    mergedInstance.BrowseName   = source.BrowseName;
                    mergedInstance.DisplayName  = source.DisplayName;
                }
                mergedInstance.ReferenceType = instance.ReferenceType;
                if (instance.ModellingRuleSpecified)
                {
                    mergedInstance.ModellingRule          = instance.ModellingRule;
                    mergedInstance.ModellingRuleSpecified = true;
                }
                // Merge in instance design
                switch (instance)
                {
                case VariableDesign variable:
                    mergedInstance.MergeIn(variable);
                    break;

                case ObjectDesign objectd:
                    mergedInstance.MergeIn(objectd);
                    break;

                case MethodDesign method:
                    mergedInstance.MergeIn(method);
                    break;
                }
            }
            else
            {
                // Merge in type design
                switch (source)
                {
                case VariableTypeDesign variableType:
                    mergedInstance.MergeIn(variableType);
                    break;

                case ObjectTypeDesign objectType:
                    mergedInstance.MergeIn(objectType);
                    break;
                }
            }
        }
示例#4
0
 /// <summary>
 /// Get symbolic id for a node that is either root or has the specified parent.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="symbolicName"></param>
 /// <returns></returns>
 public static XmlQualifiedName CreateSymbolicId(this NodeDesign parent,
                                                 XmlQualifiedName symbolicName)
 {
     if (symbolicName.IsNullOrEmpty())
     {
         throw new ArgumentNullException(nameof(symbolicName));
     }
     return(new XmlQualifiedName(CreateSymbolicId(parent?.SymbolicId?.Name, symbolicName.Name),
                                 symbolicName.Namespace));
 }
示例#5
0
 /// <summary>
 /// Returns true if the node is a declaration.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 public static bool IsDeclaration(this NodeDesign node)
 {
     for (var cur = node; cur != null; cur = cur.Parent)
     {
         if (cur.IsDeclaration)
         {
             return(true);
         }
     }
     return(false);
 }
示例#6
0
 /// <summary>
 /// Get symbolic id for a child of a node
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="childName"></param>
 /// <returns></returns>
 public static XmlQualifiedName GetSymbolicIdForChild(this NodeDesign parent,
                                                      string childName)
 {
     if (string.IsNullOrEmpty(childName))
     {
         throw new ArgumentNullException(nameof(childName));
     }
     if (parent?.SymbolicId == null)
     {
         throw new ArgumentNullException(nameof(parent));
     }
     return(new XmlQualifiedName(CreateSymbolicId(parent.SymbolicId.Name, childName),
                                 parent.SymbolicId.Namespace));
 }
示例#7
0
 /// <summary>
 /// Set identifier of node
 /// </summary>
 /// <param name="node"></param>
 /// <param name="identifier"></param>
 public static void SetIdentifier(this NodeDesign node, object identifier)
 {
     // set identifier for node.
     if (identifier is uint)
     {
         node.NumericId          = (uint)identifier;
         node.NumericIdSpecified = true;
         node.StringId           = null;
     }
     else
     {
         node.NumericId          = 0;
         node.NumericIdSpecified = false;
         node.StringId           = identifier as string;
     }
 }
        private bool IsExcluded(NodeDesign node)
        {
            if (_excludedCategories != null)
            {
                foreach (var jj in _excludedCategories)
                {
                    if (jj == node.ReleaseStatus.ToString())
                    {
                        return(true);
                    }

                    if (node.Category != null && node.Category.Contains(jj))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#9
0
 /// <summary>
 /// Find the related instance design in the node's hierarchy
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private static NodeDesign FindInstanceInHierarchy(this NodeDesign node)
 {
     for (var parent = node.Parent; parent != null; parent = parent.Parent)
     {
         if (parent.Hierarchy != null)
         {
             var browsePath = node.SymbolicId.Name;
             if (browsePath.StartsWith(parent.SymbolicId.Name, StringComparison.Ordinal) &&
                 browsePath[parent.SymbolicId.Name.Length] == NodeDesign.kPathChar[0])
             {
                 // Get relative browse path from parent
                 browsePath = browsePath.Substring(parent.SymbolicId.Name.Length + 1);
             }
             // Get instance using browse path
             if (parent.Hierarchy.Nodes.TryGetValue(browsePath, out var instance))
             {
                 return(instance.Instance);
             }
         }
     }
     return(node);
 }
示例#10
0
 /// <summary>
 /// Get node id for node
 /// </summary>
 /// <param name="node"></param>
 /// <param name="namespaceUris"></param>
 /// <returns></returns>
 public static NodeId GetNodeId(this NodeDesign node, NamespaceTable namespaceUris)
 {
     if (node == null)
     {
         return(NodeId.Null);
     }
     if (!string.IsNullOrEmpty(node.StringId))
     {
         return(new NodeId(node.StringId,
                           (ushort)namespaceUris.GetIndex(node.SymbolicId.Namespace)));
     }
     if (node.NumericId == 0)
     {
         node = node.FindInstanceInHierarchy();
         if (node.NumericId == 0)
         {
             return(NodeId.Null);
         }
     }
     return(new NodeId(node.NumericId,
                       (ushort)namespaceUris.GetIndex(node.SymbolicId.Namespace)));
 }