コード例 #1
0
ファイル: VsHierarchy.cs プロジェクト: zpublic/vs-chromium
        private void LoadDirectoryNodeChildren(DirectoryNodeViewModel directoryNode)
        {
            if (directoryNode.ChildrenLoaded)
            {
                return;
            }

            var directoryEntry = _nodeViewModelLoader.LoadChildren(directoryNode);

            if (directoryEntry == null)
            {
                return;
            }

            var children = directoryEntry.Entries
                           .Select(childEntry => {
                var node = IncrementalHierarchyBuilder.CreateNodeViewModel(_nodeTemplateFactory, childEntry, directoryNode);

                // Initialize template icon if needed
                if (node is FileNodeViewModel)
                {
                    if (node.Template.Icon == null)
                    {
                        var extension = PathHelpers.GetExtension(childEntry.Name);
                        Invariants.Assert(extension != null);
                        node.Template.Icon = _imageSourceFactory.GetFileExtensionIcon(extension);
                    }
                }

                return(node);
            })
                           .ToList();

            foreach (var child in children)
            {
                child.ItemId = _nodes.MaxItemId + 1;
                _nodes.AddNode(child);
            }

            directoryNode.SetChildren(children);
        }
コード例 #2
0
        private ApplyChangesResult ApplyChanges(IncrementalBuildResult buildResult, int hierarchyVersion,
                                                int latestFileSystemTreeVersion)
        {
            // We need to load these images on the main UI thread
            buildResult.FileTemplatesToInitialize.ForAll(item => {
                item.Value.Icon = _imageSourceFactory.GetFileExtensionIcon(item.Key);
            });

            // Apply if nobody beat us to is.
            if (_hierarchy.Version == hierarchyVersion)
            {
                Logger.LogInfo(
                    "Updating VsHierarchy nodes for version {0} and file system tree version {1}",
                    hierarchyVersion,
                    _treeVersion);
                _hierarchy.SetNodes(buildResult.NewNodes, buildResult.Changes);
                return(ApplyChangesResult.Done);
            }

            Logger.LogInfo(
                "VsHierarchy nodes have been updated concurrently, re-run or skip operation." +
                " Node verions={0}-{1}, Tree versions:{2}-{3}.",
                hierarchyVersion, _hierarchy.Version,
                _treeVersion, latestFileSystemTreeVersion);

            // If the version of the hieararchy has changed since when we started,
            // another thread has passed us.  This means the decisions we made
            // about the changes to apply are incorrect at this point. So, we run
            // again if we are processing the latest known version of the file
            // system tree, as we should be the winner (eventually)
            if (_treeVersion == latestFileSystemTreeVersion)
            {
                // Termination notes: We make this call only when the VsHierarchy
                // version changes between the time we capture it and this point.
                return(ApplyChangesResult.Retry);
            }

            return(ApplyChangesResult.Bail);
        }