Esempio n. 1
0
    public async Task LoadDirectoryRecursive(DomainExportedObject Parent, string Path) {
      DirectoryInfo   dirInfo  = new DirectoryInfo(Path);
      DirectoryInfo[] dirInfos = await Task.Run(() => dirInfo.GetDirectories());

      if (dirInfos.Length > 0) {
        Parent.Children = dirInfos.Select(dir => new DomainExportedObject { Filename = dir.FullName, Parent = Parent, Children = new List<DomainExportedObject>() }).ToList();

        foreach(DomainExportedObject exportedDir in Parent.Children) {
          await LoadDirectoryRecursive(exportedDir, exportedDir.Filename);
        }
      }

      FileInfo[] files = await Task.Run(() => dirInfo.GetFiles());

      if (files.Length > 0) {
        Parent.Children.AddRange(files.Select(f => new DomainExportedObject { Filename = f.FullName, Parent = Parent }).ToList());
      }
    }
Esempio n. 2
0
    private async void loadExportFiles() {
      if (String.IsNullOrEmpty(settings.ExportPath)) return;

      try {
        DomainExportedObject root = new DomainExportedObject();

        await repository.LoadDirectoryRecursive(root, settings.ExportPath);

        if (root.Children == null || !root.Children.Any()) return;

        viewModel.ExportsTree?.Traverse(e => true).ToList().ForEach(e => e.PropertyChanged -= onExportedObjectViewEntityChanged);

        IEnumerable<ExportedObjectViewEntity> temp = mapper.Map<IEnumerable<ExportedObjectViewEntity>>(root.Children);

        viewModel.ExportsTree = new ObservableCollection<ExportedObjectViewEntity>(temp);

        viewModel.ExportsTree.Traverse(e => true).ToList().ForEach(e => e.PropertyChanged += onExportedObjectViewEntityChanged);
      }
      catch(FileNotFoundException) { }
      catch(DirectoryNotFoundException) { }
      catch(Exception ex) {
        messenger.Send(new ApplicationErrorMessage { ErrorMessage = ex.Message, Exception = ex });
      }
    }