private Stream GetContentStream(DbConnection connection, FileAccess fileAccess = FileAccess.ReadWrite) { if (Settings.EnableFileSystemStorage && ObjectId == 0) { var path = DbFileRepository.GetFileSystemPath(this); if (File.Exists(path)) { return(File.Open(path, FileMode.Open, fileAccess)); } throw new Exception($"File '{path}' was not found."); } else { if (ObjectId == 0) { throw new Exception("Trying to get content of a file from database, but it was uploaded to file system. Check FileSystem support configuration."); } var manager = new NpgsqlLargeObjectManager(connection.connection); switch (fileAccess) { case FileAccess.Read: return(manager.OpenRead(ObjectId)); case FileAccess.Write: return(manager.OpenRead(ObjectId)); case FileAccess.ReadWrite: return(manager.OpenReadWrite(ObjectId)); } return(manager.OpenReadWrite(ObjectId)); } }
private Stream GetContentStream(DbConnection connection) { if (Settings.EnableFileSystemStorage && ObjectId == 0) { var path = DbFileRepository.GetFileSystemPath(this); if (File.Exists(path)) { return(File.Open(path, FileMode.Open, FileAccess.ReadWrite)); } throw new Exception($"File '{path}' was not found."); } else { var manager = new NpgsqlLargeObjectManager(connection.connection); return(manager.OpenReadWrite(ObjectId)); } }