private void AssertTreeIsEmpty(FileSystemTree tree) {
   Assert.IsNotNull(tree.Root);
   Assert.IsNotNull(tree.Root.Name);
   Assert.AreEqual("", tree.Root.Name);
   Assert.IsNotNull(tree.Root.Entries);
   Assert.AreEqual(0, tree.Root.Entries.Count);
 }
 public IncrementalHierarchyBuilderAggregate(
   INodeTemplateFactory nodeTemplateFactory,
   VsHierarchyAggregate hierarchy,
   FileSystemTree fileSystemTree,
   IImageSourceFactory imageSourceFactory) {
   _templateFactory = nodeTemplateFactory;
   _hierarchy = hierarchy;
   _fileSystemTree = fileSystemTree;
   _imageSourceFactory = imageSourceFactory;
 }
Exemple #3
0
 public void SetFileSystemTree(FileSystemTree tree)
 {
     _fileSystemEntryRootNodes = tree.Root
     .Entries
     .Select(x => FileSystemEntryViewModel.Create(_sourceExplorerViewModelHost, null, x))
     .ToList();
       ExpandNodes(_fileSystemEntryRootNodes, false);
       SwitchToFileSystemTree();
 }
 private void FileSystemTreeSource_OnTreeReceived(FileSystemTree fileSystemTree) {
   WpfUtilities.Post(this, () => {
     Controller.OnFileSystemTreeComputed(fileSystemTree);
   });
 }
    private IEnumerable<RootEntry> CreateRootEntries(List<VsHierarchy> oldHierarchies) {
      foreach (var hierarchy in oldHierarchies) {
        var rootPath = GetHierarchyRootPath(hierarchy);

        var directoryEntry = _fileSystemTree.Root.Entries.FirstOrDefault(x => x.Name == rootPath);
        if (directoryEntry == null) {
          // Hierarchy should be deleted, as its root does not exist in new tree
          var fakeTree = new FileSystemTree {
            Version = _fileSystemTree.Version,
            Root = new DirectoryEntry() {
              Name = _fileSystemTree.Root.Name,
              Entries = new List<FileSystemEntry>()
            }
          };
          yield return new RootEntry {
            RootPath = rootPath,
            FileSystemTree = fakeTree,
            Hierarchy = hierarchy,
            Builder = new IncrementalHierarchyBuilder(_templateFactory, hierarchy, fakeTree, _imageSourceFactory)
          };
        } else {
          // Hierarchy should be updated with new root entry
          var fakeTree = new FileSystemTree {
            Version = _fileSystemTree.Version,
            Root = new DirectoryEntry() {
              Name = _fileSystemTree.Root.Name,
              Entries = new List<FileSystemEntry> { directoryEntry }
            }
          };
          yield return new RootEntry {
            RootPath = rootPath,
            FileSystemTree = fakeTree,
            Hierarchy = hierarchy,
            Builder = new IncrementalHierarchyBuilder(_templateFactory, hierarchy, fakeTree, _imageSourceFactory)
          };
        }
      }

      // Look for new hierarchies
      foreach (var directoryEntry in _fileSystemTree.Root.Entries) {
        var rootPath = directoryEntry.Name;
        var hierarchy = oldHierarchies.FirstOrDefault(x => GetHierarchyRootPath(x) == rootPath);
        if (hierarchy == null) {
          // A new hierarchy should be created
          var fakeTree = new FileSystemTree {
            Version = _fileSystemTree.Version,
            Root = new DirectoryEntry() {
              Name = _fileSystemTree.Root.Name,
              Entries = new List<FileSystemEntry> { directoryEntry }
            }
          };
          var newHierarchy = _hierarchy.CreateHierarchy();
          yield return new RootEntry {
            RootPath = rootPath,
            FileSystemTree = fakeTree,
            Hierarchy = newHierarchy,
            Builder = new IncrementalHierarchyBuilder(_templateFactory, newHierarchy, fakeTree, _imageSourceFactory)
          };
        }
      }
    }
    private IIncrementalHierarchyBuilder CreateIncrementalBuilder(FileSystemTree fileSystemTree) {
      var vsHierarchy = _hierarchy as VsHierarchy;
      if (vsHierarchy != null) {
        return new IncrementalHierarchyBuilder(
          _nodeTemplateFactory,
          vsHierarchy,
          fileSystemTree,
          _imageSourceFactory);
      }

      var vsHierarchyAggregate = _hierarchy as VsHierarchyAggregate;
      if (vsHierarchyAggregate != null) {
        return new IncrementalHierarchyBuilderAggregate(
          _nodeTemplateFactory,
          vsHierarchyAggregate,
          fileSystemTree,
          _imageSourceFactory);
      }

      Debug.Assert(false);
      return null;
    }
    private void ApplyFileSystemTreeToVsHierarchy(FileSystemTree fileSystemTree) {
      var builder = CreateIncrementalBuilder(fileSystemTree);
      var applyChanges = builder.ComputeChangeApplier();

      _synchronizationContextProvider.UIContext.Post(() => {
        var result = applyChanges(_latestFileSystemTreeVersion);
        if (result == ApplyChangesResult.Retry) {
          PostApplyFileSystemTreeToVsHierarchy(fileSystemTree);
        }
      });
    }
 private void PostApplyFileSystemTreeToVsHierarchy(FileSystemTree fileSystemTree) {
   _delayedOperationProcessor.Post(
     new DelayedOperation {
       Id = "ApplyFileSystemTreeToVsHierarchy",
       Action = () => ApplyFileSystemTreeToVsHierarchy(fileSystemTree),
       Delay = TimeSpan.FromSeconds(0.1),
     });
 }
    /// <summary>
    /// Note: This is executed on a background thred.
    /// </summary>
    private void OnTreeReceived(FileSystemTree fileSystemTree) {
      if (!_globalSettingsProvider.GlobalSettings.EnableSourceExplorerHierarchy)
        return;

      _latestFileSystemTreeVersion = fileSystemTree.Version;
      PostApplyFileSystemTreeToVsHierarchy(fileSystemTree);
    }
 protected virtual void OnTreeReceived(FileSystemTree obj) {
   var handler = TreeReceived;
   if (handler != null) handler(obj);
 }