示例#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
        //--------------------------------------------------------------------------------
        private void LoadPath(string in_Pathname, FileSystemItemList out_ItemList, List <Guid> out_IdList)
        {
            List <string> path_list = new List <string>();

            path_list.AddRange(Pathname.PathnameItems(in_Pathname));
            this.LoadPath_Recurse(Guid.Empty, path_list, out_ItemList, out_IdList);
            return;
        }
示例#3
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;
        }
示例#5
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);
        }
示例#6
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;
        }
示例#7
0
 //--------------------------------------------------------------------------------
 private void LoadPath_Recurse(Guid in_ParentID, List <string> in_PathList, FileSystemItemList out_ItemList, List <Guid> out_IdList)
 {
     if (in_PathList.Count == 0)
     {
         return;
     }
     foreach (Guid id in this._BlockStream.GetBlockIDs())
     {
         Hashtable tags       = this._BlockStream.GetBlockTags(id);
         Guid      parent_id  = (Guid)tags["ParentID"];
         string    entry_name = (string)tags["Name"];
         if (parent_id.Equals(in_ParentID))
         {
             if (entry_name.Equals(in_PathList[0]))
             {
                 in_PathList.RemoveAt(0);
                 if (out_ItemList != null)
                 {
                     FileSystemItem entry = this.Tags2Item(tags);
                     if (out_ItemList.Count > 0)
                     {
                         entry.Path = out_ItemList[out_ItemList.Count - 1].Pathname;
                     }
                     out_ItemList.Add(entry);
                 }
                 if (out_IdList != null)
                 {
                     out_IdList.Add(id);
                 }
                 this.LoadPath_Recurse(id, in_PathList, out_ItemList, out_IdList);
                 return;
             }
         }
     }
     return;
 }