Skip to content

Commit

Permalink
feat(application): update directory path into abtraction of file cone…
Browse files Browse the repository at this point in the history
…cction
  • Loading branch information
JeferssonCL committed Sep 18, 2024
1 parent b9bf4cd commit 790378a
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,19 @@ namespace DistributionCenter.Application.Tables.Connections.File.Bases;
public abstract class FileConnectionFactory<T>(string tableName, string fileType) : IFileConnectionFactory<T>
{
private readonly string _completedFilePath = Path.Combine(Environment.CurrentDirectory,
"../../../Resources/" + tableName + "." + fileType);
"../../../../../persistence_data/" + tableName + "." + fileType);

protected string CompletedFilePath => _completedFilePath;
public virtual string CompletedFilePath => _completedFilePath;

public async Task<string> OpenFileAsync()
{
if (!File.Exists(_completedFilePath))
{
string? directoryPath = Path.GetDirectoryName(_completedFilePath);
if (File.Exists(_completedFilePath)) return await File.ReadAllTextAsync(_completedFilePath);

if (directoryPath != null)
{
_ = Directory.CreateDirectory(directoryPath);
}
string? directoryPath = Path.GetDirectoryName(_completedFilePath);
if (directoryPath != null) _ = Directory.CreateDirectory(directoryPath);

await File.Create(_completedFilePath).DisposeAsync();
await File.WriteAllTextAsync(_completedFilePath, "[]");
}
await File.Create(_completedFilePath).DisposeAsync();
await File.WriteAllTextAsync(_completedFilePath, "[]");
return await File.ReadAllTextAsync(_completedFilePath);
}

Expand Down

0 comments on commit 790378a

Please sign in to comment.