private static FilesStorage CreateFileObject(string filePath, string destinationFolderForFiles, string id) { destinationFolderForFiles = destinationFolderForFiles ?? DestinationFilesStorage; string fileName = Path.GetFileName(filePath); string fullpath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + destinationFolderForFiles; string fileExtention = Path.GetExtension(filePath).ToLower().TrimStart('.'); string destinationPath = fullpath + "\\" + fileName; string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); if (!Directory.Exists(fullpath)) { Directory.CreateDirectory(fullpath); } var obj = new FilesStorage { FilePath = destinationPath, FileType = fileExtention, Name = fileNameWithoutExtension, OriginalPath = filePath, Id = id }; return(obj); }
public FilesStorage UpdateFile(string fileId, string updateOriginalPath, string destinationFolderForFiles = null) { this.ThrowNotPossibleRemotelyExceptionIfNecessary(); FilesStorage obj = CreateFileObject(updateOriginalPath, destinationFolderForFiles, fileId); if (obj.FilePath != obj.OriginalPath) { var client = new WebClient(); client.DownloadFile(obj.OriginalPath, obj.FilePath); } return(obj); }
public string SaveFile(string filePath, string destinationFolderForFiles = null) { this.ThrowNotPossibleRemotelyExceptionIfNecessary(); this.Logger?.Trace(this.GetType().Name, $"Storing and saving file {filePath} possibly to destination {destinationFolderForFiles} - {this.GetContextDescription()}"); StorageDatabase <PecanDocument <FilesStorage>, FilesStorage> handle = this.GetDatabaseServiceHandle <FilesStorage>(null); string id = handle.GetNextId().Item1; FilesStorage obj = this.UpdateFile(id, filePath, destinationFolderForFiles); return(this.Save(obj, obj.Id)); }