public async Task <FileExplorerResponse> GetDetailsAsync(string path, string[] names, IEnumerable <object> selectedItems = null) { FileExplorerResponse DetailsResponse = new FileExplorerResponse(); try { bool isFile = false; FileDetails[] fDetails = new FileDetails[names.Length]; FileDetails fileDetails = new FileDetails(); if (selectedItems != null) { foreach (var Fileitem in selectedItems) { Newtonsoft.Json.Linq.JToken myObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JToken>(Fileitem.ToString()); AzureFileDirectoryContent s_item = myObject.ToObject <AzureFileDirectoryContent>(); isFile = s_item.isFile; break; } } if (isFile) { CloudBlockBlob blockBlob = container.GetBlockBlobReference(path + names[0]); await blockBlob.FetchAttributesAsync(); fileDetails.Name = blockBlob.Name; fileDetails.Type = blockBlob.Name.Split('.')[1]; fileDetails.Location = blockBlob.Uri.ToString(); fileDetails.Size = blockBlob.Properties.Length; fileDetails.Modified = blockBlob.Properties.LastModified.Value.LocalDateTime.ToString(); } else { CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path); fileDetails.Name = names[0]; fileDetails.Location = sampleDirectory.Uri.ToString() + "/" + names[0]; fileDetails.Type = "File Folder"; fileDetails.Modified = sampleDirectory.Container.Properties.LastModified.ToString(); } fDetails[0] = fileDetails; DetailsResponse.details = fDetails; return(await Task.Run(() => { return DetailsResponse; })); } catch (Exception ex) { throw ex; } }
public async Task RenameAsync(string path, string oldName, string newName, IEnumerable <CommonFileDetails> commonFiles, IEnumerable <object> selectedItems = null) { bool isFile = false; foreach (var Fileitem in selectedItems) { Newtonsoft.Json.Linq.JToken myObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JToken>(Fileitem.ToString()); AzureFileDirectoryContent s_item = myObject.ToObject <AzureFileDirectoryContent>(); isFile = s_item.isFile; break; } if (isFile) { CloudBlob existBlob = container.GetBlobReference(path + oldName); CloudBlob newBlob = container.GetBlobReference(path + newName); await newBlob.StartCopyAsync(existBlob.Uri); await existBlob.DeleteIfExistsAsync(); } else { CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path + oldName); var items = await AsyncReadCall(path + oldName, "Rename"); foreach (var item in items.Results) { string name = item.Uri.AbsolutePath.Replace(sampleDirectory.Uri.AbsolutePath, ""); CloudBlob newBlob = container.GetBlobReference(path + newName + "/" + name); await newBlob.StartCopyAsync(item.Uri); await container.GetBlobReference(path + oldName + "/" + name).DeleteAsync(); } } }
public async Task RemoveAsync(string[] names, string path, IEnumerable <object> selectedItems = null) { CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(path); foreach (var Fileitem in selectedItems) { Newtonsoft.Json.Linq.JToken myObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JToken>(Fileitem.ToString()); AzureFileDirectoryContent s_item = myObject.ToObject <AzureFileDirectoryContent>(); if (s_item.isFile) { CloudBlockBlob blockBlob = container.GetBlockBlobReference(path + s_item.name); await blockBlob.DeleteAsync(); } else { CloudBlobDirectory subDirectory = container.GetDirectoryReference(path + s_item.name); var items = await AsyncReadCall(path + s_item.name, "Remove"); foreach (var item in items.Results) { CloudBlockBlob blockBlob = container.GetBlockBlobReference(path + s_item.name + "/" + item.Uri.ToString().Replace(subDirectory.Uri.ToString(), "")); await blockBlob.DeleteAsync(); } } } }
public async Task PasteAsync(string sourceDir, string targetDir, string[] names, string option, IEnumerable <CommonFileDetails> commonFiles, IEnumerable <object> selectedItems = null, IEnumerable <object> targetFolder = null) { foreach (var Fileitem in selectedItems) { Newtonsoft.Json.Linq.JToken myObject = Newtonsoft.Json.JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JToken>(Fileitem.ToString()); AzureFileDirectoryContent s_item = myObject.ToObject <AzureFileDirectoryContent>(); if (s_item.isFile) { string sourceDir1 = sourceDir + s_item.name; CloudBlob existBlob = container.GetBlobReference(sourceDir1); CloudBlob newBlob = container.GetBlobReference(targetDir + s_item.name); await newBlob.StartCopyAsync(existBlob.Uri); if (option == "move") { await existBlob.DeleteIfExistsAsync(); } } else { CloudBlobDirectory sampleDirectory = container.GetDirectoryReference(sourceDir + s_item.name); string Oper = "Paste"; var items = await AsyncReadCall(sourceDir + s_item.name, Oper); foreach (var item in items.Results) { string name = item.Uri.ToString().Replace(sampleDirectory.Uri.ToString(), ""); CloudBlob newBlob = container.GetBlobReference(targetDir + s_item.name + "/" + name); await newBlob.StartCopyAsync(item.Uri); if (option == "move") { await container.GetBlobReference(sourceDir + s_item.name + "/" + name).DeleteAsync(); } } } } }