public void Retrieve(string registryEntityType, int entityTypeId, int maxRecords, ref int recordsImported, ref List <string> importSummary, string sortOrder = "asc") { bool importingThisType = UtilityManager.GetAppKeyValue("importing_" + registryEntityType, true); if (!importingThisType) { LoggingHelper.DoTrace(1, string.Format("=== ***************** Skipping import of {0} ***************** ", registryEntityType)); importSummary.Add("Skipped import of " + registryEntityType); return; } LoggingHelper.DoTrace(1, string.Format("=== ***************** Importing {0} ***************** ", registryEntityType)); //bool downloadOnly // ReadEnvelope envelope = new ReadEnvelope(); List <ReadEnvelope> list = new List <ReadEnvelope>(); int pageNbr = 1; int pageSize = UtilityManager.GetAppKeyValue("importPageSize", 100); string importResults = ""; string importNote = ""; //ThisEntity output = new ThisEntity(); List <string> messages = new List <string>(); // var savingDocumentToFileSystem = UtilityManager.GetAppKeyValue("savingDocumentToFileSystem", true); var savingDocumentToDatabase = UtilityManager.GetAppKeyValue("savingDocumentToDatabase", false); int cntr = 0; int pTotalRows = 0; int exceptionCtr = 0; string statusMessage = ""; bool isComplete = false; //var request = new SearchRequest() //{ // StartingDate = startingDate, // EndingDate = endingDate, // OwningOrganizationCTID = owningOrganizationCTID, // PublishingOrganizationCTID = publishingOrganizationCTID, // DownloadOnly = downloadOnly //}; //will need to handle multiple calls - watch for time outs while (pageNbr > 0 && !isComplete) { //19-09-22 chg to use RegistryServices to remove duplicate services list = Search(registryEntityType, StartingDate, EndingDate, pageNbr, pageSize, ref pTotalRows, ref statusMessage, Community, OwningOrganizationCTID, PublishingOrganizationCTID, sortOrder); if (list == null || list.Count == 0) { isComplete = true; if (pageNbr == 1) { LoggingHelper.DoTrace(4, registryEntityType + ": No records where found for date range. "); } break; } if (pageNbr == 1) { LoggingHelper.DoTrace(2, string.Format("Import {0} Found {1} records to process.", registryEntityType, pTotalRows)); } foreach (ReadEnvelope item in list) { cntr++; string envelopeIdentifier = item.EnvelopeIdentifier; string ctid = item.EnvelopeCtid; string payload = item.DecodedResource.ToString(); DateTime createDate = new DateTime(); DateTime envelopeUpdateDate = new DateTime(); if (DateTime.TryParse(item.NodeHeaders.CreatedAt.Replace("UTC", "").Trim(), out createDate)) { //status.SetEnvelopeCreated( createDate ); } if (DateTime.TryParse(item.NodeHeaders.UpdatedAt.Replace("UTC", "").Trim(), out envelopeUpdateDate)) { //status.SetEnvelopeUpdated( envelopeUpdateDate ); } //payload contains the graph from DecodedResource //var ctdlType = RegistryServices.GetResourceType( payload ); LoggingHelper.DoTrace(2, string.Format("{0}. {1} ctid {2}, lastUpdated: {3} ", cntr, registryEntityType, ctid, envelopeUpdateDate)); //Save file to file system //existing files will be overridden. , suppress the date prefix (" "), or use an alternate prefix if (savingDocumentToFileSystem) { LoggingHelper.WriteLogFile(1, registryEntityType + "_" + ctid, payload, "", false); } #region future: define process to generic record to a database. //TODO - add optional save to a database // - will need entity type, ctid, name, description (maybe), created and lastupdated from envelope,payload // - only doing adds, allows for history, user can choose to do updates if (savingDocumentToDatabase) { var graphMainResource = RegistryServices.GetGraphMainResource(payload); var resource = new CredentialRegistryResource() { EntityType = graphMainResource.Type, CTID = ctid, DownloadDate = DateTime.Now, Created = createDate, LastUpdated = envelopeUpdateDate, CredentialRegistryGraph = payload }; if (entityTypeId == 10) { resource.Name = graphMainResource.CeasnName.ToString(); } else { resource.Name = graphMainResource.Name.ToString(); resource.Description = graphMainResource.Description.ToString(); resource.SubjectWebpage = graphMainResource.SubjectWebpage; } statusMessage = ""; //optionally save record to a database if (new DatabaseServices().Add(resource, ref statusMessage) == 0) { //error handling } } #endregion if (maxRecords > 0 && cntr >= maxRecords) { break; } } //end foreach pageNbr++; if ((maxRecords > 0 && cntr >= maxRecords)) { isComplete = true; LoggingHelper.DoTrace(2, string.Format("Import {2} EARLY EXIT. Completed {0} records out of a total of {1} for {2} ", cntr, pTotalRows, registryEntityType)); } else if (cntr >= pTotalRows) { isComplete = true; } } importResults = string.Format("Import {0} - Processed {1} records, with {2} exceptions. \r\n", registryEntityType, cntr, exceptionCtr); LoggingHelper.DoTrace(2, importResults); if (!string.IsNullOrWhiteSpace(importNote)) { importResults += importNote; } importSummary.Add(importResults); recordsImported += cntr; //return importResults; }