private void LoadAccounts()
        {
            var nodes = _accountDirectory.GetRootNodes();
            var root  = new List <TreeNodeViewModel>();

            foreach (var node in nodes)
            {
                var vm = node switch
                {
                    CosmosAccount account =>
                    (TreeNodeViewModel)_viewModelFactory.CreateAccountNode(
                        account,
                        _accountContextFactory.Create(account),
                        null),
                    CosmosAccountFolder folder => (TreeNodeViewModel)_viewModelFactory.CreateAccountFolderNode(folder, null),
                    _ => throw new Exception("Invalid node type")
                };
                root.Add(vm);
            }
            foreach (var c in root.OrderByDescending(n => n is AccountFolderNodeViewModel)
                     .ThenBy(c => c.Text))
            {
                RootNodes.Add(c);
            }
        }
        protected override void GenerateTree(object obj) {

            NewReleaseItem newReleaseItem = (NewReleaseItem) obj;
            NewReleaseHierarchyNode root = new NewReleaseHierarchyNode(newReleaseItem, this);
            RootNodes.Add(root);
            NodeDictionary.Add(root.NewReleaseItem.Album.Name, root);
        }
Example #3
0
 /// <summary>
 /// Adds a map frame as a root node, and links an event handler to update
 /// when the mapframe triggers an ItemChanged event.
 /// </summary>
 /// <param name="mapFrame"></param>
 public void AddMapFrame(IFrame mapFrame)
 {
     mapFrame.IsSelected = true;
     if (!RootNodes.Contains(mapFrame))
     {
         OnIncludeMapFrame(mapFrame);
     }
     RootNodes.Add(mapFrame);
     RefreshNodes();
 }
Example #4
0
        private void OnRemoveEdge(GraphEdge <T> edge)
        {
            edge.Sink.IncomingEdges.Remove(edge);
            edge.Source.OutgoingEdges.Remove(edge);

            if (edge.Sink.IsRootNode)
            {
                RootNodes.Add(edge.Sink);
            }

            if (edge.Source.IsLeafNode)
            {
                LeafNodes.Add(edge.Source);
            }
        }
 private void PopulateTree()
 {
     try
     {
         var node = new MyNode {Number = 0};
         if (_dispatcher.CheckAccess())
             RootNodes.Add(node);
         else _dispatcher.Invoke(() => RootNodes.Add(node));
         FillNodeRecursively(node, 1);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Example #6
0
        /// <summary>
        /// Creates the chain.
        /// </summary>
        /// <param name="nodes">The nodes.</param>
        /// <exception cref="NotSupportedException"></exception>
        protected void CreateChain(Tree nodes)
        {
            foreach (var treeRoot in nodes.Roots)
            {
                switch (treeRoot)
                {
                case ConstantNode constantElement when treeRoot.Next is FieldNode fieldElement:
                {
                    if (!(fieldElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        fieldElement.FieldInfo.GetValue(constantElement.Value));

                    Looptree(propertyElement, root);
                    RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement:
                {
                    if (!(treeRoot.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)constantElement.Value);

                    Looptree(propertyElement, root);
                    RootNodes.Add(root);

                    break;
                }

                default:
                    throw new NotSupportedException($"{treeRoot}");
                }
            }
        }
Example #7
0
        /// <summary>
        /// Generates the tree from the root artist.
        /// </summary>
        /// <param name="artist"></param>
        protected override void GenerateTree(object obj)
        {
            Artist artist = (Artist)obj;

            if (NodeDictionary.ContainsKey(artist.Name))
            {
                return;
            }

            ArtistViewModel     rootViewModel = new ArtistViewModel(artist);
            ArtistHierarchyNode root          = new ArtistHierarchyNode(rootViewModel, this, null, 0);

            RootNodes.Add(root);
            NodeDictionary.Add(artist.Name, root);

            ArtistGroup relatedArtistList = Client.GetRelatedArtists(artist.ID);

            //First determine which artists are new; add those.
            List <Artist> newArtists = new List <Artist>();
            int           nodesAdded = 0;

            foreach (Artist relatedArtist in relatedArtistList.Artists)
            {
                if (NodeDictionary.ContainsKey(relatedArtist.Name))
                {
                    continue;
                }

                if (nodesAdded < AddChildrenLimit)
                {
                    newArtists.Add(relatedArtist);

                    ArtistViewModel     artistViewModel   = new ArtistViewModel(relatedArtist);
                    ArtistHierarchyNode relatedArtistNode = new ArtistHierarchyNode(artistViewModel, this, root, 1);
                    root.Children.Add(relatedArtistNode);
                    NodeDictionary.Add(relatedArtist.Name, relatedArtistNode);

                    nodesAdded++;
                }
                else
                {
                    break;
                }
            }
        }
Example #8
0
        public Tree_Model()
        {
            var n = new LV1
            {
                Value = "A",
            };

            n.Children.Add(new LV2()
            {
                Value = "B"
            });


            RootNodes.Add(n);
            RootNodes.Add(n);
            RootNodes.Add(n);
            RootNodes.Add(n);
            RootNodes.Add(n);
        }
Example #9
0
        private void LoadAccounts()
        {
            var nodes = _accountDirectory.GetRootNodes();

            foreach (var node in nodes)
            {
                var vm = node switch
                {
                    CosmosAccount account =>
                    (TreeNodeViewModel)_viewModelFactory.CreateAccountNode(
                        account,
                        _accountContextFactory.Create(account),
                        null),
                    CosmosAccountFolder folder => (TreeNodeViewModel)_viewModelFactory.CreateAccountFolderNode(folder, null),
                    _ => throw new Exception("Invalid node type")
                };

                RootNodes.Add(vm);
            }
        }
Example #10
0
        public bool Add(ITerm <Value> Term, Dictionary <long, RiskItemCharacteristicIDAttributes> CoverageIdAttrMap,
                        Dictionary <string, HashSet <long> > ResolvedSchedule, bool CheckForPerRisk = true)
        {
            Subject NodeIdentity = Term.GetSubject();

            bool IsAddSuccessful = true;

            if (NodeIdentity == null)
            {
                NodeIdentity = EMPTYSUBJECTCONSTRAINT;
            }

            TermCollection TermCollection = (IdentityMap.ContainsKey(NodeIdentity) ?
                                             IdentityMap[NodeIdentity].GetContent() : new TermCollection(NodeIdentity));

            // Switching off the following check intentionally, in order to allow redundant terms
            //if (TermCollection.Contains(Term))
            //    throw new ArgumentException("A term node with the same identity (i.e. subject) already contains this term in its collection!");

            IsAddSuccessful = TermCollection.Add(Term);

            if (IsAddSuccessful && !IdentityMap.ContainsKey(NodeIdentity))
            {
                TermNode _TermNode = new TermNode(TermCollection);

                IsAddSuccessful &= base.Add(_TermNode);

                if (IsAddSuccessful)
                {
                    IdentityMap.Add(NodeIdentity, _TermNode);
                    // A newly added term node (i.e. with no parent or child links) is both a root and a leaf, trivially.
                    IsAddSuccessful &= RootNodes.Add(_TermNode);
                    ExecutionState.RegisterModificationInGraphTopology();
                }
            }

            return(IsAddSuccessful);
        }
 public void Add(TreeNode item)
 {
     RootNodes.Add(item);
 }
Example #12
0
            public FeaturesTree(UnitProgressionData progression)
            {
                Dictionary <BlueprintScriptableObject, FeatureNode> normalNodes = new();
                List <FeatureNode> parametrizedNodes = new();

                //Main.Log($"prog: {progression}");
                // get nodes (features / race)
                foreach (var feature in progression.Features.Enumerable)
                {
                    var name = feature.Name;
                    if (name == null || name.Length == 0)
                    {
                        name = feature.Blueprint.name;
                    }
                    //Main.Log($"feature: {name}");
                    var source = feature.m_Source;
                    //Main.Log($"source: {source}");
                    if (feature.Blueprint is BlueprintParametrizedFeature)
                    {
                        parametrizedNodes.Add(new FeatureNode(name, feature.SourceLevel, feature.Blueprint, source));
                    }
                    else
                    {
                        normalNodes.Add(feature.Blueprint, new FeatureNode(name, feature.SourceLevel, feature.Blueprint, source));
                    }
                }

                // get nodes (classes)
                foreach (var characterClass in progression.Classes.Select(item => item.CharacterClass))
                {
                    normalNodes.Add(characterClass, new FeatureNode(characterClass.Name, 0, characterClass, null));
                }

                // set source selection
                var selectionNodes = normalNodes.Values
                                     .Where(item => item.Blueprint is BlueprintFeatureSelection).ToList();

                for (var level = 0; level <= 100; level++)
                {
                    foreach (var selection in selectionNodes)
                    {
                        foreach (var feature in progression.GetSelections(selection.Blueprint as BlueprintFeatureSelection, level))
                        {
                            FeatureNode node = default;
                            if (feature is BlueprintParametrizedFeature)
                            {
                                node = parametrizedNodes
                                       .FirstOrDefault(item => item.Source != null && item.Source == selection.Source);
                            }

                            if (node != null || normalNodes.TryGetValue(feature, out node))
                            {
                                node.Source = selection.Blueprint;
                                node.Level  = level;
                            }
                            else
                            {
                                // missing child
                                normalNodes.Add(feature,
                                                new FeatureNode(string.Empty, level, feature, selection.Blueprint)
                                {
                                    IsMissing = true
                                });
                            }
                        }
                    }
                }

                // build tree
                foreach (var node in normalNodes.Values.Concat(parametrizedNodes).ToList())
                {
                    if (node.Source == null)
                    {
                        RootNodes.Add(node);
                    }
                    else if (normalNodes.TryGetValue(node.Source, out var parent))
                    {
                        parent.ChildNodes.Add(node);
                    }
                    else
                    {
                        // missing parent
                        parent = new FeatureNode(string.Empty, 0, node.Source, null)
                        {
                            IsMissing = true
                        };
                        parent.ChildNodes.Add(node);
                        normalNodes.Add(parent.Blueprint, parent);
                        RootNodes.Add(parent);
                    }
                }
            }
Example #13
0
    public void AddRoot(MapNode fromNode, MapNode toNode)
    {
        if (toNode.Parent != null || !fromNode.Neighbours.Contains(toNode) || RootNodes.Contains(toNode))
        {
            return;
        }

        RootNodes.Add(toNode);
        RootCost = this.CalculateRootCost();

        if (fromNode.Children.Count > 0)
        {
            RootLines.Add(new List <Vector3>()
            {
                fromNode.WorldPosition, toNode.WorldPosition
            });
        }
        else
        {
            var line = RootLines.FirstOrDefault(x => x.Last().Equals(fromNode.WorldPosition));
            line.Add(toNode.WorldPosition);

            var lineStart = line.FirstOrDefault();

            // Check for a switch
            if (lineStart.magnitude > 1)
            {
                // Get lines
                var connectedLines = RootLines.Where(x => x.Contains(lineStart) && x != line).ToList();
                foreach (var connectedLine in connectedLines)
                {
                    // Get the index of
                    var indexOf         = connectedLine.IndexOf(lineStart);
                    var remainingLength = connectedLine.Count - indexOf;
                    var remainingLine   = connectedLine.Where(x => connectedLine.IndexOf(x) >= indexOf).ToList();

                    if (indexOf == 0)
                    {
                        continue;
                    }

                    if (line.Count > remainingLength)
                    {
                        // Do the switch
                        connectedLine.RemoveAll(x => connectedLine.IndexOf(x) >= indexOf);
                        connectedLine.AddRange(line);
                        RootLines.Remove(line);
                        RootLines.Add(remainingLine);
                        break;
                    }
                }
            }
        }

        toNode.Parent = fromNode;
        fromNode.Children.Add(toNode);

        toNode.OnConnectionsUpdated?.Invoke();
        fromNode.OnConnectionsUpdated?.Invoke();
        OnRootNodesUpdated?.Invoke();
    }
Example #14
0
 private void OnAddNode(GraphNode <T> node)
 {
     RootNodes.Add(node);
     LeafNodes.Add(node);
 }
        /// <summary>
        /// Creates the chain.
        /// </summary>
        /// <param name="parameter1">The parameter1.</param>
        /// <param name="parameter2">The parameter2.</param>
        /// <param name="nodes">The nodes.</param>
        /// <exception cref="NotSupportedException"></exception>
        private void CreateChain(TParameter1 parameter1, TParameter2 parameter2, ITree nodes)
        {
            foreach (var treeRoot in nodes.Roots)
            {
                switch (treeRoot)
                {
                case ParameterNode parameterElement:
                {
                    if (!(parameterElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }
                    var parameterGetter = ExpressionGetter.CreateParameterGetter(
                        parameterElement,
                        propertyExpression);
                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)parameterGetter(parameter1, parameter2));

                    Looptree(propertyElement, root);
                    RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement when treeRoot.Next is FieldNode fieldElement:
                {
                    if (!(fieldElement.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)fieldElement.FieldInfo.GetValue(constantElement.Value));

                    Looptree(propertyElement, root);
                    RootNodes.Add(root);
                    break;
                }

                case ConstantNode constantElement:
                {
                    if (!(treeRoot.Next is PropertyNode propertyElement))
                    {
                        continue;
                    }

                    var root = new RootPropertyObserverNode(
                        propertyElement.PropertyInfo,
                        this.OnAction,
                        (INotifyPropertyChanged)constantElement.Value);

                    Looptree(propertyElement, root);
                    RootNodes.Add(root);

                    break;
                }

                default:
                    throw new NotSupportedException();
                }
            }
        }