Last active
April 18, 2023 07:37
-
-
Save hikalkan/9ef8bb64acdfae42f486857013cca333 to your computer and use it in GitHub Desktop.
How to replace IBinaryObjectManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Add registration code to Initialize of your module */ | |
//... | |
public override void Initialize() | |
{ | |
IocManager.Register<IBinaryObjectManager, FileSystemBinaryObjectManager>(DependencyLifeStyle.Transient); //ADD THIS HERE | |
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); | |
} | |
//... | |
/* This is not needed if you delete DbBinaryObjectManager from your solution. */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Threading.Tasks; | |
using Abp.Runtime.Session; | |
namespace MyCompanyName.AbpZeroTemplate.Storage | |
{ | |
/* This is a simple implementation. It's better to implement methods async ( https://msdn.microsoft.com/en-us/library/kztecsys(v=vs.110).aspx ) | |
*/ | |
public class FileSystemBinaryObjectManager : IBinaryObjectManager | |
{ | |
private readonly IAbpSession _abpSession; | |
public FileSystemBinaryObjectManager(IAbpSession abpSession) | |
{ | |
_abpSession = abpSession; | |
} | |
public Task<BinaryObject> GetOrNullAsync(Guid id) | |
{ | |
var filePath = $@"C:\BinaryObjects\{id.ToString("D")}.bin"; | |
if (!File.Exists(filePath)) | |
{ | |
return null; | |
} | |
var binaryObject = new BinaryObject(_abpSession.TenantId, File.ReadAllBytes(filePath)); | |
return Task.FromResult(binaryObject); | |
} | |
public Task SaveAsync(BinaryObject file) | |
{ | |
var filePath = $@"C:\BinaryObjects\{file.Id.ToString("D")}.bin"; | |
File.WriteAllBytes(filePath, file.Bytes); | |
return Task.CompletedTask; | |
} | |
public Task DeleteAsync(Guid id) | |
{ | |
var filePath = $@"C:\BinaryObjects\{id.ToString("D")}.bin"; | |
if (!File.Exists(filePath)) | |
{ | |
return null; | |
} | |
File.Delete(filePath); | |
return Task.CompletedTask; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment