Example #1
0
        public string GetPath()
        {
            StringBuilder n = new StringBuilder();
            List <string> h = new List <string>();

            h.Add(this.name);

            Dir_Jrod temp = this.parent;

            while (temp != null)
            {
                h.Add(temp.Name);
                temp = temp.Parent;
            }
            // now the weve pieced it together reverse it
            h.Reverse();
            string removepath = Directory.GetCurrentDirectory();

            string [] remove_this = removepath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            h.Remove(remove_this[remove_this.Length - 1]);

            for (int i = 0; i < h.Count; i++)
            {
                n.Append(h[i]);

                if (i == h.Count - 1)
                {
                    break;
                }

                n.Append("/");
            }
            return(n.ToString());
        }
        public string GetPath(Dir_Jrod file)
        {
            StringBuilder n = new StringBuilder();
            List <string> h = new List <string>();

            h.Add(file.Name);

            Dir_Jrod temp = file.Parent;

            while (temp != null)
            {
                h.Add(temp.Name);
                temp = temp.Parent;
            }

            h.Reverse();
            n.Append("/");
            for (int i = 0; i < h.Count; i++)
            {
                n.Append(h[i]);

                if (i == h.Count - 1)
                {
                    break;
                }

                n.Append("/");
            }
            return(n.ToString());
        }
        private string BuildDirHTML(Dir_Jrod directory)
        {
            var html = new System.Text.StringBuilder("<html>");

            html.AppendFormat("<a>------------------------Files------------------------</a><br>");

            foreach (File_Jrod file in directory.GetFiles())
            {
                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a><br>",
                    "/files" + GetPath(file), file.Name);

                // Get HREF for File_Jrod object:
                // Last part: FIle_JrodObj.Name
                // Recurse through parent directories until hitting root
                // For each one, append directory name to FRONT of string
            }
            html.AppendFormat("<a>------------------------Directories------------------------</a><br>");
            foreach (Dir_Jrod file in directory.GetDirs())
            {
                string path = GetPath(file);
                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a><br>",
                    "/files" + GetPath(file), file.Name);

                // Get HREF for File_Jrod object:
                // Last part: FIle_JrodObj.Name
                // Recurse through parent directories until hitting root
                // For each one, append directory name to FRONT of string
            }

            html.AppendLine("</html>");
            return(html.ToString());
        }        // DO YOU have to account for directories
Example #4
0
        public MemFSFile(string fileName, Dir_Jrod par)
        {
            parent = par;
            name   = fileName;

            //if this file isnt being accounted for addd it to the concurrent dicionary
            if (!open_File_List.ContainsKey(name))
            {
                open_File_List[name] = Tuple.Create(0, 0);
            }
        }
Example #5
0
        public virtual bool Contains(Dir_Jrod dir)
        {
            if (dir == null)
            {
                return(false);
            }

            if (dir == GetRoot())
            {
                return(true);
            }


            return(Contains(dir.Parent));
        }
Example #6
0
 public MemFSDir(string names, Dir_Jrod parents)
 {
     name   = names;
     parent = parents;
 }
Example #7
0
 public StdFSFile(string fileName, Dir_Jrod par)
 {
     parent = par;
     name   = fileName;
 }
        public override void Handler(WebRequest req)
        {
            if (!req.URI.StartsWith(this.ServiceURI))
            {
                throw new InvalidOperationException();
            }

            //percent-decode URI

            string [] first_split = req.URI.Split(new [] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            string[]  pieces      = new string[first_split.Length - 1];

            Dir_Jrod dir = r_sys.GetRoot();

            // check the make sure there wasnt garbage after files
            if (first_split[0] != "files")
            {
                req.WriteNotFoundResponse(req.URI);
                return;
            }


            if (first_split.Length == 1)
            {
                req.WriteHTMLResponse(BuildDirHTML(dir));
                return;
            }

            // all this loop is doing is removing the first iteam in pieces the / file extentsion
            for (int i = 1; i < first_split.Length; i++)
            {
                pieces[i - 1] = first_split[i];
            }


            // we skip to one, forget the "files" for now
            //edit I plan on
            for (int i = 1; i < pieces.Length - 1; i++)
            {
                string piece = pieces[i];
                dir = dir.GetDir(piece);

                if (dir == null)
                {
                    req.WriteNotFoundResponse(req.URI);
                    return;
                }
            }

            //one piece left to process
            File_Jrod file = dir.GetFile(pieces[pieces.Length - 1]);

            if (file != null)
            {
                RespondWithFile(file, req);
                return;
            }
            else
            {
                dir = dir.GetDir(pieces[pieces.Length - 1]);
                if (dir != null)
                {
                    req.WriteHTMLResponse(BuildDirHTML(dir));
                    return;
                }
                else
                {
                    req.WriteNotFoundResponse(req.URI);
                    return;
                }
            }
        }