Giuliano Paschoalino 690ab131aa feat: Initialize ComplianceNFs project structure with core, infrastructure, service, and monitor components
- Created ComplianceNFs.Core project with domain entities and ports
- Implemented BuyingRecord, EnergyInvoice, ParsedInvoice entities
- Defined domain interfaces for mail listening, XML and PDF parsing, and repository access
- Established ComplianceNFs.Infrastructure project with file archiving, mail listening, and data access implementations
- Developed PDF and XML parsers for invoice data extraction
- Set up AccessDbRepository and AttachmentRepository for data retrieval and storage
- Created ComplianceNFs.Service project for background processing and service orchestration
- Implemented Worker service for periodic tasks
- Established ComplianceNFs.Monitor project with WPF UI for monitoring invoice statuses
- Added ViewModel for UI data binding and command handling
- Configured project files for .NET 9.0 and necessary package references
- Created initial appsettings.json for configuration management
- Added TODOs and roadmap for future development
2025-06-05 14:47:28 -03:00

32 lines
1.3 KiB
C#

using System.IO;
using System.Text.RegularExpressions;
using ComplianceNFs.Core.Entities;
using ComplianceNFs.Core.Ports;
namespace ComplianceNFs.Infrastructure.Parsers
{
public class PdfParser : IPdfParser
{
public ParsedInvoice Parse(Stream pdfStream)
{
// Minimal demo: just read bytes as text (replace with real PDF parsing in production)
using var ms = new MemoryStream();
pdfStream.CopyTo(ms);
var text = System.Text.Encoding.UTF8.GetString(ms.ToArray());
// Example: extract CNPJ and values using regex (replace with real patterns)
var cnpjComp = Regex.Match(text, @"CNPJComp: (\d{14})").Groups[1].Value;
var cnpjVend = Regex.Match(text, @"CNPJVend: (\d{14})").Groups[1].Value;
var montNF = decimal.TryParse(Regex.Match(text, @"MontNF: ([\d,.]+)").Groups[1].Value, out var m) ? m : 0;
var precNF = decimal.TryParse(Regex.Match(text, @"PrecNF: ([\d,.]+)").Groups[1].Value, out var p) ? p : 0;
return new ParsedInvoice
{
CnpjComp = cnpjComp,
CnpjVend = cnpjVend,
MontNF = montNF,
PrecNF = precNF
// ...fill other fields as needed
};
}
}
}