Exemplo n.º 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;
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------
        public override void Read(Commands.ReadItemCommand Command)
        {
            if (this._ShellAdapter.Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("Read", "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" }, StringSplitOptions.None);

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

            foreach (string line in lines)
            {
                FileSystemItem item = UnixShell.ParseLsOutput(Command.in_Pathname, line);
                if (item != null)
                {
                    if (string.Equals(item.Pathname, syspath, StringComparison.InvariantCultureIgnoreCase) == true)
                    {
                        item.Pathname = Command.in_Pathname;
                        items.AddSorted(item);
                    }
                }
            }
            if (items.Count == 1)
            {
                Command.out_Item = items[0];
            }
            else
            {
                Command.out_Item          = new FileSystemItem();
                Command.out_Item.Pathname = Command.in_Pathname;
                Command.out_Item.IsFolder = true;
                Command.out_Item.Exists   = true;
            }

            // Return, OK.
            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;
        }
Exemplo n.º 4
0
        ////--------------------------------------------------------------------------------
        //private FileSystemItem GetItemFromID( Guid ID )
        //{
        //    if( ID.Equals( Guid.Empty ) ) { return null; }
        //    Hashtable tags = this._BlockStream.GetBlockTags( ID );
        //    FileSystemItem entry = this.Tags2Item( tags );
        //    Guid parent_id = (Guid)tags[ "ParentID" ];
        //    if( parent_id.Equals( Guid.Empty ) == false )
        //    {
        //        FileSystemItem parent_entry = this.GetItemFromID( parent_id );
        //        entry.Path = parent_entry.Pathname;
        //    }
        //    return entry;
        //}

        ////--------------------------------------------------------------------------------
        //private FileSystemItem FindName( Guid ParentID, string Name )
        //{
        //    FileSystemItem entry = null;
        //    foreach( Guid id in this._BlockStream.BlockIDs )
        //    {
        //        Hashtable tags = this._BlockStream.GetBlockTags( id );

        //    }
        //    return entry;
        //}

        ////--------------------------------------------------------------------------------
        //private FileSystemItem ItemFromPathname( string Pathname )
        //{
        //    FileSystemItem entry = new FileSystemItem();
        //    entry.Pathname = Pathname;


        //    return entry;
        //}

        //--------------------------------------------------------------------------------
        private FileSystemItemList ListChildren(Guid ParentID, string ParentPath, bool ListFolders)
        {
            FileSystemItemList entry_list = new FileSystemItemList();

            foreach (Guid id in this._BlockStream.GetBlockIDs())
            {
                Hashtable tags = this._BlockStream.GetBlockTags(id);
                if (ParentID.Equals((Guid)tags["ParentID"]))
                {
                    FileSystemItem entry = this.Tags2Item(tags);
                    if ((ListFolders && entry.IsFolder) || (!ListFolders && !entry.IsFolder))
                    {
                        entry.Path = ParentPath;
                        entry_list.AddSorted(entry);
                    }
                }
            }
            return(entry_list);
        }