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

            string ShellCommand = "";

            if (Command.in_Item.Pathname.Equals(Command.in_Pathname))
            {
                ShellCommand = "touch " + syspath;
            }
            else
            {
                Pathname new_syspath = this.MakeSystemPathname(this._ShellAdapter.Root, Command.in_Item.Pathname);
                new_syspath.Separator = "/";
                ShellCommand          = "mv " + syspath + " " + new_syspath;
                ;
            }
            string output = this._ShellAdapter.ExecuteCommand(ShellCommand);

            Commands.ReadItemCommand ReadCmd = new Commands.ReadItemCommand();
            ReadCmd.in_Pathname = Command.in_Item.Pathname;
            this.Read(ReadCmd);
            if (ReadCmd.out_Item == null)
            {
                throw new Exceptions.InvalidOperationException("Update", "Item does not exist.");
            }

            // Return, OK.
            Command.out_Item = ReadCmd.out_Item;
            return;
        }
コード例 #2
0
        //---------------------------------------------------------------------
        public override void Create(Commands.CreateItemCommand Command)
        {
            if (this._ShellAdapter.Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("Create", "FileSystem root is undefined");
            }
            string syspath = this.MakeSystemPathname(this._ShellAdapter.Root, Command.in_Pathname);

            string ShellCommand = "";

            if (Command.in_IsFolder)
            {
                ShellCommand = "mkdir " + syspath + "/";
            }
            else
            {
                ShellCommand = "touch " + syspath;
            }
            string output = this._ShellAdapter.ExecuteCommand(ShellCommand);

            // Get item.
            Commands.ReadItemCommand ReadCmd = new Commands.ReadItemCommand();
            ReadCmd.in_Pathname = Command.in_Pathname;
            this.Read(ReadCmd);
            if (ReadCmd.out_Item == null)
            {
                throw new Exceptions.InvalidOperationException("Create", "Item does not exist.");
            }
            if (Command.in_CreatePath)
            {
            }
            Command.out_Item = ReadCmd.out_Item;
            return;
        }
コード例 #3
0
        //---------------------------------------------------------------------
        public override void ReadFileContent(Commands.ReadFileContentCommand Command)
        {
            if (this._ShellAdapter.Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("ReadContent", "FileSystem root is undefined");
            }
            string syspath = this.MakeSystemPathname(this._ShellAdapter.Root, Command.in_Pathname);

            // Check file.
            Commands.ReadItemCommand ReadCmd = new Commands.ReadItemCommand();
            ReadCmd.in_Pathname = syspath;
            this.Read(ReadCmd);
            if (ReadCmd.out_Item == null)
            {
                throw new Exceptions.InvalidOperationException("ReadContent", "Item does not exist.");
            }
            if (ReadCmd.out_Item.IsFolder)
            {
                throw new Exceptions.InvalidOperationException("ReadContent", "Cannot read content from a folder.");
            }
            if ((Command.in_Offset < 0) || (Command.in_Offset >= ReadCmd.out_Item.Size))
            {
                throw new Exceptions.InvalidOperationException("ReadContent", "Offset is outside of expected range.");
            }

            // Get file.
            string TempFilename = Path.GetTempFileName();
            string ShellCommand = "get -preservetime " + syspath + " " + TempFilename;
            string output       = this._ShellAdapter.ExecuteCommand(ShellCommand);

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

            // Read file bytes.
            using (FileStream stream = File.OpenRead(TempFilename))
            {
                long nLength = Command.in_Length;
                if (nLength < 0)
                {
                    nLength = (stream.Length - Command.in_Offset);
                }
                if ((Command.in_Offset + nLength) > stream.Length)
                {
                    nLength = (stream.Length - Command.in_Offset);
                }
                byte[] bytes = new byte[nLength];
                stream.Position = Command.in_Offset;
                int cb = stream.Read(bytes, 0, bytes.Length);
                if (cb != nLength)
                {
                    throw new Exceptions.InvalidOperationException("ReadContent", "Read error.");
                }
                Command.out_Content = bytes;
            }

            // Return, OK.
            return;
        }
コード例 #4
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;
        }
コード例 #5
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;
 }
コード例 #6
0
        //---------------------------------------------------------------------
        public override void Read(Commands.ReadItemCommand Command)
        {
            if (this._Root.Length == 0)
            {
                throw new Exceptions.InvalidOperationException("Read", "FileSystem root is undefined");
            }
            Pathname       ItemPathname = Pathname.Append(this._Root, Command.in_Pathname);
            FileSystemItem item         = this.ItemFromPathname(ItemPathname);

            if (item.Exists)
            {
                Command.out_Item = item;
            }
            return;
        }
コード例 #7
0
 //---------------------------------------------------------------------
 public FileSystemItem Read(string Pathname)
 {
     Commands.ReadItemCommand ReadCommand = new Commands.ReadItemCommand(Pathname);
     this.Read(ReadCommand);
     return(ReadCommand.out_Item);
 }
コード例 #8
0
 public abstract void Read(Commands.ReadItemCommand Command);
コード例 #9
0
 //--------------------------------------------------------------------------------
 public override void Read(Commands.ReadItemCommand Command)
 {
     throw new NotImplementedException();
 }