public SourceCodeListViewModel(IGame game) { this.game = game; List<DirectoryListing> baseListings = new List<DirectoryListing>(); foreach (ISourceCode source in game.Sources) { string dn = Path.GetDirectoryName(source.RelativeName); string[] dirs = Regex.Split(dn, @"[\\/]"); DirectoryListing d = null; foreach (var baseListing in baseListings) { if (baseListing.Name == dirs[0]) { d = baseListing; } } if (d == null) { d = new DirectoryListing(); d.Name = dirs[0]; baseListings.Add(d); } d.GetOrCreateDirectoryListing(dirs).Sources.Add(source); } DirectoryListings = baseListings; }
/// <summary> /// Builds the tree view. /// </summary> /// <param name="soap">The SOAP response.</param> public static TreeNode BuildTreeView(DirectoryListing directory) { var tree = new TreeNode("root"); AddTreeNode(tree, directory); return(tree.Nodes[0]); }
public void TestDirectoryListing() { using var runner = TestRunner.Run(DirectoryListing.From("./").Add(new ContentPrinterBuilder())); using var response = runner.GetResponse(); Assert.Contains("Acceptance", response.GetContent()); }
public FileManagerDirectory(CommandContext commandContext, Server server, VirtualDirectorySecurity vds, DirectoryListing listing, string currentDirectory) { CommandContext = commandContext; FileSystem = server.FileSystemService; Listing = listing; CurrentDirectory = currentDirectory; VirtualDirectorySecurity = vds; }
public bool PrepCurrentPath(DirectoryListing dirList, int courseId, string relativePathStart, string authToken) { if (!IsValidKey(authToken)) { return(false); } relativePathStart = CleanPath(relativePathStart); FileSystem.PrepCourseDocuments(dirList, courseId, relativePathStart); return(true); }
public void GetDirectoryStatusTest() { string folderName = "newFolder"; var client = CreateClient(); client.CreateDirectory(string.Format("{0}/{1}", defaultFilePath, folderName)); DirectoryListing list = client.GetDirectoryStatusAsync(defaultFilePath).Result; Assert.AreEqual(1, list.Entries.Count(e=>e.EntryType==DirectoryEntryType.DIRECTORY), "Unexpected number of directories found in directory listing."); Assert.AreEqual(1, list.Entries.Count(e => e.EntryType == DirectoryEntryType.FILE), "Unexpected number of files found in directory listing."); Assert.AreEqual(folderName, list.Entries.Single(e => e.EntryType == DirectoryEntryType.DIRECTORY).PathSuffix, "Directory listing should contain folder name."); Assert.AreEqual(testFileName, list.Entries.Single(e => e.EntryType == DirectoryEntryType.FILE).PathSuffix, "Directory listing should contain file name."); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.FS.UnresolvedLinkException"/> public override FileStatus[] ListStatus(Path f) { string src = GetUriPath(f); // fetch the first batch of entries in the directory DirectoryListing thisListing = dfs.ListPaths(src, HdfsFileStatus.EmptyName); if (thisListing == null) { // the directory does not exist throw new FileNotFoundException("File " + f + " does not exist."); } HdfsFileStatus[] partialListing = thisListing.GetPartialListing(); if (!thisListing.HasMore()) { // got all entries of the directory FileStatus[] stats = new FileStatus[partialListing.Length]; for (int i = 0; i < partialListing.Length; i++) { stats[i] = partialListing[i].MakeQualified(GetUri(), f); } return(stats); } // The directory size is too big that it needs to fetch more // estimate the total number of entries in the directory int totalNumEntries = partialListing.Length + thisListing.GetRemainingEntries(); AList <FileStatus> listing = new AList <FileStatus>(totalNumEntries); // add the first batch of entries to the array list foreach (HdfsFileStatus fileStatus in partialListing) { listing.AddItem(fileStatus.MakeQualified(GetUri(), f)); } do { // now fetch more entries thisListing = dfs.ListPaths(src, thisListing.GetLastName()); if (thisListing == null) { // the directory is deleted throw new FileNotFoundException("File " + f + " does not exist."); } partialListing = thisListing.GetPartialListing(); foreach (HdfsFileStatus fileStatus_1 in partialListing) { listing.AddItem(fileStatus_1.MakeQualified(GetUri(), f)); } }while (thisListing.HasMore()); return(Sharpen.Collections.ToArray(listing, new FileStatus[listing.Count])); }
public static void PrepCourseDocuments(DirectoryListing listing, int courseId, string previousPath = "") { string coursePath = GetCourseDocumentsPath(courseId); string rootPath = Path.Combine(coursePath, previousPath); foreach (DirectoryListing dl in listing.Directories) { string directoryPath = Path.Combine(rootPath, dl.Name); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } PrepCourseDocuments(dl, courseId, previousPath + dl.Name + "\\"); } }
/// <exception cref="System.IO.IOException"/> private DirListingIterator(Hdfs _enclosing, Path p, bool needLocation) { this._enclosing = _enclosing; // if status this.src = this._enclosing.GetUriPath(p); this.needLocation = needLocation; // fetch the first batch of entries in the directory this.thisListing = this._enclosing.dfs.ListPaths(this.src, HdfsFileStatus.EmptyName , needLocation); if (this.thisListing == null) { // the directory does not exist throw new FileNotFoundException("File " + this.src + " does not exist."); } }
private TestRunner GetEnvironment() { var tempFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempFolder); Directory.CreateDirectory(Path.Combine(tempFolder, "Subdirectory")); Directory.CreateDirectory(Path.Combine(tempFolder, "With Spaces")); File.WriteAllText(Path.Combine(tempFolder, "my.txt"), "Hello World!"); var listing = DirectoryListing.From(tempFolder); return(TestRunner.Run(listing)); }
public EListingType GetListingType(int index, DirectoryListing directoryListing) { try { if (FileSystem.DirectoryExists(directoryListing.Directories[index - 1].FullName)) { return(EListingType.Directory); } } catch { return(EListingType.File); } return(EListingType.Unknown); }
/// <exception cref="System.Exception"/> internal virtual void VerifyFile(Path file, byte expectedPolicyId) { Path parent = file.GetParent(); DirectoryListing children = this.dfs.GetClient().ListPaths(parent.ToString(), HdfsFileStatus .EmptyName, true); foreach (HdfsFileStatus child in children.GetPartialListing()) { if (child.GetLocalName().Equals(file.GetName())) { this.VerifyFile(parent, child, expectedPolicyId); return; } } NUnit.Framework.Assert.Fail("File " + file + " not found."); }
private List <FileInformation> GetRemoteFolderListing(FileInformation folder) { DirectoryListing dl = m_networking.GetDirectoryListing(folder.Filename, true); string fullPath = folder.Filename.GetPath(PathReturnType.GetSeparator, PathFormat.Unix); List <string> fullFileNames = dl.fileNames.ConvertAll <string>( name => { FilePath fp = new FilePath(fullPath, name, PathFormat.Unix); string s = fp.GetFullPath(); return(s); }).ToList(); List <FileInformation> files = NamesToFileInformation(fullFileNames, PathFormat.Unix); return(files); }
/// <summary> /// Adds the tree node. /// </summary> /// <param name="node">The node.</param> /// <param name="dir">The dir.</param> private static void AddTreeNode(TreeNode node, DirectoryListing dir) { if (dir.IsDirectory) { var n = node.Nodes.Add(dir.Name); n.ForeColor = Color.Blue; foreach (var child in dir.SubDirectories.OrderBy(d => d.Name) .OrderByDescending(d => d.IsDirectory)) { // recursion! AddTreeNode(n, child); } } else { node.Nodes.Add(dir.Name); } }
/// <summary> /// c = command, c_Dir /// </summary> /// <param name="dir">The directory path that you wish to pass in</param> public static void c_Dir(string dir) { string directory; //args commands Char cmdargschar = ' '; string[] cmdargs = dir.Split(cmdargschar); if (!cmdargs[1].StartsWith("-")) { directory = cmdargs[1]; if (Directory.Exists(Kernel.current_directory + directory)) { DirectoryListing.DispDirectories(Kernel.current_directory + directory); DirectoryListing.DispFiles(Kernel.current_directory + directory); } } else { if (cmdargs[1].Equals("-a")) { DirectoryListing.DispDirectories(Kernel.current_directory); DirectoryListing.DispHiddenFiles(Kernel.current_directory); if (cmdargs.Length == 3) { directory = cmdargs[2]; DirectoryListing.DispDirectories(Kernel.current_directory + directory); DirectoryListing.DispHiddenFiles(Kernel.current_directory + directory); } } else { L.Text.Display("invalidargument"); } } Console.WriteLine(); }
/// <exception cref="System.IO.IOException"/> public virtual bool HasNext() { if (this.thisListing == null) { return(false); } if (this.i >= this.thisListing.GetPartialListing().Length&& this.thisListing.HasMore ()) { // current listing is exhausted & fetch a new listing this.thisListing = this._enclosing.dfs.ListPaths(this.src, this.thisListing.GetLastName (), this.needLocation); if (this.thisListing == null) { return(false); } // the directory is deleted this.i = 0; } return(this.i < this.thisListing.GetPartialListing().Length); }
/// <exception cref="System.Exception"/> private void VerifyRecursively(Path parent, HdfsFileStatus status) { if (status.IsDir()) { Path fullPath = parent == null ? new Path("/") : status.GetFullPath(parent); DirectoryListing children = this.dfs.GetClient().ListPaths(fullPath.ToString(), HdfsFileStatus .EmptyName, true); foreach (HdfsFileStatus child in children.GetPartialListing()) { this.VerifyRecursively(fullPath, child); } } else { if (!status.IsSymlink()) { // is file this.VerifyFile(parent, status, null); } } }
/// <summary> /// CommandDir /// </summary> public override ReturnInfo Execute(List <string> arguments) { string directory; if (!arguments[0].StartsWith("-")) { directory = arguments[0]; if (Directory.Exists(Kernel.current_directory + directory)) { DirectoryListing.DispDirectories(Kernel.current_directory + directory); DirectoryListing.DispFiles(Kernel.current_directory + directory); } } else { if (arguments[0].Equals("-a")) { DirectoryListing.DispDirectories(Kernel.current_directory); DirectoryListing.DispHiddenFiles(Kernel.current_directory); if (arguments.Count == 2) { directory = arguments[1]; DirectoryListing.DispDirectories(Kernel.current_directory + directory); DirectoryListing.DispHiddenFiles(Kernel.current_directory + directory); } } else { return(new ReturnInfo(this, ReturnCode.ERROR_ARG)); } } Console.WriteLine(); return(new ReturnInfo(this, ReturnCode.OK)); }
public DirectoryListing ParseDirectoringListing(string html) { var res = new DirectoryListing { Directories = new Dictionary <string, string>() }; var htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(html); foreach (var n in htmlDoc.DocumentNode.SelectNodes(@"//a")) { if (n.InnerText.ToLowerInvariant().Contains("parent directory")) { res.ParentPage = n.GetAttributeValue("href", string.Empty); } else { res.Directories.Add(n.InnerText.Trim(), n.GetAttributeValue("href", string.Empty)); } } return(res); }
static void Main(string[] args) { CocoLib.Logging.Functions.Directory = "C:\\Users\\Zach\\Desktop\\Log.txt"; AutoInstruction instruction = new AutoInstruction(); Scalar command1 = new Scalar() { Distance = new Distance() { Amount = 10, Unit = LinearUnit.Feet }, Type = CommandType.Drive }; instruction.Commands.Add(command1); instruction.Save("C:\\Users\\Zach\\Desktop\\Auto\\AutoRed1.json"); string prefix = "C:\\Users\\Zach\\Desktop\\Auto\\"; DirectoryListing listing = new DirectoryListing() { AutoBlue1 = prefix + "AutoBlue1.json", AutoBlue2 = prefix + "AutoBlue2.json", AutoBlue3 = prefix + "AutoBlue3.json", AutoBlue4 = prefix + "AutoBlue4.json", AutoRed1 = prefix + "AutoRed1.json", AutoRed2 = prefix + "AutoRed2.json", AutoRed3 = prefix + "AutoRed3.json", AutoRed4 = prefix + "AutoRed4.json", Test = prefix + "Test.json" }; AutoFactory autoFactory = new AutoFactory(listing); autoFactory.RunAuto(AutoFactory.AutoModes.Red1); }
public void UpdateListingOrder(DirectoryListing listing, int courseId, string authToken) { if (!IsValidKey(authToken)) { return; } //pull the current user for easier access UserProfile currentUser = activeSessions[authToken].UserProfile; //make sure that the selected user has write privileges for the supplied course CourseUser currentCourse = (from cu in db.CourseUsers where cu.AbstractCourseID == courseId && cu.UserProfileID == currentUser.ID select cu).FirstOrDefault(); //make sure that we got something back if (currentCourse != null) { if (currentCourse.AbstractRole.CanModify || currentCourse.AbstractRole.CanUploadFiles == true) { FileSystem.UpdateFileOrdering(listing); } } }
public void GetListingSubdirectory() { var directory = DirectoryMock.Mock( new[] { new DirectoryInfo("directory") }, new[] { new FileInfo("hello.txt"), new FileInfo("world.txt") }); var listingService = new DirectoryListingService( DirectoryMock.MockFactory(directory).Object, FileHasherMock.Mock().Object); var actual = listingService.GetListing(new SystemFilepath("./subdirectory")).ToArray(); var expected = new DirectoryListing[] { new FileSyncDirectory(new ForwardSlashFilepath("./subdirectory/directory"), "api/v1/listing?path=./subdirectory/directory"), new FileSyncFile(new ForwardSlashFilepath("./subdirectory/hello.txt"), DirectoryMock.DefaultFileTimestamp) { Sha1 = FileHasherMock.EmptySha1Hash, ContentUrl = "api/v1/content?path=./subdirectory/hello.txt" }, new FileSyncFile(new ForwardSlashFilepath("./subdirectory/world.txt"), DirectoryMock.DefaultFileTimestamp) { Sha1 = FileHasherMock.EmptySha1Hash, ContentUrl = "api/v1/content?path=./subdirectory/world.txt" } }; Assert.Equal(expected, actual); }
static void Main(string[] args) { var path = @"c:\sandbox"; DirectoryListing.show(path); }
public void BuildTreeView(DirectoryListing ProjectList) { ProjectList.SetPath(ProjectFiles.LocalPath); }
public static IHandlerBuilder Create() { return(DirectoryListing.From("./")); }
public DirectoryListing GetOrCreateDirectoryListing(string[] dirs, int index) { if (index == dirs.Length) { return this; } foreach (DirectoryListing listing in SubDirectories) { if (listing.Name == dirs[index]) { return listing.GetOrCreateDirectoryListing(dirs, index + 1); } } var newListing = new DirectoryListing(); newListing.Name = dirs[index]; SubDirectories.Add(newListing); return newListing.GetOrCreateDirectoryListing(dirs, index + 1); }
/// <summary> /// Returns a list of files and directories for the given path /// </summary> /// <param name="relativepath"></param> /// <returns></returns> private static DirectoryListing BuildFileList(string path, bool includeParentLink = true) { //see if we have an ordering file for the supplied path Dictionary <string, int> ordering = new Dictionary <string, int>(); string orderingPath = Path.Combine(path, OrderingFileName); if (File.Exists(orderingPath)) { ordering = GetFileOrdering(orderingPath); } //build a new listing, set some initial values DirectoryListing listing = new DirectoryListing(); listing.AbsolutePath = path; listing.Name = path.Substring(path.LastIndexOf('\\') + 1); listing.LastModified = File.GetLastWriteTime(path); //handle files int defaultOrderingCount = 1000; foreach (string file in Directory.GetFiles(path)) { //the ordering file is used to denote ordering of files and should not be //displayed in the file list. if (Path.GetFileName(file).CompareTo(OrderingFileName) == 0) { continue; } FileListing fList = new FileListing(); fList.AbsolutePath = file; fList.Name = Path.GetFileName(file); fList.LastModified = File.GetLastWriteTime(file); fList.FileUrl = CourseDocumentPathToWebUrl(file); //set file ordering if it exists if (ordering.ContainsKey(fList.Name)) { fList.SortOrder = ordering[fList.Name]; } else { defaultOrderingCount++; while (ordering.ContainsValue(defaultOrderingCount)) { defaultOrderingCount++; } fList.SortOrder = defaultOrderingCount; } listing.Files.Add(fList); } //Add a parent directory "..." at the top of every directory listing if requested if (includeParentLink) { listing.Directories.Add(new ParentDirectoryListing()); } //handle other directories foreach (string folder in Directory.EnumerateDirectories(path)) { //recursively build the directory's subcontents. Note that we have //to pass only the folder's name and not the complete path DirectoryListing dlisting = BuildFileList(folder, includeParentLink); if (ordering.ContainsKey(dlisting.Name)) { dlisting.SortOrder = ordering[dlisting.Name]; } else { defaultOrderingCount++; while (ordering.ContainsValue(defaultOrderingCount)) { defaultOrderingCount++; } dlisting.SortOrder = defaultOrderingCount; defaultOrderingCount++; } listing.Directories.Add(dlisting); } //return the completed listing return(listing); }
/// <summary> /// c = commnad, c_Dir /// </summary> public static void c_Dir() { DirectoryListing.DispDirectories(Kernel.current_directory); DirectoryListing.DispFiles(Kernel.current_directory); Console.WriteLine(); }
/// <summary> /// c = commnad, c_Dir /// </summary> public static void c_Dir() { DirectoryListing.DispDirectories(Uszka.Kernel.cd); DirectoryListing.DispFiles(Uszka.Kernel.cd); Console.WriteLine(); }
public DirectoryListing NavigateNextFolder(int nextDirectory, DirectoryListing directoryListing) { return(GenerateListingDirectory(directoryListing.Directories[nextDirectory - 1].FullName)); }
public async Task SendMessageAsync(MiunieChannel mc, DirectoryListing dl) { var channel = _discord.Client.GetChannel(mc.ChannelId) as SocketTextChannel; var result = string.Join("\n", dl.Result.Select(s => $":file_folder: {s}")); await channel.SendMessageAsync(result); }
public FileInfo GetFileInfo(int fileId, DirectoryListing directoryListing) { var file = directoryListing.Files[fileId - 1]; return(file); }