Пример #1
0
        /// <summary>
        /// Returns link instance, detached from the <see cref="freeGraph"/> model
        /// </summary>
        /// <param name="link">The link.</param>
        /// <param name="skipCheck">if set to <c>true</c> [skip check].</param>
        /// <returns></returns>
        public freeGraphLink GetLinkInstance(freeGraphLinkBase link, Boolean skipCheck = true)
        {
            freeGraphLink output = new freeGraphLink(link.GetClone());

            output.nodeA = GetNode(link.nodeNameA, skipCheck);

            if (output.nodeA != null)
            {
                output.nodeA = output.nodeA.GetQueryResultClone(0);
            }

            output.nodeB = GetNode(link.nodeNameB, skipCheck);
            if (output.nodeB != null)
            {
                output.nodeB = output.nodeB.GetQueryResultClone(0);
            }

            return(output);
        }
Пример #2
0
        /// <summary>
        /// Gets the links.
        /// </summary>
        /// <param name="nodeName">Name of the node.</param>
        /// <param name="AtoB">if set to <c>true</c> [ato b].</param>
        /// <param name="BtoA">if set to <c>true</c> [bto a].</param>
        /// <param name="nodeWeightFactor">The node weight factor.</param>
        /// <param name="nodeType">Type of the node.</param>
        /// <param name="skipCheck">if set to <c>true</c> [skip check].</param>
        /// <param name="initialWeightFromParent">if set to <c>true</c> [initial weight from parent].</param>
        /// <returns></returns>
        public freeGraphNodeAndLinks GetLinks(String nodeName, Boolean AtoB = true, Boolean BtoA = true, Double nodeWeightFactor = 1.0, Int32 nodeType = 0, Boolean skipCheck = true, Boolean initialWeightFromParent = true)
        {
            //if (!nodeDictionary.ContainsKey(nodeName)) return null;

            freeGraphNodeAndLinks output = new freeGraphNodeAndLinks();


            //List<freeGraphLinkBase> lnks = new List<freeGraphLinkBase>();
            if (skipCheck)
            {
                if (AtoB)
                {
                    output.links.AddRange(links.Where(x => x.nodeNameA.Equals(nodeName)));
                }
                if (BtoA)
                {
                    output.links.AddRange(links.Where(x => x.nodeNameB.Equals(nodeName)));
                }
            }
            else
            {
                output.links.AddRange(linkRegistry.GetLinks(nodeName, AtoB, BtoA));
            }

            output.node = GetNode(nodeName, skipCheck);

            foreach (freeGraphLinkBase link in output.links)
            {
                freeGraphLink link_instance = GetLinkInstance(link, skipCheck);
                if (link_instance.IsReady)
                {
                    if (link_instance.nodeA.name != nodeName)
                    {
                        if (initialWeightFromParent)
                        {
                            link_instance.nodeA.weight = link_instance.nodeA.weight * nodeWeightFactor;
                        }
                        else
                        {
                            link_instance.nodeA.weight = 1 * nodeWeightFactor;
                        }
                    }
                    if (link_instance.nodeB.name != nodeName)
                    {
                        if (initialWeightFromParent)
                        {
                            link_instance.nodeB.weight = link_instance.nodeB.weight * nodeWeightFactor;
                        }
                        else
                        {
                            link_instance.nodeB.weight = 1 * nodeWeightFactor;
                        }
                    }
                    if (link_instance.nodeA.name != nodeName)
                    {
                        link_instance.nodeA.type = nodeType;
                    }
                    if (link_instance.nodeB.name != nodeName)
                    {
                        link_instance.nodeB.type = nodeType;
                    }
                    output.Add(link_instance);
                    if (!output.linkedNodeClones.ContainsKey(link_instance.nodeA.name))
                    {
                        output.linkedNodeClones.Add(link_instance.nodeA.name, link_instance.nodeA);
                    }
                    if (!output.linkedNodeClones.ContainsKey(link_instance.nodeB.name))
                    {
                        output.linkedNodeClones.Add(link_instance.nodeB.name, link_instance.nodeB);
                    }
                }
            }

            return(output);
        }