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 }
private void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Remove: switch (_DataList.Tag.ToString()) { case TAG_FIXCOST: DataFolder.AddFile(_DataList.Tag.ToString(), RootManager.Fixcosts.ToArray()); break; case TAG_SERVICE: DataFolder.AddFile(_DataList.Tag.ToString(), RootManager.Services.ToArray()); break; } break; } if (e.NewItems != null && e.NewItems.Count > 0) { foreach (var item in e.NewItems) { var listItem = new ListViewItem(); listItem.Checked = true; if (sender is ObservableCollection <FixcostItem> ) { var fixcostItem = item as FixcostItem; listItem.Text = fixcostItem.Name; listItem.SubItems.Add(fixcostItem.Price.ToString("C2")); listItem.Tag = item; listViewFixcosts.Items.Add(listItem); continue; } if (sender is ObservableCollection <ServiceItem> ) { var serviceItem = item as ServiceItem; listItem.Text = serviceItem.Name; listItem.SubItems.Add(serviceItem.Price.ToString("C2")); listItem.Tag = item; listViewServices.Items.Add(listItem); continue; } } } _DataList.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); UpdateForm(); }
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(); }
public void Go4CreateFile() { Console.Write("Parent Directory File:"); string path = Console.ReadLine(); Console.Write("File Name:"); string fileName = Console.ReadLine(); Console.Write("Creator :"); string creator = Console.ReadLine(); Console.Write("Format :"); string format = Console.ReadLine(); try { Console.Write("Size :"); decimal size = Convert.ToDecimal(Console.ReadLine()); File file = new File(fileName, creator, format, size); Folder parentFolder = (Folder)rootFolder.GetLastElementFromPath(path); parentFolder.AddFile(file); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e.Message); Console.ResetColor(); } }
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); } }
public override void Move(long EntityId, long folderId) { FolderElementExists(EntityId); if (_folderRepository.Get(folderId) == null) { throw new Exception("El elemento no existe."); } File Entity = _repository.Get(EntityId); Folder folder = _folderRepository.Get(folderId); IsTheSameOwner(Entity, folder); Folder folderWhereFileWas = Entity.Parent; Folder folderWhereIsIt = folder; File filePrevious = Entity; folderFileNull(Entity.Parent); Entity.Parent.RemoveFile(Entity); _folderRepository.Update(folderWhereFileWas, Entity.Parent); Entity.Parent = folder; Entity.LastModifiedDate = DateTime.Now; folderFileNull(folder); folder.AddFile(Entity); _repository.Update(filePrevious, Entity); _folderRepository.Update(folderWhereIsIt, folder); }
protected override void ProcessRecord() { base.ProcessRecord(); var ctx = base.Context; Dictionary <string, object> fieldValues = null; if (FieldValues != null) { fieldValues = FieldValues.Read(); } byte[] content = System.IO.File.ReadAllBytes(File); System.IO.FileInfo file = new System.IO.FileInfo(File); string leafName = file.Name; if (ParameterSetName == "List") { var web = ctx.Site.OpenWeb(Web.Read()); SPOList list = List.Read(web, true); WriteObject(list.AddFile(content, Overwrite, leafName, fieldValues)); } else { WriteObject(Folder.AddFile(content, Overwrite, leafName, fieldValues)); } }
public static void AddFiles(Folder folder, params string[] files) { foreach (var file in files) { folder.AddFile(file); } }
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 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 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 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 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 void LoadFiles(ContentReader input, Folder folder, int fileCount) { for (int file = 0; file < fileCount; file++) { // file on id string name = input.ReadString(); int w = input.ReadInt32(); int h = input.ReadInt32(); float pivotX = input.ReadSingle(); float pivotY = input.ReadSingle(); folder.AddFile(new File(file, name, new Dimension(w, h), new Point(pivotX, pivotY))); } }
private void AddFiles(Folder folder, string[] files) { foreach (var fileName in files) { var fileId = ProcessRecordsFile(JohnId.ToString(), fileName, new Dictionary <string, object>() { { "parentId", folder.Id } }).Result; folder.AddFile(fileName, fileId); } // FilesId[parentId].Add(fileId); }
public override File Add(File entity) { ValidateFormat(entity); entity.LastModifiedDate = DateTime.Now; entity.CreationDate = DateTime.Now; entity.Parent = GetFileId(entity.Parent.Id); Folder folderBefore = entity.Parent; Folder folderAfter = entity.Parent; folderFileNull(folderAfter); _repository.Add(entity); folderAfter.AddFile(entity); _folderRepository.Update(folderBefore, folderAfter); return(entity); }
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); } }
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 GeneratePath(ListingAssets.AssetReferences asset) { try { string[] dirs = Path.GetDirectoryName(asset.asset).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); string extension = Path.GetExtension(asset.asset); Folder folder = this.root; // Skip Assets folder. for (int i = 1; i < dirs.Length; i++) { folder = folder.GenerateFolder(dirs[i]); } folder.AddFile(asset.mainAssetIndex, asset.IDs, asset.subNames, asset.types, extension); } catch (Exception ex) { InternalNGDebug.LogException("Embedded asset \"" + asset.asset + "\" contains an error.", ex); } }
public void mnu_addSourceFolder(object sender, EventArgs e) { TreeViewWix tv = this.TreeView as TreeViewWix; Form f = null; if (this.TreeView != null) { f = this.TreeView.FindForm(); } FolderBrowserDialog dlg = new FolderBrowserDialog(); dlg.Description = "All files in the selected folder will be included in the setup"; if (dlg.ShowDialog(f) == DialogResult.OK) { bool b = true; WixSourceFileNode fn = Folder.GetWixNodeByName(dlg.SelectedPath); if (fn != null) { MessageBox.Show(f, "Source folder is already included", "Add Source Folder", MessageBoxButtons.OK, MessageBoxIcon.Information); b = false; } else { fn = Folder.AddFile(dlg.SelectedPath); } if (SelectFile != null) { SelectFile(fn, EventArgs.Empty); } if (b && tv != null) { tv.OnPropertyValueChanged(); UserControlSetupProperties ucp = getHolder(); if (ucp != null) { ucp.OnSelectTreeNode(this); } } } }
// 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; }
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); }
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); } }
static void Main(string[] args) { string s; Folder folder = new Folder(); while (!String.IsNullOrEmpty(s = Console.ReadLine())) { string[] comand = s.Split(); string filename; switch (comand[0]) { case "create": filename = comand[1]; int size = int.Parse(comand[2]); try { folder.AddFile(filename, size); Console.WriteLine($"Sucsessfully added {filename}"); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case "print_by_name": filename = comand[1]; try { Console.WriteLine(folder[filename]); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case "print_by_number": int fileNumber = int.Parse(comand[1]); try { Console.WriteLine(folder[fileNumber]); } catch (IndexOutOfRangeException ex) { Console.WriteLine(ex.Message); } break; case "remove": try { filename = comand[1]; folder.RemoveFile(folder[filename]); Console.WriteLine($"Sucsessfully removed {filename}"); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } break; case "backup": backups.Add(folder.GetBackup()); Console.WriteLine($"Sucsessfully created {backups.Count - 1}"); break; case "restore": int backupNumber = int.Parse(comand[1]); folder.RestoreBackup(backups[backupNumber]); Console.WriteLine($"Sucsessfully restored"); break; case "show_all": Console.WriteLine(folder); break; } } Console.Out.Close(); }
public void AddFileTest() { folder.AddFile(file); Assert.AreEqual(file, folder.Files[0]); }