123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.ObjectModel;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Caliburn.Micro.Core;
- namespace VirgoUI.Client.Models.Recipe
- {
- public class FileNode : PropertyChangedBase
- {
- public FileNode()
- {
- this.Files = new ObservableCollection<FileNode>();
- this.IsFile = false;
- }
- private string name = string.Empty;
- public string Name
- {
- get { return name; }
- set { name = value; NotifyOfPropertyChange("Name"); }
- }
- public string FullPath { get; set; }
- public FileNode Parent { get; set; }
- public ObservableCollection<FileNode> Files { get; set; }
- public bool IsFile { get; set; }
- }
-
- public class RecipeSequenceTreeBuilder
- {
- public static List<FileNode> GetFiles(List<string> filenames)
- {
- List<FileNode> folders = new List<FileNode>();
- FileNode root = new FileNode() { Name = "Files", IsFile = false, FullPath="" };
- folders.Add(root);
- foreach(string filename in filenames)
- {
- string[] filesplits = filename.Split('\\');
- FileNode parent = root;
- if (filesplits.Length>1)
- {
- for(var index =0;index< filesplits.Length-1; index++)
- {
- bool found = false;
- for(var j = 0; j < parent.Files.Count; j++)
- {
- if(parent.Files[j].Name == filesplits[index] && !parent.Files[j].IsFile)
- {
- found = true;
- parent = parent.Files[j];
- break;
- }
- }
- if (!found)
- {
- FileNode folder = new FileNode() { Name = filesplits[index], IsFile = false };
- folder.FullPath = (parent.FullPath == string.Empty ? filesplits[index] : parent.FullPath + "\\" + filesplits[index]);
- folder.Parent = parent;
- parent.Files.Add(folder);
- parent = folder;
- }
- }
- }
- FileNode file = new FileNode() { Name = filesplits[filesplits.Length - 1], IsFile = true };
- file.FullPath = (parent.FullPath == string.Empty ? filesplits[filesplits.Length - 1] : parent.FullPath + "\\" + filesplits[filesplits.Length - 1]);
- file.Parent = parent;
- parent.Files.Add(file);
- }
- return folders;
- }
- }
- }
|