Esempio n. 1
0
        public void TestMethod1()
        {
            //Arrange
            Folder root = new Folder("Games");

            Folder skyrim = new Folder("Skyrim");

            Folder gameVideos = new Folder("videos");
            Folder gameLevels = new Folder("game_levels");

            root.AddFolder(skyrim);
            skyrim.AddFolder(gameVideos);
            skyrim.AddFolder(gameLevels);

            Folder levelSprites = new Folder("level_sprites");

            gameLevels.AddFolder(levelSprites);

            File spriteOne   = new File("levelOneSprite.spr", 10000);
            File spriteTwo   = new File("levelTwoSprite.spr", 20000);
            File spriteThree = new File("levelThreeSprite.spr", 20000);
            File spriteFour  = new File("levelFourSprite.spr", 30000);

            levelSprites.AddFile(spriteOne);
            levelSprites.AddFile(spriteTwo);
            levelSprites.AddFile(spriteThree);
            levelSprites.AddFile(spriteFour);

            //Act
            gameVideos.AddFile(new File("proverka testa.txt", 100));
            gameVideos.AddFile(new File("proverka testa 222.txt", 100));
            gameVideos.AddFolder(new Folder("popsa"));
            gameVideos.RemoveFile("proverka testa.txt");
            //Assert
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            File file = new File();

            file.Extension = file.FileName;
            Folder root = new Folder("Games");

            Folder skyrim = new Folder("Skyrim");

            Folder gameVideos = new Folder("videos");
            Folder gameLevels = new Folder("game_levels");

            root.AddFolder(skyrim);
            skyrim.AddFolder(gameVideos);
            skyrim.AddFolder(gameLevels);

            Folder levelSprites = new Folder("level_sprites");

            gameLevels.AddFolder(levelSprites);

            File spriteOne   = new File("levelOneSprite.spr", 10000);
            File spriteTwo   = new File("levelTwoSprite.spr", 20000);
            File spriteThree = new File("levelThreeSprite.spr", 20000);
            File spriteFour  = new File("levelFourSprite.spr", 30000);

            File introVideo  = new File("intro.mp4", 300000);
            File endingVideo = new File("ending.mp4", 200000);

            File gameConfigurationFile = new File("game_settings.config", 1000);
            File saveRecordsFile       = new File("saves.config", 2000);

            levelSprites.AddFile(spriteOne);
            levelSprites.AddFile(spriteTwo);
            levelSprites.AddFile(spriteThree);
            levelSprites.AddFile(spriteFour);

            gameVideos.AddFile(introVideo);
            gameVideos.AddFile(endingVideo);

            skyrim.AddFile(gameConfigurationFile);
            skyrim.AddFile(saveRecordsFile);



            Console.WriteLine(skyrim.FolderSize);

            Console.ReadLine();
        }
Esempio n. 3
0
        private static void TraverseDirectory(Folder currentFolder)
        {
            try
            {
                DirectoryInfo currentDirecotoryInfo = new DirectoryInfo(currentFolder.Name);
                DirectoryInfo[] subDirectories = currentDirecotoryInfo.GetDirectories();

                foreach (var file in currentDirecotoryInfo.GetFiles())
                {
                    currentFolder.AddFile(file.Name, (int)file.Length);
                }

                foreach (var dir in subDirectories)
                {
                    currentFolder.AddFolder(dir.FullName);
                }

                foreach (var child in currentFolder.ChildFolders)
                {
                    TraverseDirectory(child);
                }
            }
            catch (UnauthorizedAccessException uae)
            {
                Console.WriteLine("Cannot access directory: {0}", uae.Message);
            }
            catch(DirectoryNotFoundException dnf)
            {
                Console.WriteLine("Directory not found: {0}", dnf.Message);
            }
        }
        private void mnu_addFolder(object sender, EventArgs e)
        {
            TreeViewWix tv = this.TreeView as TreeViewWix;
            Form        f  = null;

            if (this.TreeView != null)
            {
                f = this.TreeView.FindForm();
            }
            DlgFolderName dlg = new DlgFolderName();

            dlg.LoadData(Folder.Folders);
            if (dlg.ShowDialog(f) == DialogResult.OK)
            {
                this.Expand();
                WixFolderNode     fo = Folder.AddFolder(dlg.NewName);
                TreeNodeWixFolder tn = new TreeNodeWixFolder(fo);
                tn.SelectFile += new EventHandler(tn_SelectFile);
                Nodes.Add(tn);
                if (this.TreeView != null)
                {
                    this.TreeView.SelectedNode = tn;
                }
                if (tv != null)
                {
                    tv.OnPropertyValueChanged();
                    UserControlSetupProperties ucp = getHolder();
                    if (ucp != null)
                    {
                        ucp.OnSelectTreeNode(tn);
                    }
                }
            }
        }
 private static void FillDirectoryTree(string path, Folder folder)
 {
     try
     {
         // Append files
         var files = Directory.GetFiles(path);
         foreach (var file in files)
         {
             string   fileName = GetName(file);
             FileInfo fileInfo = new FileInfo(file);
             folder.AddFile(new File(fileName, fileInfo.Length));
         }
         // Append dirs recursively
         var dirs = Directory.GetDirectories(path);
         foreach (var dir in dirs)
         {
             string dirName   = GetName(dir);
             Folder newFolder = new Folder(dirName);
             folder.AddFolder(newFolder);
             FillDirectoryTree(dir, newFolder);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Esempio n. 6
0
        private static void PopulateFolders(string dirName, Folder parentFolder)
        {
            string[] folderItems = Directory.GetFileSystemEntries(dirName);

            foreach (var folderItem in folderItems)
            {
                // If the current node is a filename, don't call recursion and continue
                try
                {
                    Directory.GetDirectories(folderItem);
                }
                catch (IOException ex)
                {
                    FileInfo finfo       = new FileInfo(folderItem);
                    FileItem fileSubItem = new FileItem(folderItem, finfo.Length);
                    parentFolder.AddFile(fileSubItem);
                    continue;
                }
                // Some windows folders could be restricted, so just output a warning message and continue
                catch (UnauthorizedAccessException)
                {
                    Console.WriteLine("Warning: No access to folder {0}", dirName);
                    continue;
                }

                Folder folderSubItem = new Folder(folderItem, true);
                parentFolder.AddFolder(folderSubItem);

                PopulateFolders(folderItem, folderSubItem);
            }
        }
    private Folder DirectoryDFS(Folder folder)
    {
        try
        {
            var files = Directory.GetFiles(folder.Name);
            foreach (string item in files)
            {
                FileInfo fileinfo = new FileInfo(item);
                File file = new File(item, (int)fileinfo.Length);
                folder.AddFile(file);
            }

            var childFolders = Directory.GetDirectories(folder.Name);
            foreach (string item in childFolders)
            {
                Folder subFolder = new Folder(item);
                folder.AddFolder(subFolder);
                DirectoryDFS(subFolder);
            }
        }

        //catches the exceptions given if access restricted folder reached
        catch (UnauthorizedAccessException)
        {
        }

        return folder;
    }
 private static void FillDirectoryTree(string path, Folder folder)
 {
     try
     {
         // Append files
         var files = Directory.GetFiles(path);
         foreach (var file in files)
         {
             string fileName = GetName(file);
             FileInfo fileInfo = new FileInfo(file);
             folder.AddFile(new File(fileName, fileInfo.Length));
         }
         // Append dirs recursively
         var dirs = Directory.GetDirectories(path);
         foreach (var dir in dirs)
         {
             string dirName = GetName(dir);
             Folder newFolder = new Folder(dirName);
             folder.AddFolder(newFolder);
             FillDirectoryTree(dir, newFolder);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
    private static Folder GetAllFilesAndFolders(DirectoryInfo directory)
    {
        Folder currentFolder = new Folder(directory.Name);

        try
        {
            var directories = directory.GetDirectories();
            foreach (var dir in directories)
            {
                currentFolder.AddFolder(GetAllFilesAndFolders(dir));
            }
        }
        catch (UnauthorizedAccessException uae)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(uae.Message);
            Console.ForegroundColor = ConsoleColor.Gray;
        }

        foreach (var file in directory.GetFiles())
        {
            currentFolder.AddFile(new File(file.Name, file.Length));
        }

        return(currentFolder);
    }
    private static Folder GetAllFilesAndFolders(DirectoryInfo directory)
    {
        Folder currentFolder = new Folder(directory.Name);
        try
        {
            var directories = directory.GetDirectories();
            foreach (var dir in directories)
            {
                currentFolder.AddFolder(GetAllFilesAndFolders(dir));
            }
        }
        catch (UnauthorizedAccessException uae)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(uae.Message);
            Console.ForegroundColor = ConsoleColor.Gray;
        }

        foreach (var file in directory.GetFiles())
        {
            currentFolder.AddFile(new File(file.Name, file.Length));
        }

        return currentFolder;
    }
 private static FolderComponent GetFolders(string path)
 {
     FolderComponent folder = new Folder(path);
     folder.AssignRules();
     foreach (var directory in Directory.GetDirectories(path))
     {
         folder.AddFolder(GetFolders(directory));
     }
     return folder;
 }
Esempio n. 12
0
    static Folder Traverse(string root)
    {
        var folder = new Folder(root);

        foreach (string file in Directory.GetFiles(root))
            folder.Add(new File(file, new FileInfo(file).Length));

        foreach (string directory in Directory.GetDirectories(root))
            folder.AddFolder(Traverse(directory));

        return folder;
    }
Esempio n. 13
0
        private Folder CreateFolders()
        {
            Folder root       = new Folder("Collection");
            Folder collection = root.AddFolder("Models", true);

            foreach (Category cat in Category.FindAll())
            {
                collection.AddFolder(cat.Name, false, true, cat);
            }
            collection.AddFolder("All");

            Folder data = root.AddFolder("Data", false, true, new Category());

            data.AddFolder("Categories", false, true, FileType.Categories);
            data.AddFolder("Manufacturers", false, true, FileType.Manufacturers);
            data.AddFolder("Stores", false, true, FileType.Stores);
            data.AddFolder("Railway companies", false, true, FileType.RailwayCompanies);
            data.AddFolder("Decoders", false, true, FileType.Decoders);
            data.AddFolder("Scales / Gauges", false, true, FileType.Gauges);

            return(root);
        }
Esempio n. 14
0
        private static void AddFolder(object sender, ExecutedRoutedEventArgs e)
        {
            Main main = (Main)sender;

            Folder folder = main.SelectedFolder;

            if (folder != null)
            {
                Folder newFolder = folder.AddFolder("New Folder");
                if (newFolder != null)
                {
                    main.SelectedFolder = newFolder;
                    main.FocusEditFolderName();
                }
            }
        }
Esempio n. 15
0
    public static void AddFolders(Folder folder)
    {
        string[] fileNames = Directory.GetFiles(folder.Name);
        foreach (var fileName in fileNames)
        {
            folder.AddFile(new File(fileName));
        }

        string[] childFoldersNames = Directory.GetDirectories(folder.Name);
        foreach (var childFolderName in childFoldersNames)
        {
            Folder childFolder = new Folder(childFolderName);
            folder.AddFolder(childFolder);
            AddFolders(childFolder);
        }
    }
Esempio n. 16
0
        public void Apply(ModelSpecification viewModelSpecification, File mvvmFile)
        {
            var project  = mvvmFile.Project;
            var solution = project.Solution;

            var testProject = solution.Projects.Where(p => p.Name == string.Format("{0}.Tests", project.Name) ||
                                                      p.Name == string.Format("{0}Tests", project.Name)).FirstOrDefault();

            if (testProject != null)
            {
                Folder folderInUnitTestProj = CreateFolderInUnitTestProject(mvvmFile, testProject);

                if (!folderInUnitTestProj.HasFolder("TestScenarios"))
                {
                    folderInUnitTestProj.AddFolder(factory.NewFolder("TestScenarios", folderInUnitTestProj));
                }

                var testScenariosFolder = folderInUnitTestProj.GetSubFolder("TestScenarios");

                foreach (var viewModel in viewModelSpecification.ViewModels)
                {
                    var testScenarioFileName = string.Format("{0}TestScenario.cs", viewModel.Name);
                    var unitTestFileName     = string.Format("{0}Tests.cs", viewModel.Name);

                    if (!testScenariosFolder.HasFile(testScenarioFileName))
                    {
                        var testScenarioFile = factory.NewFile(testScenarioFileName, testScenariosFolder);
                        testScenariosFolder.AddFile(testScenarioFile);
                    }

                    codeGeneratorService.Generate(mvvmFile, testScenariosFolder.GetFile(testScenarioFileName),
                                                  new CodeGeneratorArgs(viewModelSpecification, viewModel, testScenarioCodeGenTemplate));

                    //UnitTests
                    if (!folderInUnitTestProj.HasFile(unitTestFileName))
                    {
                        var unitTestFile = factory.NewFile(unitTestFileName, folderInUnitTestProj);
                        folderInUnitTestProj.AddFile(unitTestFile);

                        codeGeneratorService.Generate(mvvmFile, unitTestFile,
                                                      new CodeGeneratorArgs(viewModelSpecification, viewModel, unitTestCodeGenTemplate));
                    }
                }
            }
        }
        private void GroupItems(ArrayList items)
        {
            var castedItems = items.OfType <FolderItemViewModel>().ToArray();
            var fromDate    = castedItems.Min(x => x.FromDate);
            var toDate      = castedItems.Max(x => x.ToDate);

            var newFolder = Folder.AddFolder("", fromDate, toDate);

            foreach (var item in castedItems)
            {
                item._item.Move(Folder, newFolder);
                Items.Remove(item);
            }

            var newFolderVm = new FolderItemViewModel(newFolder);

            Items.Add(newFolderVm);
        }
    // Traverse input directory using recursive DFS and reflect its structure in input folder
    private static void TraverseDFS(DirectoryInfo directory, Folder currentFolder)
    {
        FileInfo[] files = directory.GetFiles();
        List<File> fileList = new List<File>();
        foreach (var file in files)
        {
            fileList.Add(new File(file.Name, file.Length));
        }

        currentFolder.AddFiles(fileList);

        DirectoryInfo[] children = directory.GetDirectories();
        List<Folder> folderList = new List<Folder>();
        foreach (DirectoryInfo child in children)
        {
            Folder childFolder = new Folder(child.Name);
            currentFolder.AddFolder(childFolder);
            TraverseDFS(child, childFolder);
        }
    }
Esempio n. 19
0
    // Adds all files and folders from 'source' to the root folder recursively
    private static Folder FillFolder(string path, Folder root)
    {
        try
        {
            var source = new DirectoryInfo(path);

            foreach (var file in source.EnumerateFiles())
            {
                root.AddFile(new File(file.Name, file.Length));
            }

            foreach (DirectoryInfo dir in source.EnumerateDirectories())
            {
                root.AddFolder(FillFolder(dir.FullName, new Folder(dir.Name)));                
            }            
        }
        catch (System.Exception)
        { 
        }

        return root;
    }
Esempio n. 20
0
    private void SaveFilesAndDirectories(Folder parent)
    {
        if (parent == null)
        {
            return;
        }

        currentDirectory = new DirectoryInfo(parent.Path);

        FileInfo[] folderFiles;

        try
        {
            folderFiles = currentDirectory.GetFiles();
        }
        catch (UnauthorizedAccessException)
        {
            return;
        }

        foreach (var file in folderFiles)
        {
            parent.AddFile(new File(file.Name, file.Length));
        }

        subDirectories = currentDirectory.GetDirectories();

        Folder subFolder;

        foreach (var directory in subDirectories)
        {
            subFolder = new Folder(directory.FullName, directory.Name);

            parent.AddFolder(subFolder);

            SaveFilesAndDirectories(subFolder);
        }
    }
Esempio n. 21
0
    public static Folder CopyFileSystem(ref Folder directoryToSearch)
    {
        try
        {
            string[] allFilesInCurrentFolder = Directory.GetFiles(directoryToSearch.Name, "*.*");

            //Add the files to the folder
            for (int i = 0; i < allFilesInCurrentFolder.Length; i++)
            {
                long sizeOfNewFile = new FileInfo(allFilesInCurrentFolder[i]).Length;
                File newFile       = new File(allFilesInCurrentFolder[i], sizeOfNewFile);

                directoryToSearch.AddFile(newFile);
            }

            var foldersInCurrentDir = Directory.EnumerateDirectories(directoryToSearch.Name);

            foreach (var folder in foldersInCurrentDir)
            {
                Folder newFolder = new Folder(folder);
                //Add the folder to the folder
                directoryToSearch.AddFolder(newFolder);

                //Check and add files fo the newly added folder
                CopyFileSystem(ref newFolder);
            }
        }
        catch (UnauthorizedAccessException)
        {
            Console.WriteLine("Directory {0} cannot be accessed", directoryToSearch.Name);
        }
        catch (NotSupportedException)
        {
            Console.WriteLine("Directory {0} does not exist.", directoryToSearch.Name);
        }

        return(directoryToSearch);
    }
        public void Go4CreateFolder()
        {
            Console.Write("Parent Directory Folder:");
            string path = Console.ReadLine();

            Console.Write("Folder Name:");
            string folderName = Console.ReadLine();

            Console.Write("Creator :");
            string creator = Console.ReadLine();

            try
            {
                Folder folder       = new Folder(folderName, creator);
                Folder parentFolder = (Folder)rootFolder.GetLastElementFromPath(path);
                parentFolder.AddFolder(folder);
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Message);
                Console.ResetColor();
            }
        }
Esempio n. 23
0
        public void AddFolderTest()
        {
            folder.AddFolder(dummyFolder);

            Assert.AreEqual(dummyFolder, folder.Folders[0]);
        }
Esempio n. 24
0
 public static void AddFolder(Folder folder, Config config)
 {
     folder.AddFolder();
 }