public virtual async Task <StorageReturnValue> DownloadFileAsynch(string downloadToLocation, List <string> fileNameWithExtList) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); List <FileStorageAttachment> listFileDownload = new List <FileStorageAttachment>(); foreach (var item in fileNameWithExtList) { string pathFileName = Path.Combine(downloadToLocation, item.Trim()); FileStorageAttachment downloaded = null; result = await fileManagementAsync.CreateFileDownloadAsync(pathFileName); if (result.IsSuccess) { downloaded = (FileStorageAttachment)result.ListFile[0]; result.IsSuccess = true; result.ListFile.Add(downloaded); } else { result.ErrorMessage = FileStorageProperties.GetInstance.WrongFileDownload; } } return(result); }
public virtual StorageReturnValue DeleteFolder(string pathFolderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFolderName)) { //BlobContinuationToken blobContinuationToken = null; //do //{ // var azureDirBlob = azure.AzureBlobDirectory(pathFolderName); // var listblob = azureDirBlob.ListBlobsSegmentedAsync(blobContinuationToken).GetAwaiter().GetResult(); // blobContinuationToken = listblob.ContinuationToken; // foreach (var item in listblob.Results) // { // if (item is CloudBlobDirectory directory) // { // //DeleteBlobsInDirectoryAsync(azure.StorageContainerName, directory.Prefix); // } // else if (item is CloudPageBlob pageBlob) // { // //CloudPageBlob cloudPageBlob = container.GetPageBlobReference(pageBlob.Name); // //success = await cloudPageBlob.DeleteIfExistsAsync(); // } // else if (item is CloudBlockBlob blockBlob) // { // //CloudBlockBlob cloudBlockBlob = container.GetBlockBlobReference(blockBlob.Name); // //success = await cloudBlockBlob.DeleteIfExistsAsync(); // } // } //} while (blobContinuationToken != null); result = new StorageReturnValue(true, "Temp true, still under construction", null); } return(result); }
public virtual StorageReturnValue CreateFolder(string pathFolderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFolderName)) { result = CheckFolderAndCreate(pathFolderName); } return(result); }
public virtual async Task <StorageReturnValue> DeleteFileAsync(string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); await Task.Run(() => { result = this.DeleteFile(pathFileNameWithExt); }); return(result); }
public virtual async Task <StorageReturnValue> CreateFileUploadAsync(byte[] uploadedFile, string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); await Task.Run(() => { result = this.CreateFileUpload(uploadedFile, pathFileNameWithExt); }); return(result); }
public virtual StorageReturnValue DeleteFile(string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFileNameWithExt)) { result = client.StorageFtpDelete(pathFileNameWithExt); } return(result); }
public StorageReturnValue CheckFolderStorageExistAndCreate(string folderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(folderName)) { IFolderManagement folderManagement = FolderFileBantuan.GetInstance.DictFolder[FileStorageProperties.GetInstance.FileStorageType]; result = folderManagement.CheckFolderAndCreate(folderName); } return(result); }
public virtual async Task <StorageReturnValue> DownloadFileAsynch(string downloadToLocation, string fileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); string pathFileName = Path.Combine(downloadToLocation, fileNameWithExt); if (!string.IsNullOrEmpty(pathFileName)) { pathFileName = pathFileName.Trim(); result = await fileManagementAsync.CreateFileDownloadAsync(pathFileName); } return(result); }
public virtual StorageReturnValue DeleteFolder(string folderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (client.FtpDeleteDirectory(folderName)) { result = result.SetStorageReturnValue(true, string.Empty, null); } else { result = result.SetStorageReturnValue(false, string.Empty, null); } return(result); }
public virtual StorageReturnValue CreateFileUpload(byte[] uploadedFile, string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFileNameWithExt) & uploadedFile != null) { pathFileNameWithExt = pathFileNameWithExt.Trim(); if (client.FtpFileExists(pathFileNameWithExt)) { client.FtpDelete(pathFileNameWithExt); } client.StorageUpload(pathFileNameWithExt, uploadedFile); } return(result); }
private async Task <StorageReturnValue> UploadFileProcessAsync(string uploadToLocation, List <FileStorageAttachment> uploadedFile) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(uploadToLocation) & uploadedFile != null) { uploadToLocation = uploadToLocation.Trim(); if (FileStorageProperties.GetInstance.FileStorageType == StorageType.Azure) { result = FileValidation.GetInstance.CheckFolderStorageExistAndCreate(uploadToLocation); if (!result.IsSuccess) { return(result); } result = FileValidation.GetInstance.IsFileExtAllowed(uploadedFile); if (!result.IsSuccess) { return(result); } List <FileStorageAttachment> uploadedFileSuccess = new List <FileStorageAttachment>(); foreach (FileStorageAttachment item in uploadedFile) { string fileName = item.GetFileName; string fileToUpload = Path.Combine(uploadToLocation, fileName); result = await fileManagementAsync.CreateFileUploadAsync(item.FileAttachment, fileToUpload); if (result.IsSuccess) { uploadedFileSuccess.Add(item); } else { break; } } if (!result.IsSuccess) { /*if any error when uploaded,all data will be deleted also*/ foreach (FileStorageAttachment item in uploadedFile) { string fileName = item.GetFileName; string fileToUpload = Path.Combine(uploadToLocation, fileName); result = await fileManagementAsync.DeleteFileAsync(fileToUpload); } } } } return(result); }
public virtual async Task <StorageReturnValue> UploadFileAsync(string uploadToLocation, List <FileStorageAttachment> uploadedFile, int sizeLimit) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(uploadToLocation) & uploadedFile != null) { uploadToLocation = uploadToLocation.Trim(); result = FileValidation.GetInstance.IsFileSizeLimitationOK(uploadedFile, sizeLimit); if (result.IsSuccess) { result = await this.UploadFileProcessAsync(uploadToLocation, uploadedFile); } } return(result); }
private StorageReturnValue UploadFileProcess(string uploadToLocation, List <FileStorageAttachment> uploadedFile) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(uploadToLocation) & uploadedFile != null) { uploadToLocation = uploadToLocation.Trim(); if (FileStorageProperties.GetInstance.FileStorageType == StorageType.LocalNetwork) { result = FileValidation.GetInstance.CheckFolderStorageExistAndCreate(uploadToLocation); if (!result.IsSuccess) { return(result); } result = FileValidation.GetInstance.IsFileExtAllowed(uploadedFile); if (!result.IsSuccess) { return(result); } string folderUploadToLocation = Path.Combine(localNetwork, uploadToLocation); List <FileStorageAttachment> uploadedFileSuccess = new List <FileStorageAttachment>(); foreach (FileStorageAttachment item in uploadedFile) { string fileName = !string.IsNullOrEmpty(item.FileNameWithExtRenamed) ? item.FileNameWithExtRenamed : item.FileNameWithExt; string fileToUpload = Path.Combine(folderUploadToLocation, fileName); result = fileManagement.CreateFileUpload(item.FileAttachment, fileToUpload); if (result.IsSuccess) { uploadedFileSuccess.Add(item); } else { break; } } if (!result.IsSuccess) { /*if any error when uploaded,all data will be deleted also*/ foreach (FileStorageAttachment item in uploadedFile) { string fileName = !string.IsNullOrEmpty(item.FileNameWithExtRenamed) ? item.FileNameWithExtRenamed : item.FileNameWithExt; string fileToUpload = Path.Combine(folderUploadToLocation, fileName); result = fileManagement.DeleteFile(fileToUpload); } } } } return(result); }
public virtual StorageReturnValue CheckFolderExist(string folderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); var checkDir = client.ListDirectory(folderName).Where(a => (string)a == folderName).ToList(); if (checkDir.Count > 0) { result = result.SetStorageReturnValue(true, string.Empty, null); } else { result = result.SetStorageReturnValue(false, string.Empty, null); } return(result); }
public virtual StorageReturnValue CreateFileUpload(byte[] uploadedFile, string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); try { var myblob = azure.blobContainerInstance.GetBlockBlobReference(pathFileNameWithExt); myblob.UploadFromByteArrayAsync(uploadedFile, 0, uploadedFile.Length).GetAwaiter().GetResult(); result = new StorageReturnValue(true, string.Empty, null); } catch (Exception ex) { result = new StorageReturnValue(false, ex.Message + " :" + FileStorageProperties.GetInstance.WrongFileUpload, null); } return(result); }
public virtual StorageReturnValue DeleteFile(string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); try { var myblob = azure.blobContainerInstance.GetBlockBlobReference(pathFileNameWithExt); myblob.DeleteIfExistsAsync().GetAwaiter().GetResult(); result = new StorageReturnValue(true, string.Empty, null); } catch (Exception ex) { result = new StorageReturnValue(false, ex.Message + " :" + FileStorageProperties.GetInstance.WrongFileDelete, null); } return(result); }
public virtual StorageReturnValue CreateFolder(string pathFolderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFolderName)) { try { if (FileStorageProperties.GetInstance.FileStorageType == StorageType.LocalNetwork) { string checkFolderAddress = Path.Combine(localNetwork, pathFolderName); Directory.CreateDirectory(checkFolderAddress); result = result.SetStorageReturnValue(true, string.Empty, null); } } catch (Exception ex) { result = result.SetStorageReturnValue(false, ex.Message.ToString(), null); } } return(result); }
public virtual StorageReturnValue CreateFileDownload(string pathFileNameWithExt) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); try { Byte[] mybyte = null; var myblob = azure.blobContainerInstance.GetBlockBlobReference(pathFileNameWithExt); myblob.DownloadToByteArrayAsync(mybyte, 0).GetAwaiter().GetResult(); FileStorageAttachment fileStorage = new FileStorageAttachment(); fileStorage.FileAttachment = mybyte; fileStorage.FileNameWithExt = pathFileNameWithExt; fileStorage.FileNameWithExtRenamed = pathFileNameWithExt; var file = new List <FileStorageAttachment>(); file.Add(fileStorage); result = new StorageReturnValue(true, string.Empty, file); } catch (Exception ex) { result = new StorageReturnValue(false, ex.Message + " :" + FileStorageProperties.GetInstance.WrongFileUpload, null); } return(result); }
public StorageReturnValue IsFileExtAllowed(List <FileStorageAttachment> fileAttachments) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (fileAttachments != null) { string[] fileExtAllowed = FileStorageProperties.GetInstance.FileExtAllowed; if (fileExtAllowed.Contains("*")) // if found * , all files ok { result.SetStorageReturnValue(true, string.Empty, null); } else { if (fileAttachments.Where(a => a.FileNameWithExt.Contains(".") == false).Count() > 0) // filename must have dot (.) { result.SetStorageReturnValue(false, FileStorageProperties.GetInstance.WrongFileExt, null); } else { foreach (var item in fileAttachments) { string[] fileNameArray = item.FileNameWithExt.Split("."); if (fileNameArray.Length > 0) { string fileExt = fileNameArray[(fileNameArray.Length) - 1].Trim().Replace(".", ""); if (fileExtAllowed.Contains(fileExt)) { result.SetStorageReturnValue(true, string.Empty, null); } else { result.SetStorageReturnValue(false, FileStorageProperties.GetInstance.WrongFileExt, null); } } } } } } return(result); }
public virtual StorageReturnValue CheckFolderExist(string pathFolderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFolderName)) { if (FileStorageProperties.GetInstance.FileStorageType == StorageType.LocalNetwork) { if (!string.IsNullOrEmpty(localNetwork)) { string checkFolderAddress = Path.Combine(localNetwork, pathFolderName); if (Directory.Exists(checkFolderAddress)) { result = result.SetStorageReturnValue(true, string.Empty, null); } else { result = result.SetStorageReturnValue(false, FileStorageProperties.GetInstance.WrongFolderManagement, null); } } } } return(result); }
public StorageReturnValue IsFileSizeLimitationOK(List <FileStorageAttachment> fileAttachments, int sizeLimit) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (fileAttachments != null) { int fileLimit = sizeLimit; int totLimit = 0; foreach (var item in fileAttachments) { totLimit += item.FileAttachment.Length; } if (totLimit < fileLimit) { result = result.SetStorageReturnValue(true, string.Empty, null); } else { result = result.SetStorageReturnValue(false, FileStorageProperties.GetInstance.WrongAttachment + " Max Size : " + FileStorageProperties.GetInstance.FileUploadMaxSize.ToString(), null); } } return(result); }
public virtual StorageReturnValue CheckFolderAndCreate(string pathFolderName) { result = new StorageReturnValue(false, FileStorageProperties.GetInstance.WrongInitialManagement, null); if (!string.IsNullOrEmpty(pathFolderName)) { try { string localPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string localFileName = "DefaultSystemGenerated_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".txt"; string PathFileName = Path.Combine(pathFolderName, localFileName); var sourceFile = Path.Combine(localPath, localFileName); File.WriteAllText(sourceFile, FileStorageProperties.GetInstance.AzureGeneratedFile); var myblob = azure.AzureBlobContainer.GetBlockBlobReference(PathFileName); myblob.DeleteAsync().Wait(); myblob.UploadFromFileAsync(sourceFile).Wait(); FileNetwork.GetInstance.DeleteFile(sourceFile); result = result.SetStorageReturnValue(true, string.Empty, null); } catch (Exception ex) { result = result.SetStorageReturnValue(false, ex.Message, null); }; } return(result); }