示例#1
0
        //---------------------------------------------------------------------
        public override void List(Commands.ListEntriesCommand Command)
        {
            if (this._ShellAdapter.Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("List", "FileSystem root is undefined");
            }
            string syspath = this.MakeSystemPathname(this._ShellAdapter.Root, Command.in_Pathname);

            // Get file listing.
            string ShellCommand = "";

            if (this._ShellAdapter.ProtocolName.Equals("ssh", StringComparison.InvariantCultureIgnoreCase))
            {
                ShellCommand = "ls -l " + syspath + "/";
            }
            else if (this._ShellAdapter.ProtocolName.Equals("scp", StringComparison.InvariantCultureIgnoreCase))
            {
                ShellCommand = "ls " + syspath + "/";
            }
            string output = this._ShellAdapter.ExecuteCommand(ShellCommand);

            string[] lines = output.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);

            // Parse listing output.
            FileSystemItemList items = new FileSystemItemList();

            foreach (string line in lines)
            {
                FileSystemItem item = UnixShell.ParseLsOutput(Command.in_Pathname, line);
                if (item != null)
                {
                    if (item.IsLink)
                    {
                        if (Command.in_IncludeLinks)
                        {
                            items.AddSorted(item);
                        }
                    }
                    else if (item.IsFolder)
                    {
                        if (Command.in_IncludeFolders)
                        {
                            items.AddSorted(item);
                        }
                    }
                    else
                    {
                        if (Command.in_IncludeFiles)
                        {
                            items.AddSorted(item);
                        }
                    }
                }
            }

            // Return, OK.
            Command.out_ItemList = items;
            return;
        }
示例#2
0
 //---------------------------------------------------------------------
 public void Invoke(CommandContext Command)
 {
     if (Command == null)
     {
     }
     else if (Command is Commands.SettingsCommand)
     {
         Commands.SettingsCommand SettingsCommand = (Commands.SettingsCommand)Command;
         this.Settings(SettingsCommand);
     }
     else if (Command is Commands.ListEntriesCommand)
     {
         Commands.ListEntriesCommand ListCommand = (Commands.ListEntriesCommand)Command;
         this.List(ListCommand);
     }
     else if (Command is Commands.CreateItemCommand)
     {
         Commands.CreateItemCommand CreateCommand = (Commands.CreateItemCommand)Command;
         this.Create(CreateCommand);
     }
     else if (Command is Commands.ReadItemCommand)
     {
         Commands.ReadItemCommand ReadCommand = (Commands.ReadItemCommand)Command;
         this.Read(ReadCommand);
     }
     else if (Command is Commands.UpdateItemCommand)
     {
         Commands.UpdateItemCommand UpdateCommand = (Commands.UpdateItemCommand)Command;
         this.Update(UpdateCommand);
     }
     else if (Command is Commands.DeleteItemCommand)
     {
         Commands.DeleteItemCommand DeleteCommand = (Commands.DeleteItemCommand)Command;
         this.Delete(DeleteCommand);
     }
     else if (Command is Commands.ReadFileContentCommand)
     {
         Commands.ReadFileContentCommand ReadContentCommand = (Commands.ReadFileContentCommand)Command;
         this.ReadFileContent(ReadContentCommand);
     }
     else if (Command is Commands.WriteFileContentCommand)
     {
         Commands.WriteFileContentCommand WriteContentCommand = (Commands.WriteFileContentCommand)Command;
         this.WriteFileContent(WriteContentCommand);
     }
     else
     {
     }
     return;
 }
        //---------------------------------------------------------------------
        public override void List(Commands.ListEntriesCommand Command)
        {
            if (this._Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("List", "FileSystem root is undefined");
            }
            string search_path = Pathname.Append(this._Root, Command.in_Pathname);

            if (Directory.Exists(search_path))
            {
                SearchOption search_option = SearchOption.TopDirectoryOnly;
                Command.out_ItemList = new FileSystemItemList();
                if (Command.in_IncludeFolders)
                {
                    FileSystemItemList items = new FileSystemItemList();
                    foreach (string localpath in Directory.GetDirectories(search_path, "*", search_option))
                    {
                        string         itemname = localpath.Substring(search_path.Length);
                        FileSystemItem item     = new FileSystemItem(Command.in_Pathname, itemname, true, true);
                        item.DateCreated   = Directory.GetCreationTimeUtc(localpath);
                        item.DateLastRead  = Directory.GetLastAccessTimeUtc(localpath);
                        item.DateLastWrite = Directory.GetLastWriteTimeUtc(localpath);
                        items.AddSorted(item);
                    }
                    Command.out_ItemList.AddRange(items.ToArray());
                }
                if (Command.in_IncludeFiles)
                {
                    FileSystemItemList items = new FileSystemItemList();
                    foreach (string localpath in Directory.GetFiles(search_path, "*", search_option))
                    {
                        string         itemname = localpath.Substring(search_path.Length);
                        FileSystemItem item     = new FileSystemItem(Command.in_Pathname, itemname, false, true);
                        item.DateCreated   = File.GetCreationTimeUtc(localpath);
                        item.DateLastRead  = File.GetLastAccessTimeUtc(localpath);
                        item.DateLastWrite = File.GetLastWriteTimeUtc(localpath);
                        item.Size          = (new FileInfo(localpath)).Length;
                        items.AddSorted(item);
                    }
                    Command.out_ItemList.AddRange(items.ToArray());
                }
            }
            else
            {
                throw new Exceptions.InvalidOperationException("List", "Path does not exist.");
            }
            return;
        }
示例#4
0
        //--------------------------------------------------------------------------------
        public override void List(Commands.ListEntriesCommand Command)
        {
            if (this._BlockStream == null)
            {
                throw new Exceptions.InvalidOperationException("List", "FileSystem root is undefined");
            }
            string search_path = Command.in_Pathname;
            // Load the path entries and ids.
            FileSystemItemList path_entries = new FileSystemItemList();
            List <Guid>        path_ids     = new List <Guid>();

            this.LoadPath(search_path, path_entries, path_ids);
            // Get parent path and id.
            string parent_path = "";

            if (path_entries.Count > 0)
            {
                parent_path = path_entries[path_entries.Count - 1].Pathname;
            }
            Guid parent_id = Guid.Empty;

            if (path_ids.Count > 0)
            {
                parent_id = path_ids[path_ids.Count - 1];
            }
            // List child folders and files.
            FileSystemItemList entry_list = new FileSystemItemList();

            if (Command.in_IncludeFolders)
            {
                entry_list.AddRange(this.ListChildren(parent_id, parent_path, true));
            }
            if (Command.in_IncludeFiles)
            {
                entry_list.AddRange(this.ListChildren(parent_id, parent_path, false));
            }
            // Return, OK
            Command.out_ItemList = entry_list;
            return;
        }
示例#5
0
 public abstract void List(Commands.ListEntriesCommand Command);
示例#6
0
 //---------------------------------------------------------------------
 public FileSystemItemList List(string Path, bool IncludeFolders, bool IncludeLinks, bool IncludeFiles)
 {
     Commands.ListEntriesCommand ListCommand = new Commands.ListEntriesCommand(Path, IncludeFolders, IncludeLinks, IncludeFiles);
     this.List(ListCommand);
     return(ListCommand.out_ItemList);
 }