Ejemplo n.º 1
0
        public CommandResponse GetResponse(ICommandContext commandContext)
        {
            var fileSystem = commandContext.CreateFileSystem();

            var hash = commandContext.Parameters["current"];

            DirectoryContentHash cwd;

            if (!DirectoryContentHash.TryParse(hash, out cwd))
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_Error")
                });
            }

            bool canWrite;

            try
            {
                canWrite = fileSystem.Using(cwd, fs => fs.Current.CanWrite);
            }
            catch (InvalidOperationException)
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_Error")
                });
            }

            if (!canWrite)
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Delete_Permission_Denied_For_Current_Directory_Error")
                });
            }

            var errors = RemoveFiles(commandContext);

            try
            {
                return(fileSystem.Using(cwd, fs => GetResponse(commandContext, fs, errors)));
            }
            catch (InvalidOperationException)
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_Error")
                });
            }
        }
Ejemplo n.º 2
0
        public CommandResponse GetResponse(ICommandContext commandContext)
        {
            var fileSystem = commandContext.CreateFileSystem();

            // If no target directory is specified (as on first init), use a working directory, if
            // specified.
            var hash = string.IsNullOrEmpty(commandContext.Parameters["target"])
                                ? commandContext.Parameters["working"]
                                : commandContext.Parameters["target"];

            var response = new OpenCommandResponse
            {
                tmb        = false,
                disabled   = commandContext.DisabledCommands.ToArray(),
                parameters = new InitializationParameters
                {
                    dotFiles = false,
                    archives = new string[] {},
                    extract  = new string[] {},
                }
            };

            DirectoryContentHash cwd;

            if (DirectoryContentHash.TryParse(hash, out cwd))
            {
                try
                {
                    return(fileSystem.Using(cwd, fs => GetResponse(commandContext, fs, response)));
                }
                catch (InvalidOperationException e)
                {
                    response.error = e.Message;
                }
            }

            try
            {
                return(fileSystem.Using(fs => GetResponse(commandContext, fs, response)));
            }
            catch (InvalidOperationException e)
            {
                response.error = e.Message;

                return(response);
            }
        }
Ejemplo n.º 3
0
        public CommandResponse GetResponse(ICommandContext commandContext)
        {
            var fileSystem = commandContext.CreateFileSystem();

            var hash = commandContext.Parameters["current"];

            DirectoryContentHash cwd;

            if (!DirectoryContentHash.TryParse(hash, out cwd))
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error")
                });
            }

            DirectoryUploadInfo cwdInfo;

            try
            {
                cwdInfo = fileSystem.Using(cwd, fs => new DirectoryUploadInfo(fs.Current));
            }
            catch (InvalidOperationException)
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error")
                });
            }

            if (!(cwdInfo.SupportsUpload && cwdInfo.CanWrite))
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Upload_Permission_Denied_For_Current_Directory_Error")
                });
            }

            var files = GetUploadedFiles(commandContext.Files);

            if (!files.Any())
            {
                return(new ErrorCommandResponse
                {
                    error = "No valid files were uploaded"
                });
            }

            var portal          = commandContext.CreatePortalContext();
            var publishingState = GetPublishingState(portal, cwdInfo.Entity);

            if (publishingState == null)
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error")
                });
            }

            List <string> @select;
            List <Tuple <string, string> > errors;

            CreateFiles(commandContext, cwdInfo, files, publishingState, out @select, out errors);

            try
            {
                return(fileSystem.Using(cwd, fs => GetResponse(commandContext, fs, @select, errors)));
            }
            catch (InvalidOperationException)
            {
                return(new ErrorCommandResponse
                {
                    error = ResourceManager.GetString("Unable_To_Retrieve_Current_Directory_For_Upload_Error")
                });
            }
        }