コード例 #1
0
        public RequestResult <List <DirectoryItem> > GetDirContent(PathContentRequestModel request)
        {
            string path = request.FullPath;

            path = path.TrimEnd(((char)92));
            //currentPath used to form fullPath property in FileDirToDirectoryItem convertor
            currentPath  = path.Replace("root", "");
            currentPath += (string.IsNullOrWhiteSpace(currentPath) ? "" : @"\");

            if (path.EndsWith(":"))
            {
                path += @"\";
            }

            if (!_worker.PathExists(path))
            {
                return(new RequestResult <List <DirectoryItem> >(RequestResultStatus.Error, null, "Such directory does not exist"));
            }

            List <DirectoryItem> items         = new List <DirectoryItem>();
            DirectoryItem        parentDirItem = new DirectoryItem();

            parentDirItem.FullPath = _worker.GetParentDirectory(path);
            parentDirItem.Name     = "...";
            parentDirItem.isDir    = true;
            //if ( !string.IsNullOrWhiteSpace(parentDirItem.FullPath))
            //{
            //    items.Add(parentDirItem);
            //}
            if (!string.IsNullOrWhiteSpace(path))
            {
                items.Add(parentDirItem);
            }

            try
            {
                items.AddRange(_worker.GetDirectorySubDirs(path).ConvertAll(new Converter <FileDir, DirectoryItem>(FileDirToDirectoryItem)));
                items.AddRange(_worker.GetDirectoryFiles(path).ConvertAll(new Converter <FileDir, DirectoryItem>(FileDirToDirectoryItem)));
            } catch (UnauthorizedAccessException)
            {
                return(new RequestResult <List <DirectoryItem> >(RequestResultStatus.Error, items, "You have no access to this directory"));
            }

            return(new RequestResult <List <DirectoryItem> >(RequestResultStatus.Success, items, "worker instance " + _worker.instanceIdx.ToString()));
        }
コード例 #2
0
        public HttpResponseMessage Get(PathContentRequestModel model)
        {
            if (model == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Model is not valid"));
            }

            if (string.IsNullOrWhiteSpace(model.FullPath))
            {
                model.FullPath = "root";
            }

            var result = _directoryBrowserService.GetDirContent(model);

            if (result.Status == RequestResultStatus.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, result));
            }
        }