public void TestProcesarDistribucionDocumentosXBRL() { LogUtil.LogDirPath = @"..\..\TestOutput\"; LogUtil.Inicializa(); var DirectorioProcesar = @"..\..\TestInput\XBRL\JBRL\Auxiliar"; var xpe = XPEServiceImpl.GetInstance(true); var abaxXBRLCellStoreMongo = new AbaxXBRLCellStoreMongo(); abaxXBRLCellStoreMongo.JSONOutDirectory = @"..\..\TestOutput\"; abaxXBRLCellStoreMongo.ConnectionString = "mongodb://localhost/jbrl"; abaxXBRLCellStoreMongo.DataBaseName = "jbrl"; //abaxXBRLCellStoreMongo.ConnectionString = "mongodb+srv://oscarloyola:[email protected]/xbrl?retryWrites=true"; //abaxXBRLCellStoreMongo.DataBaseName = "xbrl"; abaxXBRLCellStoreMongo.Init(); var mongoDB = abaxXBRLCellStoreMongo.GetMongoDB(); XPEService xpeService = XPEServiceImpl.GetInstance(); string[] fileEntries = Directory.GetFiles(DirectorioProcesar); var taskList = new List <Task>(); foreach (string rutaArchivo in fileEntries) { var registrationDate = System.IO.File.GetLastWriteTime(rutaArchivo); var fileName = Path.GetFileName(rutaArchivo); using (var reader = File.OpenRead(rutaArchivo)) { var reportParams = new Dictionary <String, String>(); var factsList = new List <FactJBRL>(); DocumentoInstanciaXbrlDto documentoInstanciXbrlDto = xpeService.CargaInstanciaXBRLStreamFile(reader, fileName); if (documentoInstanciXbrlDto.Taxonomia == null) { JBRLUtils.ObtenerTaxonomia(documentoInstanciXbrlDto); } JBRLUtils.InsertFacts( documentoInstanciXbrlDto, reportParams, factsList, taskList, registrationDate, abaxXBRLCellStoreMongo); } System.GC.Collect(); } Task.WaitAll(taskList.ToArray()); }
public void ProcessFile( string rutaArchivo, string downloadId, string downloadPage, DateTime registrationDate) { try { XPEService xpeService = XPEServiceImpl.GetInstance(true); var fileName = Path.GetFileName(rutaArchivo); using (var reader = File.OpenRead(rutaArchivo)) { var reportParams = new Dictionary <String, String>(); reportParams["downloadId"] = downloadId; reportParams["downloadPage"] = downloadPage; var factsList = new List <FactJBRL>(); DocumentoInstanciaXbrlDto documentoInstanciXbrlDto = xpeService.CargaInstanciaXBRLStreamFile(reader, fileName); if (documentoInstanciXbrlDto.Taxonomia == null) { JBRLUtils.ObtenerTaxonomia(documentoInstanciXbrlDto); } JBRLUtils.InsertFacts( documentoInstanciXbrlDto, reportParams, factsList, taskList, registrationDate, abaxXBRLCellStoreMongo); } System.GC.Collect(); } catch (Exception ex) { LogUtil.Error(ex); } }
/// <summary> /// /// </summary> //[TestMethod] public void GetFactsByXBRL() { LogUtil.LogDirPath = @"..\..\TestOutput\"; LogUtil.Inicializa(); var outDirectoryPath = @"C:\CNBVDownloads\"; //var uri = @"file:///C:/2HSoftware/Notas/55_Documentaci%C3%B3nCNBV/02/02_Documentos/Respaldo/20181030/GetRSSWalmexAnual.xml"; var uri = @"file:///C:/2HSoftware/Notas/55_Documentaci%C3%B3nCNBV/02/02_Documentos/Respaldo/2018/20181030/GetRSS_erb_.xml"; var reader = XmlReader.Create(uri); var feed = SyndicationFeed.Load(reader); var regEntity = new Regex("^(.+?)\\s", RegexOptions.Compiled | RegexOptions.Multiline); reader.Close(); foreach (SyndicationItem item in feed.Items) { String subject = item.Title.Text; String summary = item.Summary.Text; if (item.Links.Count > 0) { var link = item.Links.First(); var linkUri = link.Uri.ToString(); var downloadUri = new Uri(linkUri); var cnbvId = item.Id; var documentName = item.Title.Text; var receptionDate = item.LastUpdatedTime.DateTime; var description = item.Summary.Text; var entity = String.Empty; var outPath = outDirectoryPath; if (regEntity.IsMatch(description)) { var match = regEntity.Match(description); if (match.Groups.Count > 1) { entity = match.Groups[1].Value; outPath = outPath + "\\" + entity + "\\"; Directory.CreateDirectory(outPath); } } var fileName = "id_" + cnbvId + "_" + documentName.Replace(".xbrl", String.Empty) + ".zip"; outPath = outPath + fileName; if (!File.Exists(outPath)) { try { using (WebClient webClient = new WebClient()) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; webClient.DownloadFile(linkUri, outPath); File.SetLastWriteTime(outPath, receptionDate); } } catch (Exception ex) { LogUtil.Error("Error al descargar el archivo: " + cnbvId); LogUtil.Error(ex); } } if ((description.Contains("mx_ics_entry_point") || description.Contains("ar_N_entry_point") || description.Contains("rel_news_issuer")) && !JBRLUtils.ExistsDownloadId(cnbvId, abaxXBRLCellStoreMongo)) { ProcessFile(outPath, cnbvId, downloadUri.Host, receptionDate); } } } Task.WaitAll(taskList.ToArray()); }