Exemple #1
0
 /// <summary>
 /// Get attribute
 /// </summary>
 /// <param name="attributes"></param>
 /// <param name="attribute"></param>
 /// <param name="defaultValue"></param>
 /// <returns></returns>
 public static T?GetAttribute <T>(this INodeAttributes attributes,
                                  uint attribute, T?defaultValue) where T : struct
 {
     if (attributes.TryGetAttribute <T>(attribute, out var result))
     {
         return(result);
     }
     return(defaultValue);
 }
		public static void Copy(INodeAttributes source, INodeAttributes destination)
		{
			foreach (Pair<string, object> attributePair in source)
			{
				if (attributePair.Value != null)
				{
					destination[attributePair.Name] = attributePair.Value;
				}
			}
		}
		/// <summary>
		/// Construct a new <c>AutoRefreshingNodeAttributes</c> class that automatically
		/// refreshes the details on every query for a set number of queries.
		/// </summary>
		/// <remarks>
		/// When <c>localAutoRefreshCount</c> is specified
		/// </remarks>
		/// <param name="details">The underlying details implementation to use.</param>
		/// <param name="autoRefreshCount">
		/// The minimum number of future queries in which to auto refresh.  -1 means infininty.
		/// </param>
		public AutoRefreshingNodeAttributes(INodeAttributes details, int autoRefreshCount)
			: base(details)
		{
			if (autoRefreshCount < -1)
			{
				throw new ArgumentOutOfRangeException("Can't be less than -1", "localAutoRefreshCount");
			}

			this.orignalAutoRefreshCount = this.autoRefreshCount = autoRefreshCount;
		}
Exemple #4
0
 public static void Copy(INodeAttributes source, INodeAttributes destination)
 {
     foreach (Pair <string, object> attributePair in source)
     {
         if (attributePair.Value != null)
         {
             destination[attributePair.Name] = attributePair.Value;
         }
     }
 }
        /// <summary>
        /// Construct a new <c>AutoRefreshingNodeAttributes</c> class that automatically
        /// refreshes the details on every query for a set number of queries.
        /// </summary>
        /// <remarks>
        /// When <c>localAutoRefreshCount</c> is specified
        /// </remarks>
        /// <param name="details">The underlying details implementation to use.</param>
        /// <param name="autoRefreshCount">
        /// The minimum number of future queries in which to auto refresh.  -1 means infininty.
        /// </param>
        public AutoRefreshingNodeAttributes(INodeAttributes details, int autoRefreshCount)
            : base(details)
        {
            if (autoRefreshCount < -1)
            {
                throw new ArgumentOutOfRangeException("Can't be less than -1", "localAutoRefreshCount");
            }

            this.orignalAutoRefreshCount = this.autoRefreshCount = autoRefreshCount;
        }
Exemple #6
0
        public StandardNodeAttributesUpdateContext(INodeAttributes nodeAttributes)
        {
            this.nodeAttributes = nodeAttributes;

            this.syncLock = nodeAttributes.GetAutoLock().Lock();
        }
		public NodeToFileAttributes(INodeAttributes attributes)
			: base(attributes)
		{
		}
Exemple #8
0
        /// <summary>
        /// Creates a series of columns in <paramref name="nodeAttribs"/> based on the names in <paramref name="nodeHeaders"/>.
        /// </summary>
        /// <param name="nodeAttribs">An INodeAttributes object</param>
        /// <param name="nodeHeaders">The node header names read in from the file, (items are assumed to be unique).</param>
        /// <param name="writerHelper">An IKnownHeaderNamesHelper object to help</param>
        internal void CreateNodeAttribs_XXX(INodeAttributes nodeAttribs, IList<HeaderField> nodeHeaders, IKnownHeaderNamesReaderHelper writerHeloper)
        {
            // Assumes nodeHeaders has unique entries

            // for each entry in headHeaderNames
            //  check if it is a known entry
            //  if it is
            //      create an attrib of that type
            //  else
            //      create an attrib of type string (defaut)
            foreach (var header in nodeHeaders)
            {
                header.AttribColumnIndex = nodeAttribs.NodeData.AddColumn(header.AttribColName, header.AttribColumnType);
            }
        }
Exemple #9
0
        /// <summary>
        /// Creates a series of columns in <paramref name="nodeAttribs"/> based on the names in <paramref name="nodeHeaders"/>.
        /// All types are left as strings.
        /// </summary>
        /// <param name="nodeAttribs">An INodeAttributes object</param>
        /// <param name="nodeHeaders">The node header names read in from the file, (items are assumed to be unique).</param>
        internal void CreateNodeAttribs(INodeAttributes nodeAttribs, IList<HeaderField> nodeHeaders)
        {
            // Assumes nodeHeaders has unique entries

            // for each entry in nodeHeaders
            // create an attrib of type defined by the header
            // and assign the index of the attrib back to he header
            foreach (var header in nodeHeaders)
            {
                header.AttribColumnIndex = nodeAttribs.NodeData.AddColumn(header.AttribColName, header.AttribColumnType);
            }
        }
Exemple #10
0
 /// <summary>
 /// Assigns the value to <paramref name="node"/> using the appropriate <see cref="INodeMap"/>.  The node map
 /// corresponds to <paramref name="mapKeyId."/>
 /// </summary>
 /// <param name="mapKeyId">The string id of the <see cref="Key"/> object which corresponds to INodeMap to use.</param>
 /// <param name="rawVal">The raw string value which is to be converted to its final data type.</param>
 /// <param name="node">The INode which will have the value assigned to it.</param>
 /// <param name="network">The parent network.</param>
 internal void MapNodeAttrib(string mapKey, string rawVal, INode node, INodeAttributes network)
 {
     Key key = NodeDataMapKeys[mapKey];
     var value = Convert.ChangeType(rawVal, key.DataType);
     network.NodeData.SetValue(node, key.Index, value);
 }
Exemple #11
0
 internal void CreateNodeMaps(INodeAttributes network, IDictionary<string, Key> nodeDataMapKeys)
 {
     foreach (KeyValuePair<string, Key> kvp in nodeDataMapKeys)
     {
         CreateDataAttribute(network, kvp.Value);
     }
 }
        /// <summary>
        /// Populates <paramref name="copyTable"/> with node attribute data from <paramref name="srcNetwork"/>.
        /// The input table is assumed to have the correct structure (columns etc) but be empty of
        /// row data.  
        /// </summary>
        /// <param name="srcNetwork">The srcNetwork to extract node data attribs</param>
        /// <param name="includeNodeIndices">If true include a col of node indices</param>
        /// <param name="copyTable">The empty, structured, table to be populated</param>
        /// <remarks>The reason for passing in the table is that it can be a plain datatable or a BasicFrame.</remarks>
        internal void PopulateTable(INodeAttributes srcNetwork, bool includeNodeIndices, DataTable copyTable)
        {
            var srcTable = srcNetwork.NodeData as DataAttributeTable<INode>;

            if (!includeNodeIndices)
            {
                for (int i = 0; i < srcTable.Rows.Count; i++)
                {
                    copyTable.ImportRow(srcTable.Rows[i]);
                }
            }
            else
            {
                DataRow newRow = null;
                foreach (KeyValuePair<INode, DataRow> kvp in srcTable.RowOwnerMap)
                {
                    newRow = copyTable.NewRow();
                    newRow[0] = kvp.Key.Index;
                    for (int i = 0; i < srcNetwork.NodeDataAttributeCount; i++)
                    {
                        newRow[i + 1] = kvp.Value[i];
                    }
                    copyTable.Rows.Add(newRow);
                }
                copyTable.AcceptChanges();
            }
        }
 public NodeToFileAttributes(INodeAttributes attributes)
     : base(attributes)
 {
 }
 /// <summary>
 /// If the 'size' header is found in the *Node properties header line, this method handles what
 /// needs to be done
 /// </summary>
 /// <param name="nodeAttribs"></param>
 internal void DealWithSpecialCaseOfNodeSizeHeader(INodeAttributes nodeAttribs)
 {
     nodeAttribs.NodeData.AddColumn(BlueSpider.Blob.Common.Constants._Name_NodesWidth, typeof(float));
     nodeAttribs.NodeData.AddColumn(BlueSpider.Blob.Common.Constants._Name_NodesHeight, typeof(float));
 }
        /// <summary>
        /// Creates a series of columns in <paramref name="nodeAttribs"/> based on the names in <paramref name="headerFields"/>.
        /// </summary>
        /// <param name="nodeAttribs">An INodeAttributes object</param>
        /// <param name="headerFields">The node header names read in from the file, (items are assumed to be unique).</param>
        /// <param name="writerHelper">An IKnownHeaderNamesHelper object to help</param>
        internal void CreateNodeAttribs(INodeAttributes nodeAttribs, IList<HeaderField> headerFields, IKnownHeaderNamesReaderHelper writerHelper)
        {
            // Assumes nodeHeaders has unique entries

            // for each entry in headHeaderNames
            //  check if it is a known entry
            //  if it is
            //      create an attrib of that type
            //  else
            //      create an attrib of type string (defaut)
            HeaderMatch match = null;
            bool nodeSizeColFound = false;
            int attribColIndex = -1;
            foreach (var header in headerFields)
            {
                match = writerHelper.GetKnownNodeHeader(header.Name);
                if (match != null)
                {
                    attribColIndex = nodeAttribs.NodeData.AddColumn(match.NameToUse ?? header.Name, match.DataType);
                    // check for the special case of node size
                    nodeSizeColFound |= string.Compare(match.Name, "size", true, CultureInfo.InvariantCulture) == 0;
                }
                else
                {
                    attribColIndex = nodeAttribs.NodeData.AddColumn(header.Name, typeof(string));
                }
                header.IndexOfTargetAttribColumn = attribColIndex;
            }

            // Now handle special cases (eg node size)
            if (nodeSizeColFound)
                DealWithSpecialCaseOfNodeSizeHeader(nodeAttribs);
        }
        /// <summary>
        /// Creates a series of columns in <paramref name="nodeAttribs"/> based on the names in <paramref name="headerFields"/>.
        /// All types are left as strings.
        /// </summary>
        /// <param name="nodeAttribs">An INodeAttributes object</param>
        /// <param name="headerFields">The node header names read in from the file, (items are assumed to be unique).</param>
        internal void CreateNodeAttribs(INodeAttributes nodeAttribs, IList<HeaderField> headerFields)
        {
            // Assumes nodeHeaders has unique entries

            // for each entry in headHeaderNames
            // create an attrib of type string (defaut)
            // size is left as a string
            int attribColIndex = -1;
            foreach (var header in headerFields)
            {
                attribColIndex = nodeAttribs.NodeData.AddColumn(header.Name, typeof(string));
                header.IndexOfTargetAttribColumn = attribColIndex;
            }
        }
		public AutoRefreshingFileAttributes(INodeAttributes details, int autoRefreshCount)
			: base(details, autoRefreshCount)
		{
		}
		public StandardNodeAttributesUpdateContext(INodeAttributes nodeAttributes)
		{
			this.nodeAttributes = nodeAttributes;

			this.syncLock = nodeAttributes.GetAutoLock().Lock();
		}
        /// <summary>
        /// Convert to node model
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="isProperty"></param>
        /// <returns></returns>
        public static BaseNodeModel ToNodeModel(this INodeAttributes attributes,
                                                bool isProperty = false)
        {
            BaseNodeModel nodeModel;
            var           nodeClass = attributes.NodeClass;

            switch (nodeClass)
            {
            case NodeClass.View:
                nodeModel = new ViewNodeModel {
                    ContainsNoLoops = attributes.ContainsNoLoops,
                    EventNotifier   = attributes.EventNotifier
                };
                break;

            case NodeClass.ReferenceType:
            case NodeClass.DataType:
            case NodeClass.ObjectType:
            case NodeClass.VariableType:
                switch (nodeClass)
                {
                case NodeClass.VariableType:
                    if (isProperty)
                    {
                        nodeModel = new PropertyTypeNodeModel();
                    }
                    else
                    {
                        nodeModel = new DataVariableTypeNodeModel();
                    }
                    var baseVariableTypeState = nodeModel as VariableTypeNodeModel;
                    baseVariableTypeState.ArrayDimensions =
                        attributes.ArrayDimensions;
                    baseVariableTypeState.DataType =
                        attributes.DataType;
                    baseVariableTypeState.ValueRank =
                        attributes.ValueRank;
                    baseVariableTypeState.Value =
                        attributes.Value;
                    break;

                case NodeClass.ObjectType:
                    nodeModel = new ObjectTypeNodeModel();
                    break;

                case NodeClass.ReferenceType:
                    nodeModel = new ReferenceTypeNodeModel {
                        Symmetric   = attributes.Symmetric,
                        InverseName = attributes.InverseName
                    };
                    break;

                default:
                    return(null);
                }
                var baseTypeState = nodeModel as TypeNodeModel;
                baseTypeState.IsAbstract = attributes.IsAbstract;
                break;

            case NodeClass.Object:
            case NodeClass.Method:
            case NodeClass.Variable:
                switch (nodeClass)
                {
                case NodeClass.Variable:
                    if (isProperty)
                    {
                        nodeModel = new PropertyNodeModel();
                    }
                    else
                    {
                        nodeModel = new DataVariableNodeModel();
                    }
                    var baseVariableState = nodeModel as VariableNodeModel;
                    baseVariableState.ArrayDimensions =
                        attributes.ArrayDimensions;
                    baseVariableState.DataType =
                        attributes.DataType;
                    baseVariableState.ValueRank =
                        attributes.ValueRank;
                    baseVariableState.Value =
                        attributes.Value;
                    baseVariableState.AccessLevel =
                        attributes.AccessLevel;
                    baseVariableState.UserAccessLevel =
                        attributes.UserAccessLevel;
                    baseVariableState.Historizing =
                        attributes.Historizing;
                    baseVariableState.MinimumSamplingInterval =
                        attributes.MinimumSamplingInterval;
                    break;

                case NodeClass.Object:
                    nodeModel = new ObjectNodeModel {
                        EventNotifier = attributes.EventNotifier
                    };
                    break;

                case NodeClass.Method:
                    nodeModel = new MethodNodeModel {
                        UserExecutable = attributes.UserExecutable ?? true,
                        Executable     = attributes.Executable ?? true
                    };
                    break;

                default:
                    return(null);
                }
                break;

            default:
                return(null);
            }
            nodeModel.BrowseName          = attributes.BrowseName;
            nodeModel.Description         = attributes.Description;
            nodeModel.DisplayName         = attributes.DisplayName;
            nodeModel.NodeId              = attributes.LocalId;
            nodeModel.WriteMask           = (AttributeWriteMask?)attributes.WriteMask;
            nodeModel.UserWriteMask       = (AttributeWriteMask?)attributes.UserWriteMask;
            nodeModel.AccessRestrictions  = attributes.AccessRestrictions;
            nodeModel.RolePermissions     = attributes.RolePermissions.ToListSafe();
            nodeModel.UserRolePermissions = attributes.UserRolePermissions.ToListSafe();
            if (attributes is NodeAttributeSet raw)
            {
                foreach (var reference in raw.References)
                {
                    if (nodeModel is InstanceNodeModel instance)
                    {
                        if (reference.ReferenceTypeId == ReferenceTypeIds.HasModellingRule &&
                            !reference.IsInverse)
                        {
                            instance.ModellingRuleId = (NodeId)reference.TargetId;
                        }
                        else if (reference.ReferenceTypeId == ReferenceTypeIds.HasTypeDefinition &&
                                 !reference.IsInverse)
                        {
                            instance.TypeDefinitionId = (NodeId)reference.TargetId;
                        }
                    }
                    else if (nodeModel is TypeNodeModel type)
                    {
                        if (reference.ReferenceTypeId == ReferenceTypeIds.HasSubtype &&
                            !reference.IsInverse)
                        {
                            type.SuperTypeId = (NodeId)reference.TargetId;
                        }
                    }
                    else
                    {
                        nodeModel.AddReference(reference.ReferenceTypeId, reference.IsInverse,
                                               reference.TargetId);
                    }
                }
            }
            return(nodeModel);
        }
 public AutoRefreshingFileAttributes(INodeAttributes details, int autoRefreshCount)
     : base(details, autoRefreshCount)
 {
 }
Exemple #21
0
 public NodeAttributesWrapper(INodeAttributes innerMutableNodeAttributes)
 {
     this.wrappee = innerMutableNodeAttributes;
 }
Exemple #22
0
 internal void CreateDataAttribute(INodeAttributes network, Key mapKey)
 {
     int index = network.NodeData.AddColumn(mapKey.Name, mapKey.DataType);
 }