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;
 }
예제 #2
0
        /// <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]);
        }
예제 #3
0
        public void TestDirectoryListing()
        {
            using var runner = TestRunner.Run(DirectoryListing.From("./").Add(new ContentPrinterBuilder()));

            using var response = runner.GetResponse();

            Assert.Contains("Acceptance", response.GetContent());
        }
예제 #4
0
 public FileManagerDirectory(CommandContext commandContext, Server server,
                             VirtualDirectorySecurity vds, DirectoryListing listing, string currentDirectory)
 {
     CommandContext           = commandContext;
     FileSystem               = server.FileSystemService;
     Listing                  = listing;
     CurrentDirectory         = currentDirectory;
     VirtualDirectorySecurity = vds;
 }
예제 #5
0
 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.");
 }
예제 #7
0
        /// <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]));
        }
예제 #8
0
        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 + "\\");
            }
        }
예제 #9
0
 /// <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.");
     }
 }
예제 #10
0
        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));
        }
예제 #11
0
        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);
        }
예제 #12
0
            /// <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.");
            }
예제 #13
0
        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);
        }
예제 #14
0
 /// <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);
     }
 }
예제 #15
0
        /// <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();
        }
예제 #16
0
 /// <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);
 }
예제 #17
0
 /// <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);
         }
     }
 }
예제 #18
0
        /// <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));
        }
예제 #19
0
        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);
        }
예제 #20
0
        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);
        }
예제 #21
0
        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);
        }
예제 #23
0
        static void Main(string[] args)
        {
            var path = @"c:\sandbox";

            DirectoryListing.show(path);
        }
예제 #24
0
 public void BuildTreeView(DirectoryListing ProjectList)
 {
     ProjectList.SetPath(ProjectFiles.LocalPath);
 }
예제 #25
0
 public static IHandlerBuilder Create()
 {
     return(DirectoryListing.From("./"));
 }
예제 #26
0
            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);
            }
예제 #27
0
        /// <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);
        }
예제 #28
0
 /// <summary>
 /// c = commnad, c_Dir
 /// </summary>
 public static void c_Dir()
 {
     DirectoryListing.DispDirectories(Kernel.current_directory);
     DirectoryListing.DispFiles(Kernel.current_directory);
     Console.WriteLine();
 }
예제 #29
0
파일: Dir.cs 프로젝트: carcarjg/Uszka
 /// <summary>
 /// c = commnad, c_Dir
 /// </summary>
 public static void c_Dir()
 {
     DirectoryListing.DispDirectories(Uszka.Kernel.cd);
     DirectoryListing.DispFiles(Uszka.Kernel.cd);
     Console.WriteLine();
 }
예제 #30
0
 public DirectoryListing NavigateNextFolder(int nextDirectory, DirectoryListing directoryListing)
 {
     return(GenerateListingDirectory(directoryListing.Directories[nextDirectory - 1].FullName));
 }
예제 #31
0
 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);
 }
예제 #32
0
        public FileInfo GetFileInfo(int fileId, DirectoryListing directoryListing)
        {
            var file = directoryListing.Files[fileId - 1];

            return(file);
        }