private void DownloadSECFiling(DownloadFiling msgDownload) { var secApi = new Fineo.SEC.Api.SECApi(); var submission = secApi.ArchivesEdgarDataCIKSubmission(msgDownload.CompanyCode, msgDownload.Filing); if (submission != null && submission.Files != null) { var filingDownloadedDto = new FilingDownloaded() { RegulatorCode = msgDownload.RegulatorCode, CompanyCode = msgDownload.CompanyCode, Filing = msgDownload.Filing }; var loopResult = Parallel.ForEach(submission.Files, f => { var subFile = secApi.ArchivesEdgarDataCIKSubmissionFile(msgDownload.CompanyCode, msgDownload.Filing, f.Name); if (subFile != null) { string blobPath = string.Format($"{msgDownload.RegulatorCode}\\{msgDownload.CompanyCode}\\{msgDownload.Filing}\\{subFile.Name}"); var newFile = new Fineo.Interfaces.FileInfo(); newFile.Path = blobPath; newFile.Content = subFile.Content.ToArray(); if (fileStorage.UploadAsync(newFile).Result) { filingDownloadedDto.Docs.Add(blobPath); } } }); var notificationDto = new MessageBusDto(); notificationDto.Body = JsonConvert.SerializeObject(filingDownloadedDto); notificationDto.MessageID = Guid.NewGuid().ToString(); msbOutNotification.Send(notificationDto); } }
private void ListenInQueue() { try { while (isRunning) { var msgBusDto = msbInFiles.ReadNext(); if (msgBusDto != null && !string.IsNullOrEmpty(msgBusDto.Body)) { DownloadFiling msgDownload = JsonConvert.DeserializeObject <DownloadFiling>(msgBusDto.Body); if (msgDownload != null && msgDownload.RegulatorCode == "SEC") { Task.Run(() => DownloadSECFiling(msgDownload)); } } } } catch (ThreadAbortException) { // Thread was aborted } }