public void ProcessRequest(HttpContext context) { var resolver = DependencyResolver.Resolver; using (resolver.BeginResolverScope()) { var parameters = getParameters(context.Request); string cmd = parameters["cmd"]; if (string.IsNullOrWhiteSpace(cmd)) { sendError(context, "Command not set"); return; } var foundCmd = resolver.Resolve <IEnumerable <Command.ICommand> >().FirstOrDefault(x => x.Name.Equals(cmd, StringComparison.OrdinalIgnoreCase)); if (foundCmd == null) { sendError(context, "errUnknownCmd"); return; } var args = new Command.CommandArgs(parameters, context.Request.Files); var cmdResponse = foundCmd.Execute(args); cmdResponse.Process(context.Response); } }
public Response.IResponse Execute(CommandArgs args) { var oa = args.As <openArgs>(); if (string.IsNullOrWhiteSpace(oa.target) && oa.init.IsFalse()) { return(new Response.ErrorResponse("target not specified")); } // get volume for our target var vol = _volumeManager.GetByHash(oa.target); // try to get directory for our target var cwd = (vol != null ? vol.GetDirectoryByHash(oa.target) : null); if ((cwd == null || cwd.IsReadable.IsFalse()) && oa.init.IsTrue()) { // get default volume vol = _volumeManager.DefaultVolume; if (vol != null) { cwd = vol.GetRootDirectory(); } } // if we still haven't got volume service, then something is wrong if (cwd == null || cwd.IsReadable.IsFalse()) { return(new Response.ErrorResponse("target dir not found or access denied")); } var subItems = new List <Model.ObjectModel>(); // get sub directories if (oa.tree.IsTrue()) { subItems.AddRange(vol.GetSubdirectoriesFlat(cwd)); } else { subItems.AddRange(vol.GetSubdirectoriesFlat(cwd, 0)); } // get files in our CWD subItems.AddRange(vol.GetFiles(cwd)); if (oa.init.IsTrue()) { return(new Response.InitDirectoryResponse(_config.ApiVersion, new string[0], //TODO _config.UploadMaxSize, cwd, subItems.ToArray(), new Model.OptionsModel(vol.GetPathToRoot(cwd), _config.BaseUrl, _config.BaseThumbsUrl))); } else { return(new Response.DirectoryResponse(cwd, subItems.ToArray(), new Model.OptionsModel(vol.GetPathToRoot(cwd), _config.BaseUrl, _config.BaseThumbsUrl))); } }