Exemplo n.º 1
0
        private void ProcessChildFile(DirectoryItem <T> directory, XElement f)
        {
            var fileName = CreateFileName(directory, f);
            var fileData = GetFileData(f);

            AddFileToDirectory(directory, fileName, fileData);
        }
Exemplo n.º 2
0
        private void ProcessChild(XElement child, DirectoryItem <T> parent)
        {
            string directoryName = CreateDirectoryName(parent, child);
            var    directory     = AddSubdirectory(parent, directoryName);

            var files = child.Elements("file");

            foreach (var f in files)
            {
                ProcessChildFile(directory, f);
            }

            foreach (var d in child.Elements("dir"))
            {
                ProcessChild(d, directory);
            }
        }
Exemplo n.º 3
0
        private void AddFileToDirectory(DirectoryItem <T> dir, string fullFileName, T fileData)
        {
            int sameFilesCount = dir.Files.Select(f => f.File).Where(f => f.FullName == fullFileName).Count();

            if (sameFilesCount == 0)
            {
                dir.Files.Add(new FileItem <T>()
                {
                    File = new FsFile(fullFileName),
                    Data = fileData
                });
            }
            else
            {
                throw new Exception(
                          String.Format("Attempted to add duplicate file={0} in the same directory={1}.",
                                        dir.Dir.FullName, fullFileName));
            }
        }
Exemplo n.º 4
0
        private void InitFileSystem(string xml)
        {
            XElement   rootElement   = XElement.Parse(xml);
            XAttribute rootAttribute = rootElement.Attribute("root");

            Root = new DirectoryItem <T>(null)
            {
                Dir = new Dir(rootAttribute.Value)
            };

            foreach (var child in rootElement.Elements("dir"))
            {
                ProcessChild(child, Root);
            }

            foreach (var childFile in rootElement.Elements("file"))
            {
                ProcessChildFile(Root, childFile);
            }
        }
Exemplo n.º 5
0
        private DirectoryItem <T> AddSubdirectory(DirectoryItem <T> parent, string directoryName)
        {
            int sameDirsCount = parent.Childs.Select(c => c.Dir.FullName).
                                Where(s => s == directoryName).Count();

            if (sameDirsCount == 0)
            {
                var subDir = new DirectoryItem <T>(parent)
                {
                    Dir = new Dir(directoryName)
                };

                parent.Childs.Add(subDir);

                return(subDir);
            }
            else
            {
                throw new Exception(); // duplicate detected
            }
        }
Exemplo n.º 6
0
 private string CreateFileName(DirectoryItem <T> parent, XElement fileElement)
 {
     return(Path.Combine(parent.Dir.FullName, fileElement.Attribute("name").Value));
 }
Exemplo n.º 7
0
 public DirectoryItem(DirectoryItem <T> parent)
 {
     Files  = new List <FileItem <T> >();
     Childs = new List <DirectoryItem <T> >();
     Parent = parent;
 }