Skip to content

Commit f74bc78

Browse files
committed
stable version 5.0.3
1 parent ca7da7c commit f74bc78

File tree

8 files changed

+299
-465
lines changed

8 files changed

+299
-465
lines changed

DownloaderExtensions.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,8 @@ public static TEnum ToEnumElement<TEnum>(this string code) where TEnum : struct,
169169
/// <param name="services">The service collection</param>
170170
/// <param name="storageSettings">File storage settings</param>
171171
/// <returns>The service collection for chaining</returns>
172-
public static IServiceCollection AddXmlDownloader(this IServiceCollection services,
173-
Action<FileStorageSettings>? storageSettings = null)
172+
public static IServiceCollection AddXmlDownloader(this IServiceCollection services)
174173
{
175-
// File storage settings
176-
if (storageSettings is not null)
177-
services.Configure(storageSettings);
178-
else
179-
services.Configure<FileStorageSettings>(settings => { settings.InitializeDefaultDirectories(); });
180-
181-
182174
// Register the services
183175
services.AddScoped<IAuthService, AuthService>();
184176
services.AddScoped<IQueryService, QueryService>();

FileStorage/FileStorageService.cs

Lines changed: 135 additions & 279 deletions
Large diffs are not rendered by default.

FileStorage/FileStorageSettings.cs

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,22 @@
1414
* ============================================================================
1515
*/
1616

17-
using System.Runtime.InteropServices;
18-
1917
namespace Fiscalapi.XmlDownloader.FileStorage;
2018

21-
/// <summary>
22-
/// Configuration settings for file management operations
23-
/// </summary>
24-
public class FileStorageSettings
19+
public static class FileStorageSettings
2520
{
2621
/// <summary>
2722
/// Package file extension
2823
/// </summary>
29-
public string PackageExtension { get; set; } = ".zip";
24+
public static string PackageExtension { get; set; } = ".zip";
3025

3126
/// <summary>
32-
/// XML file extension for CFDI documents
27+
/// CFDI file extension
3328
/// </summary>
34-
public string CfdiExtension { get; set; } = ".xml";
29+
public static string CfdiExtension { get; set; } = ".xml";
3530

3631
/// <summary>
3732
/// Metadata file extension
3833
/// </summary>
39-
public string MetadataExtension { get; set; } = ".txt";
40-
41-
/// <summary>
42-
/// Folder to perform temporary operations like folder extractions
43-
/// </summary>
44-
public string TempDirectory { get; set; } = string.Empty;
45-
46-
/// <summary>
47-
/// Folder where packages will be saved
48-
/// </summary>
49-
public string PackagesDirectory { get; set; } = string.Empty;
50-
51-
/// <summary>
52-
/// Initialize default directories based on current operating system
53-
/// </summary>
54-
public void InitializeDefaultDirectories()
55-
{
56-
if (string.IsNullOrEmpty(TempDirectory))
57-
{
58-
//Windows: C:\Users\[Username]\AppData\Local\Fiscalapi\Temp
59-
//Linux : /home/[username]/.fiscalapi/temp
60-
TempDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
61-
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Fiscalapi",
62-
"Temp")
63-
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".fiscalapi", "temp");
64-
}
65-
66-
if (string.IsNullOrEmpty(PackagesDirectory))
67-
{
68-
//Windows: C:\Users\[Username]\AppData\Local\Fiscalapi\Packages
69-
//Linux : /home/[username]/.fiscalapi/packages
70-
PackagesDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
71-
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Fiscalapi",
72-
"Packages")
73-
: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".fiscalapi",
74-
"packages");
75-
}
76-
}
34+
public static string MetaExtension { get; set; } = ".txt";
7735
}

FileStorage/IFileStorageService.cs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,91 +17,91 @@
1717
namespace Fiscalapi.XmlDownloader.FileStorage;
1818

1919
/// <summary>
20-
/// Interface for cross-platform file system operations
21-
/// Designed to support multiple implementations like local file system, cloud storage, etc.
20+
/// Interface for file system operations.
2221
/// </summary>
2322
public interface IFileStorageService
2423
{
25-
/// <summary>
26-
/// Check if a file exists at the specified path
27-
/// </summary>
28-
bool FileExists(string filePath);
29-
3024
/// <summary>
3125
/// Check if a directory exists at the specified path
3226
/// </summary>
27+
/// <param name="directoryPath">Full path to the directory</param>
28+
/// <returns>True if directory exists</returns>
3329
bool DirectoryExists(string directoryPath);
3430

3531
/// <summary>
3632
/// Delete all files and folders recursively from the specified directory
3733
/// </summary>
38-
Task CleanDirectoryAsync(string directoryPath, CancellationToken cancellationToken = default);
34+
/// <param name="directoryPath">Full path to the directory to clean</param>
35+
/// <param name="cancellationToken">Cancellation token</param>
36+
void CleanDirectory(string directoryPath, CancellationToken cancellationToken = default);
3937

4038
/// <summary>
41-
/// Extract a ZIP file to the specified destination path or default directory if not specified
39+
/// Create a directory if it doesn't exist
4240
/// </summary>
43-
/// <param name="zipFilePath">Package .zip path</param>
44-
/// <param name="extractToPath">Path to write unzip files</param>
45-
/// <param name="cancellationToken">CancellationToken</param>
46-
/// <returns>Completion Task</returns>
47-
Task ExtractZipFileAsync(string zipFilePath, string? extractToPath = null,
48-
CancellationToken cancellationToken = default);
41+
/// <param name="directoryPath">Full path to the directory to create</param>
42+
void CreateDirectoryIfNotExist(string directoryPath);
4943

5044
/// <summary>
51-
/// Ensure required directories exist based on configuration settings
45+
/// Check if a file exists at the specified path
5246
/// </summary>
53-
Task EnsureDirectoriesAsync(CancellationToken cancellationToken = default);
47+
/// <param name="fullFilePath">Full path to the file</param>
48+
/// <returns>True if file exists</returns>
49+
bool FileExists(string fullFilePath);
5450

5551
/// <summary>
56-
/// Get a list of files from the specified directory with optional file extension filter
52+
/// Extract a ZIP file to the specified destination path
5753
/// </summary>
58-
Task<List<FileDetails>> GetFilesAsync(string directoryPath, string? fileExtension = null,
54+
/// <param name="fullFilePath">Full path to the ZIP file</param>
55+
/// <param name="extractToPath">Path to extract files to</param>
56+
/// <param name="cancellationToken">Cancellation token</param>
57+
/// <returns>Completion Task</returns>
58+
void ExtractZipFile(string fullFilePath, string extractToPath,
5959
CancellationToken cancellationToken = default);
6060

61+
/// <summary>
62+
/// Get a list of files from the specified directory with optional file extension filter
63+
/// </summary>
64+
/// <param name="directoryPath">Full path to the directory</param>
65+
/// <param name="fileExtension">File extension filter (optional)</param>
66+
/// <returns>List of file details</returns>
67+
List<FileDetails> GetFiles(string directoryPath, string? fileExtension = null);
68+
6169
/// <summary>
6270
/// Write binary data to a file
6371
/// </summary>
64-
Task WriteFileAsync(string filePath, byte[] data, CancellationToken cancellationToken = default);
72+
/// <param name="fullFilePath">Full path to the file</param>
73+
/// <param name="data">Binary data to write</param>
74+
/// <param name="cancellationToken">Cancellation token</param>
75+
Task WriteFileAsync(string fullFilePath, byte[] data, CancellationToken cancellationToken = default);
6576

6677
/// <summary>
6778
/// Write base64 encoded data to a file
6879
/// </summary>
69-
Task WriteFileAsync(string filePath, string base64Data, CancellationToken cancellationToken = default);
80+
/// <param name="fullFilePath">Full path to the file</param>
81+
/// <param name="base64Data">Base64 encoded data to write</param>
82+
/// <param name="cancellationToken">Cancellation token</param>
83+
Task WriteFileAsync(string fullFilePath, string base64Data, CancellationToken cancellationToken = default);
7084

7185
/// <summary>
7286
/// Read file content as byte array
7387
/// </summary>
74-
Task<byte[]> ReadFileAsync(string filePath, CancellationToken cancellationToken = default);
88+
/// <param name="fullFilePath">Full path to the file</param>
89+
/// <param name="cancellationToken">Cancellation token</param>
90+
/// <returns>File content as byte array</returns>
91+
Task<byte[]> ReadFileAsync(string fullFilePath, CancellationToken cancellationToken = default);
7592

7693
/// <summary>
7794
/// Read file content as string
7895
/// </summary>
79-
Task<string> ReadFileContentAsync(string filePath, CancellationToken cancellationToken = default);
80-
81-
/// <summary>
82-
/// Copy a file from source to destination
83-
/// </summary>
84-
Task<bool> CopyFileAsync(string sourceFilePath, string destinationFilePath, bool overwrite = false,
85-
CancellationToken cancellationToken = default);
86-
87-
/// <summary>
88-
/// Move a file from source to destination
89-
/// </summary>
90-
Task<bool> MoveFileAsync(string sourceFilePath, string destinationFilePath,
91-
CancellationToken cancellationToken = default);
96+
/// <param name="fullFilePath">Full path to the file</param>
97+
/// <param name="cancellationToken">Cancellation token</param>
98+
/// <returns>File content as string</returns>
99+
Task<string> ReadFileContentAsync(string fullFilePath, CancellationToken cancellationToken = default);
92100

93101
/// <summary>
94102
/// Delete a file
95103
/// </summary>
96-
Task<bool> DeleteFileAsync(string filePath, CancellationToken cancellationToken = default);
97-
98-
/// <summary>
99-
/// Get file size in bytes
100-
/// </summary>
101-
Task<long> GetFileSizeAsync(string filePath, CancellationToken cancellationToken = default);
102-
103-
/// <summary>
104-
/// Create a directory if it doesn't exist
105-
/// </summary>
106-
Task CreateDirectoryAsync(string directoryPath, CancellationToken cancellationToken = default);
104+
/// <param name="fullFilePath">Full path to the file</param>
105+
/// <returns>True if file was deleted successfully</returns>
106+
void DeleteFile(string fullFilePath);
107107
}

IXmlDownloaderService.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,40 @@ Task<AuthResponse> AuthenticateAsync(string base64Cer, string base64Key, string
8989
/// <summary>
9090
/// Writes the downloaded package bytes to a file at the specified path.
9191
/// </summary>
92-
/// <param name="path">Disk path where package will be written</param>
92+
/// <param name="fullFilePath">Disk path where package will be written</param>
9393
/// <param name="bytes">Package data in bytes</param>
9494
/// <param name="cancellationToken">cancellationToken</param>
9595
/// <returns>Completed Task</returns>
96-
Task WritePackageAsync(string path, byte[] bytes, CancellationToken cancellationToken = default);
96+
Task WritePackageAsync(string fullFilePath, byte[] bytes, CancellationToken cancellationToken = default);
9797

9898

9999
/// <summary>
100100
/// Writes the downloaded package data to a file at the specified path.
101101
/// </summary>
102-
/// <param name="path">Disk path where package will be written</param>
102+
/// <param name="fullFilePath">Disk path where package will be written</param>
103103
/// <param name="base64Package">Package data in base 64</param>
104104
/// <param name="cancellationToken">cancellationToken</param>
105105
/// <returns>Completed Task</returns>
106-
Task WritePackageAsync(string path, string base64Package, CancellationToken cancellationToken = default);
106+
Task WritePackageAsync(string fullFilePath, string base64Package, CancellationToken cancellationToken = default);
107107

108108

109109
/// <summary>
110110
/// Reads a file from the disk at the specified path and returns its content as a byte array.
111111
/// </summary>
112-
/// <param name="filePath">File path</param>
112+
/// <param name="fullFilePath">File path</param>
113113
/// <param name="cancellationToken">CancellationToken</param>
114114
/// <returns>data in bytes</returns>
115-
Task<byte[]> ReadFileAsync(string filePath, CancellationToken cancellationToken = default);
115+
Task<byte[]> ReadFileAsync(string fullFilePath, CancellationToken cancellationToken = default);
116116

117117

118118
/// <summary>
119119
/// Retrieves a list of Comprobantes from a package represented by its extracted directory path.
120120
/// </summary>
121-
/// <param name="zipFilePath">Package .zip file path</param>
121+
/// <param name="fullZipFilePath">Package .zip file path</param>
122+
/// <param name="extractToPath"></param>
122123
/// <param name="cancellationToken">CancellationToken</param>
123124
/// <returns>List of Comprobantes objects</returns>
124-
IAsyncEnumerable<Comprobante> GetComprobantesAsync(string zipFilePath,
125+
IAsyncEnumerable<Comprobante> GetComprobantesAsync(string fullZipFilePath, string extractToPath,
125126
CancellationToken cancellationToken = default);
126127

127128
/// <summary>

XmlDownloader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>5.0.2</Version>
7+
<Version>5.0.3</Version>
88
<AssemblyVersion>$(Version)</AssemblyVersion>
99
<FileVersion>$(Version)</FileVersion>
1010
<PackageVersion>$(Version)</PackageVersion>

0 commit comments

Comments
 (0)