public AddResponseModel(DirectoryInfo newDir, Root root) { added = new List <BaseModel>() { BaseModel.Create(newDir, root) }; }
public AddResponseModel(FileInfo newFile, Root root) { added = new List <BaseModel>() { BaseModel.Create(newFile, root) }; }
public async Task <JsonResult> RenameAsync(FullPath path, string name) { var response = new ReplaceResponseModel(); response.Removed.Add(path.HashedTarget); RemoveThumbs(path); if (path.IsDirectory) { // Get new path var newPath = AzureStorageAPI.UrlCombine(path.Directory.Parent.FullName ?? string.Empty, name); // Move file await AzureStorageAPI.MoveDirectory(path.Directory.FullName, newPath); // Add it to added entries list response.Added.Add(await BaseModel.Create(this, new AzureStorageDirectory(newPath), path.RootVolume)); } else { // Get new path var newPath = AzureStorageAPI.UrlCombine(path.File.DirectoryName ?? string.Empty, name); // Move file await AzureStorageAPI.MoveFile(path.File.FullName, newPath); // Add it to added entries list response.Added.Add(await BaseModel.Create(this, new AzureStorageFile(newPath), path.RootVolume)); } return(await Json(response)); }
public async Task <JsonResult> Duplicate(IEnumerable <string> targets) { AddResponseModel response = new AddResponseModel(); foreach (var target in targets) { FullPath fullPath = ParsePath(target); if (fullPath.Directory != null) { var parentPath = fullPath.Directory.Parent.FullName; var name = fullPath.Directory.Name; var newName = string.Format(@"{0}\{1} copy", parentPath, name); if (!Directory.Exists(newName)) { DirectoryCopy(fullPath.Directory, newName, true); } else { for (int i = 1; i < 100; i++) { newName = string.Format(@"{0}\{1} copy {2}", parentPath, name, i); if (!Directory.Exists(newName)) { DirectoryCopy(fullPath.Directory, newName, true); break; } } } response.Added.Add(BaseModel.Create(new DirectoryInfo(newName), fullPath.Root)); } else { var parentPath = fullPath.File.Directory.FullName; var name = fullPath.File.Name.Substring(0, fullPath.File.Name.Length - fullPath.File.Extension.Length); var ext = fullPath.File.Extension; var newName = string.Format(@"{0}\{1} copy{2}", parentPath, name, ext); if (!System.IO.File.Exists(newName)) { fullPath.File.CopyTo(newName); } else { for (int i = 1; i < 100; i++) { newName = string.Format(@"{0}\{1} copy {2}{3}", parentPath, name, i, ext); if (!System.IO.File.Exists(newName)) { fullPath.File.CopyTo(newName); break; } } } response.Added.Add(BaseModel.Create(new FileInfo(newName), fullPath.Root)); } } return(await Json(response)); }
public async Task <JsonResult> DuplicateAsync(IEnumerable <FullPath> paths) { var response = new AddResponseModel(); foreach (var path in paths) { if (path.IsDirectory) { var parentPath = path.Directory.Parent.FullName; var name = path.Directory.Name; string newName = $"{parentPath}{Path.DirectorySeparatorChar}{name} copy"; if (!Directory.Exists(newName)) { DirectoryCopy(path.Directory.FullName, newName, true); } else { for (int i = 1; i < 100; i++) { newName = $"{parentPath}{Path.DirectorySeparatorChar}{name} copy {i}"; if (!Directory.Exists(newName)) { DirectoryCopy(path.Directory.FullName, newName, true); break; } } } response.Added.Add(await BaseModel.Create(this, new FileSystemDirectory(newName), path.RootVolume)); } else { var parentPath = path.File.Directory.FullName; var name = path.File.Name.Substring(0, path.File.Name.Length - path.File.Extension.Length); var ext = path.File.Extension; string newName = $"{parentPath}{Path.DirectorySeparatorChar}{name} copy{ext}"; if (!File.Exists(newName)) { File.Copy(path.File.FullName, newName); } else { for (int i = 1; i < 100; i++) { newName = $"{parentPath}{Path.DirectorySeparatorChar}{name} copy {i}{ext}"; if (!File.Exists(newName)) { File.Copy(path.File.FullName, newName); break; } } } response.Added.Add(await BaseModel.Create(this, new FileSystemFile(newName), path.RootVolume)); } } return(await Json(response)); }
public async Task <JsonResult> PasteAsync(FullPath dest, IEnumerable <FullPath> paths, bool isCut) { var response = new ReplaceResponseModel(); foreach (var src in paths) { if (src.IsDirectory) { var newDir = new AzureStorageDirectory(AzureStorageAPI.UrlCombine(dest.Directory.FullName, src.Directory.Name)); // Check if it already exists if (await newDir.ExistsAsync) { // Exists await newDir.DeleteAsync(); } if (isCut) { RemoveThumbs(src); await AzureStorageAPI.MoveDirectory(src.Directory.FullName, newDir.FullName); response.Removed.Add(src.HashedTarget); } else { // Copy directory await AzureStorageAPI.CopyDirectory(src.Directory.FullName, newDir.FullName); } response.Added.Add(await BaseModel.Create(this, newDir, dest.RootVolume)); } else { string newFilePath = AzureStorageAPI.UrlCombine(dest.Directory.FullName, src.File.Name); await AzureStorageAPI.DeleteFileIfExists(newFilePath); if (isCut) { RemoveThumbs(src); // Move file await AzureStorageAPI.MoveFile(src.File.FullName, newFilePath); response.Removed.Add(src.HashedTarget); } else { // Copy file await AzureStorageAPI.CopyFile(src.File.FullName, newFilePath); } response.Added.Add(await BaseModel.Create(this, new AzureStorageFile(newFilePath), dest.RootVolume)); } } return(await Json(response)); }
public async Task <JsonResult> PutAsync(FullPath path, string content) { var response = new ChangedResponseModel(); // Write content await AzureStorageAPI.Put(path.File.FullName, content); response.Changed.Add((FileModel)await BaseModel.Create(this, path.File, path.RootVolume)); return(await Json(response)); }
public async Task <JsonResult> MakeDirAsync(FullPath path, string name) { var newDir = new FileSystemDirectory(Path.Combine(path.Directory.FullName, name)); await newDir.CreateAsync(); var response = new AddResponseModel(); response.Added.Add(await BaseModel.Create(this, newDir, path.RootVolume)); return(await Json(response)); }
public async Task <JsonResult> MakeFileAsync(FullPath path, string name) { var newFile = new AzureStorageFile(AzureStorageAPI.UrlCombine(path.Directory.FullName, name)); await newFile.CreateAsync(); var response = new AddResponseModel(); response.Added.Add(await BaseModel.Create(this, newFile, path.RootVolume)); return(await Json(response)); }
public async Task <JsonResult> InitAsync(FullPath path) { if (path == null) { var root = Roots.FirstOrDefault(r => r.StartDirectory != null); if (root == null) { root = Roots.First(); } path = new FullPath(root, new FileSystemDirectory(root.StartDirectory ?? root.RootDirectory), null); } var response = new InitResponseModel(await BaseModel.Create(this, path.Directory, path.RootVolume), new Options(path)); foreach (var item in await path.Directory.GetFilesAsync()) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, item, path.RootVolume)); } } foreach (var item in await path.Directory.GetDirectoriesAsync()) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, item, path.RootVolume)); } } foreach (var item in Roots) { response.Files.Add(await BaseModel.Create(this, new FileSystemDirectory(item.RootDirectory), item)); } if (path.RootVolume.RootDirectory != path.Directory.FullName) { var dirInfo = new DirectoryInfo(path.RootVolume.RootDirectory); foreach (var item in dirInfo.GetDirectories()) { var attributes = item.Attributes; if (!attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, new FileSystemDirectory(item), path.RootVolume)); } } } if (path.RootVolume.MaxUploadSize.HasValue) { response.UploadMaxSize = path.RootVolume.MaxUploadSizeInKb.Value + "K"; } return(await Json(response)); }
public async Task <JsonResult> Rotate(string target, int degree) { FullPath path = ParsePath(target); RemoveThumbs(path); path.Root.PicturesEditor.Rotate(path.File.FullName, degree); var output = new ChangedResponseModel(); output.Changed.Add((FileModel)BaseModel.Create(path.File, path.Root)); return(await Json(output)); }
public async Task <JsonResult> Crop(string target, int x, int y, int width, int height) { FullPath path = ParsePath(target); RemoveThumbs(path); path.Root.PicturesEditor.Crop(path.File.FullName, x, y, width, height); var output = new ChangedResponseModel(); output.Changed.Add((FileModel)BaseModel.Create(path.File, path.Root)); return(await Json(output)); }
public async Task <JsonResult> PutAsync(FullPath path, string content) { var response = new ChangedResponseModel(); using (var fileStream = new FileStream(path.File.FullName, FileMode.Create)) using (var writer = new StreamWriter(fileStream)) { writer.Write(content); } response.Changed.Add((FileModel)await BaseModel.Create(this, path.File, path.RootVolume)); return(await Json(response)); }
public async Task <JsonResult> Init(string target) { FullPath fullPath; if (string.IsNullOrEmpty(target)) { Root root = _roots.FirstOrDefault(r => r.StartPath != null); if (root == null) { root = _roots.First(); } fullPath = new FullPath(root, root.StartPath ?? root.Directory); } else { fullPath = ParsePath(target); } InitResponseModel answer = new InitResponseModel(BaseModel.Create(fullPath.Directory, fullPath.Root), new Options(fullPath)); foreach (FileInfo item in fullPath.Directory.GetFiles()) { if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { answer.Files.Add(BaseModel.Create(item, fullPath.Root)); } } foreach (DirectoryInfo item in fullPath.Directory.GetDirectories()) { if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { answer.Files.Add(BaseModel.Create(item, fullPath.Root)); } } foreach (Root item in _roots) { answer.Files.Add(BaseModel.Create(item.Directory, item)); } if (fullPath.Root.Directory.FullName != fullPath.Directory.FullName) { foreach (DirectoryInfo item in fullPath.Root.Directory.GetDirectories()) { if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { answer.Files.Add(BaseModel.Create(item, fullPath.Root)); } } } if (fullPath.Root.MaxUploadSize.HasValue) { answer.UploadMaxSize = fullPath.Root.MaxUploadSizeInKb.Value + "K"; } return(await Json(answer)); }
public async Task <JsonResult> PasteAsync(FullPath dest, IEnumerable <FullPath> paths, bool isCut) { var response = new ReplaceResponseModel(); foreach (var src in paths) { if (src.IsDirectory) { var newDir = new FileSystemDirectory(Path.Combine(dest.Directory.FullName, src.Directory.Name)); if (await newDir.ExistsAsync) { Directory.Delete(newDir.FullName, true); } if (isCut) { await RemoveThumbs(src); Directory.Move(src.Directory.FullName, newDir.FullName); response.Removed.Add(src.HashedTarget); } else { DirectoryCopy(src.Directory.FullName, newDir.FullName, true); } response.Added.Add(await BaseModel.Create(this, newDir, dest.RootVolume)); } else { var newFile = new FileSystemFile(Path.Combine(dest.Directory.FullName, src.File.Name)); if (await newFile.ExistsAsync) { await newFile.DeleteAsync(); } if (isCut) { await RemoveThumbs(src); File.Move(src.File.FullName, newFile.FullName); response.Removed.Add(src.HashedTarget); } else { File.Copy(src.File.FullName, newFile.FullName); } response.Added.Add(await BaseModel.Create(this, newFile, dest.RootVolume)); } } return(await Json(response)); }
public async Task <ObjectResult> Comparison([FromQuery] int consumption) { try { var data = await _productService.Comparison(consumption); return(new OkObjectResult(BaseModel.Create(success: true, data, total: data.Count, message: "success"))); } catch (Exception ex) { return(new NotFoundObjectResult(BaseModel.Create(success: false, data: null, total: 0, message: ex.Message))); } }
public override async Task <ObjectResult> Get() { try { var products = await _productService.GetAllProducts(); return(new OkObjectResult(BaseModel.Create(success: true, data: products, total: products.Count, message: "success"))); } catch (Exception ex) { return(new NotFoundObjectResult(BaseModel.Create(success: false, data: null, total: 0, message: ex.Message))); } }
public async Task <JsonResult> TreeAsync(FullPath path) { var response = new TreeResponseModel(); foreach (var item in await path.Directory.GetDirectoriesAsync()) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { response.Tree.Add(await BaseModel.Create(this, item, path.RootVolume)); } } return(await Json(response)); }
public virtual async Task <ObjectResult> Get() { try { var all = await genericService.Get().ConfigureAwait(false); return(new OkObjectResult(BaseModel.Create(success: true, data: all, total: all.Count, message: "success"))); } catch (Exception ex) { return(new NotFoundObjectResult(BaseModel.Create(success: false, data: null, total: 0, message: ex.Message))); } }
public async Task <JsonResult> Put(string target, string content) { FullPath fullPath = ParsePath(target); ChangedResponseModel answer = new ChangedResponseModel(); using (var fileStream = new FileStream(fullPath.File.FullName, FileMode.Create)) using (var writer = new StreamWriter(fileStream)) { writer.Write(content); } answer.Changed.Add((FileModel)BaseModel.Create(fullPath.File, fullPath.Root)); return(await Json(answer)); }
public async Task <JsonResult> Tree(string target) { FullPath fullPath = ParsePath(target); TreeResponseModel answer = new TreeResponseModel(); foreach (var item in fullPath.Directory.GetDirectories()) { if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { answer.Tree.Add(BaseModel.Create(item, fullPath.Root)); } } return(await Json(answer)); }
public async Task <JsonResult> Paste(string source, string dest, IEnumerable <string> targets, bool isCut) { FullPath destPath = ParsePath(dest); ReplaceResponseModel response = new ReplaceResponseModel(); foreach (var item in targets) { FullPath src = ParsePath(item); if (src.Directory != null) { DirectoryInfo newDir = new DirectoryInfo(Path.Combine(destPath.Directory.FullName, src.Directory.Name)); if (newDir.Exists) { Directory.Delete(newDir.FullName, true); } if (isCut) { RemoveThumbs(src); src.Directory.MoveTo(newDir.FullName); response.Removed.Add(item); } else { DirectoryCopy(src.Directory, newDir.FullName, true); } response.Added.Add(BaseModel.Create(newDir, destPath.Root)); } else { string newFilePath = Path.Combine(destPath.Directory.FullName, src.File.Name); if (System.IO.File.Exists(newFilePath)) { System.IO.File.Delete(newFilePath); } if (isCut) { RemoveThumbs(src); src.File.MoveTo(newFilePath); response.Removed.Add(item); } else { System.IO.File.Copy(src.File.FullName, newFilePath); } response.Added.Add(BaseModel.Create(new FileInfo(newFilePath), destPath.Root)); } } return(await Json(response)); }
public async Task <JsonResult> OpenAsync(FullPath path, bool tree) { var response = new OpenResponse(await BaseModel.Create(this, path.Directory, path.RootVolume), path); // Get all files and directories var items = await AzureStorageAPI.ListFilesAndDirectories(path.Directory.FullName); // Add visible files foreach (var file in items.Where(i => i is CloudFile)) { var f = new AzureStorageFile(file as CloudFile); if (!f.Attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, f, path.RootVolume)); } } // Add visible directories foreach (var dir in items.Where(i => i is CloudFileDirectory)) { var d = new AzureStorageDirectory(dir as CloudFileDirectory); if (!d.Attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, d, path.RootVolume)); } } // Add parents if (tree) { var parent = path.Directory; while (parent != null && parent.FullName != path.RootVolume.RootDirectory) { // Update parent parent = parent.Parent; // Ensure it's a child of the root if (parent != null && path.RootVolume.RootDirectory.Contains(parent.FullName)) { response.Files.Insert(0, await BaseModel.Create(this, parent, path.RootVolume)); } } } return(await Json(response)); }
public async Task <JsonResult> ParentsAsync(FullPath path) { var response = new TreeResponseModel(); if (path.Directory.FullName == path.RootVolume.RootDirectory) { response.Tree.Add(await BaseModel.Create(this, path.Directory, path.RootVolume)); } else { // Not root level // Go back to root var parent = path.Directory; while (parent != null && parent.Name != path.RootVolume.RootDirectory) { // Update parent parent = parent.Parent; // Ensure it's a child of the root if (parent != null && path.RootVolume.RootDirectory.Contains(parent.Name)) { response.Tree.Insert(0, await BaseModel.Create(this, parent, path.RootVolume)); } } // Check that directory has a parent if (path.Directory.Parent != null) { var items = await AzureStorageAPI.ListFilesAndDirectories(path.Directory.Parent.FullName); // Add all visible directories except the target foreach (var dir in items.Where(i => i is CloudFileDirectory && ((CloudFileDirectory)i).Name != path.Directory.Name)) { var d = new AzureStorageDirectory(dir as CloudFileDirectory); if (!d.Attributes.HasFlag(FileAttributes.Hidden)) { response.Tree.Add(await BaseModel.Create(this, d, path.RootVolume)); } } } } return(await Json(response)); }
public async Task <JsonResult> TreeAsync(FullPath path) { var response = new TreeResponseModel(); var items = await AzureStorageAPI.ListFilesAndDirectories(path.Directory.FullName); // Add visible directories foreach (var dir in items.Where(i => i is CloudFileDirectory)) { var d = new AzureStorageDirectory(dir as CloudFileDirectory); if (!d.Attributes.HasFlag(FileAttributes.Hidden)) { response.Tree.Add(await BaseModel.Create(this, d, path.RootVolume)); } } return(await Json(response)); }
public async Task <JsonResult> RotateAsync(FullPath path, int degree) { RemoveThumbs(path); // Crop Image ImageWithMimeType image; using (var stream = await path.File.OpenReadAsync()) { image = path.RootVolume.PictureEditor.Rotate(stream, degree); } await AzureStorageAPI.Put(path.File.FullName, image.ImageStream); var output = new ChangedResponseModel(); output.Changed.Add((FileModel)await BaseModel.Create(this, path.File, path.RootVolume)); return(await Json(output)); }
public async Task <JsonResult> Rename(string target, string name) { FullPath fullPath = ParsePath(target); var answer = new ReplaceResponseModel(); answer.Removed.Add(target); RemoveThumbs(fullPath); if (fullPath.Directory != null) { string newPath = Path.Combine(fullPath.Directory.Parent.FullName, name); System.IO.Directory.Move(fullPath.Directory.FullName, newPath); answer.Added.Add(BaseModel.Create(new DirectoryInfo(newPath), fullPath.Root)); } else { string newPath = Path.Combine(fullPath.File.DirectoryName, name); System.IO.File.Move(fullPath.File.FullName, newPath); answer.Added.Add(BaseModel.Create(new FileInfo(newPath), fullPath.Root)); } return(await Json(answer)); }
public async Task <JsonResult> Open(string target, bool tree) { FullPath fullPath = ParsePath(target); OpenResponse answer = new OpenResponse(BaseModel.Create(fullPath.Directory, fullPath.Root), fullPath); foreach (FileInfo item in fullPath.Directory.GetFiles()) { if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { answer.Files.Add(BaseModel.Create(item, fullPath.Root)); } } foreach (DirectoryInfo item in fullPath.Directory.GetDirectories()) { if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { answer.Files.Add(BaseModel.Create(item, fullPath.Root)); } } return(await Json(answer)); }
public async Task <JsonResult> RenameAsync(FullPath path, string name) { var response = new ReplaceResponseModel(); response.Removed.Add(path.HashedTarget); await RemoveThumbs(path); if (path.IsDirectory) { var newPath = new FileSystemDirectory(Path.Combine(path.Directory.Parent.FullName, name)); Directory.Move(path.Directory.FullName, newPath.FullName); response.Added.Add(await BaseModel.Create(this, newPath, path.RootVolume)); } else { var newPath = new FileSystemFile(Path.Combine(path.File.DirectoryName, name)); File.Move(path.File.FullName, newPath.FullName); response.Added.Add(await BaseModel.Create(this, newPath, path.RootVolume)); } return(await Json(response)); }
public async Task <JsonResult> OpenAsync(FullPath path, bool tree) { var response = new OpenResponse(await BaseModel.Create(this, path.Directory, path.RootVolume), path); foreach (var item in await path.Directory.GetFilesAsync()) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, item, path.RootVolume)); } } foreach (var item in await path.Directory.GetDirectoriesAsync()) { if (!item.Attributes.HasFlag(FileAttributes.Hidden)) { response.Files.Add(await BaseModel.Create(this, item, path.RootVolume)); } } // Add parents if (tree) { var parent = path.Directory; var rootDirectory = new DirectoryInfo(path.RootVolume.RootDirectory); while (parent != null && parent.Name != rootDirectory.Name) { // Update parent parent = parent.Parent; // Ensure it's a child of the root if (parent != null && path.RootVolume.RootDirectory.Contains(parent.Name)) { response.Files.Insert(0, await BaseModel.Create(this, parent, path.RootVolume)); } } } return(await Json(response)); }