public void GenerateFile(FATCA_OECD FATCAObj) { XmlSerializer xser = new XmlSerializer(typeof(FATCA_OECD)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("ftc", "urn:oecd:ties:fatca:v2"); ns.Add("stf", "urn:oecd:ties:stf:v4"); ns.Add("sfa", "urn:oecd:ties:stffatcatypes:v2"); ns.Add("iso", "urn:oecd:ties:isofatcatypes:v1"); ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); //Sorting Reports By type var AccountReport = FATCAObj.FATCA[0].ReportingGroup[0].Items.OfType <CorrectableAccountReport_Type>(); var NilReport = FATCAObj.FATCA[0].ReportingGroup[0].Items.OfType <CorrectableNilReport_Type>(); var PoolReport = FATCAObj.FATCA[0].ReportingGroup[0].Items.OfType <CorrectablePoolReport_Type>(); IEnumerable <object> Reports = new object[0]; if (AccountReport.Count() > 0 || PoolReport.Count() > 0) { Reports = AccountReport.Concat <object>(PoolReport); FATCAObj.FATCA[0].ReportingGroup[0].Items = Reports.ToArray(); string accountsPoolReportUrl = Path.Combine(appConfiguration.DestinationFilesDirectory, DateTime.Now.ToString("yyyyMMddHHmmss_") + "Accounts_Pool_Report.xml"); using (StreamWriter s = new StreamWriter(accountsPoolReportUrl)) { xser.Serialize(s, FATCAObj, ns); applicationLog.LogMessage($"Archivo Generado con éxito: {accountsPoolReportUrl}"); } } if (NilReport.Count() > 0) { Reports = NilReport; FATCAObj.FATCA[0].ReportingGroup[0].Items = Reports.ToArray(); string NilReportUrl = Path.Combine(appConfiguration.DestinationFilesDirectory, DateTime.Now.ToString("yyyyMMddHHmmss_") + "NilReport.xml"); using (StreamWriter s = new StreamWriter(NilReportUrl)) { xser.Serialize(s, FATCAObj, ns); applicationLog.LogMessage($"Archivo Generado con éxito: {NilReportUrl}"); } } }
public IEnumerable <string[]> GetFATCAData() { List <string[]> FATCAData = new List <string[]>(); var path = _appConfiguration.SourceFilesDirectory; System.IO.DirectoryInfo Dinfo = new DirectoryInfo(path); var filesinDirectory = Dinfo.GetFiles("*.csv"); if (filesinDirectory.Count() > 0) { using (TextFieldParser csvParser = new TextFieldParser(filesinDirectory[0].FullName)) { csvParser.CommentTokens = new string[] { "#" }; csvParser.SetDelimiters(new string[] { "," }); csvParser.HasFieldsEnclosedInQuotes = true; // Skip the row with the column names // csvParser.ReadLine(); while (!csvParser.EndOfData) { // Read current line fields, pointer moves to the next line. FATCAData.Add(csvParser.ReadFields()); } } if (FATCAData.Count == 0) { applicationLog.LogMessage($"No se encontraron Datos en el archivo{filesinDirectory[0].FullName}"); } else { applicationLog.LogMessage($"Se ha encontrado el archivo {filesinDirectory[0].FullName} con {FATCAData.Count} registros"); } filesinDirectory[0].Delete(); } else { applicationLog.LogMessage("No se encontraron archivos en la carpeta de Origen"); } return(FATCAData); }