public FileExplorerHtmlTemplate(FileExplorerViewModel viewModel) { FileExplorerViewModel = viewModel; }
public HttpResponseMessage GetListingPage(string path) { path = path ?? string.Empty; var listingPhysicalPath = GetListingPhysicalPath(path); var baseUri = GetBaseUri(path); var currenUri = string.IsNullOrWhiteSpace(path) ? baseUri : baseUri + path; if (_fileSystemHelper.Exists(listingPhysicalPath) == false) { return ConvertListingToReponse(new FileExplorerViewModel()); } var fullPath = listingPhysicalPath; if (string.IsNullOrWhiteSpace(path) == false) { fullPath = Path.Combine(listingPhysicalPath, path); } if (_fileSystemHelper.Exists(fullPath) == false) { return ConvertListingToReponse(new FileExplorerViewModel()); } var fileExplorerViewModel = new FileExplorerViewModel(); var directories = _fileSystemHelper.GetNonHiddenDirectories(fullPath); fileExplorerViewModel.Entries.AddRange( directories.Select(directory => new FileSystemEntry { Name = _fileSystemHelper.GetShortName(directory) + "/", LastModified = _fileSystemHelper.GetLastModifiedDate(directory), Size = 0, Link = currenUri + _fileSystemHelper.GetShortName(directory) + "/" }).ToList()); var files = _fileSystemHelper.GetNonHiddenFiles(fullPath); fileExplorerViewModel.Entries.AddRange(files.Select(file => new FileSystemEntry { Name = _fileSystemHelper.GetShortName(file), LastModified = _fileSystemHelper.GetLastModifiedDate(file), Link = currenUri + _fileSystemHelper.GetShortName(file), Size = _fileSystemHelper.GetSize(file) }).ToList()); string baseHeaderName = baseUri.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last() + "/"; fileExplorerViewModel.CurrentEntryPath.Add(new FileSystemEntry { Name = baseHeaderName, Link = baseUri }); var currentLink = baseUri; foreach (var header in path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)) { currentLink += header + "/"; fileExplorerViewModel.CurrentEntryPath.Add(new FileSystemEntry { Name = header + "/", Link = currentLink }); } return ConvertListingToReponse(fileExplorerViewModel); }
private HttpResponseMessage ConvertListingToReponse(FileExplorerViewModel fileExplorerViewModel) { var response = new HttpResponseMessage { Content = new StringContent(new FileExplorerHtmlTemplate(fileExplorerViewModel).TransformText()) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return response; }