Example #1
0
        void Cd(object sender, MenuItemSelectedEventArgs e)
        {
            string path;

            if (e.Args != null)
            {
                path = e.Args;
            }
            else
            {
                Console.WriteLine("Enter path: ");
                path = Console.ReadLine();
            }

            IResource resource = NavigateTo(current, path);

            if (resource == null)
            {
                throw new MenuItemUsageException("Directory not found.");
            }

            if (!(resource is IDirectory))
            {
                throw new MenuItemUsageException("Path specified is not a directory.");
            }

            current = resource as IDirectory;
            SetPrompt();
        }
Example #2
0
        void Rm(object sender, MenuItemSelectedEventArgs e)
        {
            string path;

            if (e.Args != null)
            {
                path = e.Args;
            }
            else
            {
                Console.Write("Enter path: ");
                path = Console.ReadLine();
            }

            IResource resource = NavigateTo(current, path);

            if (resource == null)
            {
                throw new MenuItemUsageException("Resource not found.");
            }

            if (resource.Parent == null)
            {
                throw new MenuItemUsageException("Root cannot be removed.");
            }

            if (!(resource.Parent is VirtualDirectory))
            {
                throw new MenuItemUsageException("Parent of resource must be a virtual directory.");
            }

            (resource.Parent as VirtualDirectory).Remove(resource.Name);
        }
Example #3
0
        void Add(object sender, MenuItemSelectedEventArgs e)
        {
            if (!(current is VirtualDirectory))
            {
                throw new MenuItemUsageException("Cannot add files to " + current.GetType().Name);
            }
            string path;

            if (e.Args != null)
            {
                path = e.Args;
            }
            else
            {
                Console.Write("Enter path: ");
                path = Console.ReadLine();
            }

            path = Path.GetFullPath(path);

            if (Directory.Exists(path))
            {
                (current as VirtualDirectory).AddDirectory(path);
            }
            else if (File.Exists(path))
            {
                (current as VirtualDirectory).AddFile(path);
            }
            else
            {
                throw new MenuItemUsageException("File not found.");
            }
        }
Example #4
0
        void Location(object sender, MenuItemSelectedEventArgs e)
        {
            string path;

            if (e.Args != null)
            {
                path = e.Args;
            }
            else
            {
                Console.Write("Enter path: ");
                path = Console.ReadLine();
            }

            IResource resource = NavigateTo(current, path);

            if (resource == null)
            {
                throw new MenuItemUsageException("Path not found.");
            }

            if (resource is VirtualDirectory)
            {
                Console.WriteLine("Resource is a virtual directory.");
            }
            else if (resource is IPhysicalResource)
            {
                Console.WriteLine("Location: " + (resource as IPhysicalResource).Path);
            }
            else if (resource is RedirectFile)
            {
                Console.WriteLine("URL: " + (resource as RedirectFile).Redirect);
            }
        }
Example #5
0
 void List(object sender, MenuItemSelectedEventArgs e)
 {
     foreach (IDirectory directory in current.GetDirectories())
     {
         Console.WriteLine("[" + directory.Name + "]");
     }
     foreach (IFile file in current.GetFiles())
     {
         Console.WriteLine(file.Name);
     }
 }
Example #6
0
        private void SetRootPath(object sender, MenuItemSelectedEventArgs e)
        {
            string path = e.Args;

            if (e.Args == null)
            {
                Console.Write("Enter path: ");
                path = Console.ReadLine();
            }
            rootPath = path;
            if (server.Root is DriveDirectory)
            {
                server.Root = new DriveDirectory(path);
            }
        }
Example #7
0
        private void SetHostName(object sender, MenuItemSelectedEventArgs e)
        {
            string input = e.Args;

            if (e.Args == null)
            {
                Console.Write("Enter host name: ");
                input = Console.ReadLine();
            }
            if (input.Length == 0)
            {
                return;
            }

            server.HostName = input;
        }
Example #8
0
        void Redirect(object sender, MenuItemSelectedEventArgs e)
        {
            if (!(current is VirtualDirectory))
            {
                throw new MenuItemUsageException("Cannot create directory in " + current.GetType().Name);
            }

            string name;
            string url;

            Console.Write("Enter name of redirect: ");
            if (string.IsNullOrEmpty(name = Console.ReadLine()))
            {
                throw new MenuItemUsageException("You must enter a name.");
            }
            Console.Write("Enter redirect URL: ");
            url = Console.ReadLine();

            (current as VirtualDirectory).AddFile(new RedirectFile(name, url, current));
        }
Example #9
0
        void Mkdir(object sender, MenuItemSelectedEventArgs e)
        {
            if (!(current is VirtualDirectory))
            {
                throw new MenuItemUsageException("Cannot create directory in " + current.GetType().Name);
            }

            string name;

            if (e.Args != null)
            {
                name = e.Args;
            }
            else
            {
                Console.Write("Enter directory name: ");
                name = Console.ReadLine();
            }

            (current as VirtualDirectory).AddDirectory(new VirtualDirectory(name, current));
        }
Example #10
0
        private void SelectPort(object sender, MenuItemSelectedEventArgs e)
        {
            if (server.IsRunning)
            {
                Console.Error.WriteLine("Port cannot be changed while the server is running.");
                return;
            }
            string input = e.Args;

            if (e.Args == null)
            {
                Console.Write("Enter port: ");
                input = Console.ReadLine();
            }
            if (input.Length == 0)
            {
                return;
            }

            server.Port = int.Parse(input);
        }