private void Run() { var dbConnFact = new DbConnectionFactory(_config); using (var conn = dbConnFact.Get()) { Console.WriteLine($"Importing data:"); Console.WriteLine($" from: {NHSD.GPITF.BuyingCatalog.Settings.GIF_CRM_URL(_config)}"); Console.WriteLine($" into: {conn.ConnectionString}"); Console.WriteLine(); Console.WriteLine($"Retrieving data from CRM:"); #region NHSD data Console.WriteLine($" Frameworks..."); var frameworksSvc = new FrameworksService(_repo); var frameworks = frameworksSvc .GetAll() .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" Capabilities..."); var capsSvc = new CapabilitiesService(_repo); var caps = capsSvc .GetAll() .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" Standards..."); var stdsSvc = new StandardsService(_repo); var stds = stdsSvc .GetAll() .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" TODO CapabilityFramework..."); Console.WriteLine($" TODO FrameworkStandard..."); Console.WriteLine($" CapabilityStandard..."); var capsStdsSvc = new CapabilitiesStandardService(_repo); var capsStds = capsStdsSvc .GetAll() .Select(x => Converter.FromCrm(x)) .ToList(); #endregion #region Supplier data Console.WriteLine($" Organisations..."); var orgsSvc = new OrganisationsService(_repo); var orgs = orgsSvc .GetAll() .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" Contacts..."); var contactsSvc = new ContactsService(_repo); var contacts = orgs .SelectMany(org => contactsSvc.ByOrganisation(org.Id)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" Solutions..."); var solnsSvc = new SolutionsService(_repo); var solns = orgs .SelectMany(org => solnsSvc.ByOrganisation(org.Id)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" TechnicalContact..."); var techContSvc = new TechnicalContactService(_repo); var techConts = solns .SelectMany(soln => techContSvc.BySolution(soln.Id)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" TODO FrameworkSolution..."); Console.WriteLine($" ClaimedCapability..."); var claimedCapsSvc = new CapabilitiesImplementedService(_repo); var claimedCaps = solns .SelectMany(soln => claimedCapsSvc.BySolution(soln.Id)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" ClaimedStandard..."); var claimedStdsSvc = new StandardsApplicableService(_repo); var claimedStds = solns .SelectMany(soln => claimedStdsSvc.BySolution(soln.Id)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" ClaimedCapabilityEvidence..."); var claimedCapsEvSvc = new CapabilitiesImplementedEvidenceService(_repo); var claimedCapsEv = claimedCaps .SelectMany(claim => claimedCapsEvSvc.ByClaim(claim.Id).SelectMany(x => x)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" ClaimedStandardEvidence..."); var claimedStdsEvSvc = new StandardsApplicableEvidenceService(_repo); var claimedStdsEv = claimedStds .SelectMany(claim => claimedStdsEvSvc.ByClaim(claim.Id).SelectMany(x => x)) .Select(x => Converter.FromCrm(x)) .ToList(); Console.WriteLine($" ClaimedCapabilityReview..."); var claimedCapsRevSvc = new CapabilitiesImplementedReviewsService(_repo); var claimedCapsRev = claimedCapsEv .SelectMany(ev => claimedCapsRevSvc.ByEvidence(ev.Id).SelectMany(x => x)) .Select(x => Converter.CapabilitiesImplementedReviewsFromCrm(x)) .ToList(); Console.WriteLine($" ClaimedStandardReview..."); var claimedStdsRevSvc = new StandardsApplicableReviewsService(_repo); var claimedStdsRev = claimedStdsEv .SelectMany(ev => claimedStdsRevSvc.ByEvidence(ev.Id).SelectMany(x => x)) .Select(x => Converter.StandardsApplicableReviewsFromCrm(x)) .ToList(); #endregion Console.WriteLine(); Console.WriteLine($"Importing data into datastore..."); using (var trans = conn.BeginTransaction()) { // NHSD data conn.Insert(frameworks, trans); conn.Insert(caps, trans); conn.Insert(stds, trans); conn.Insert(capsStds, trans); // Supplier data conn.Insert(orgs, trans); conn.Insert(contacts, trans); conn.Insert(solns, trans); conn.Insert(techConts, trans); conn.Insert(claimedCaps, trans); conn.Insert(claimedStds, trans); conn.Insert(GetInsertionTree(claimedCapsEv), trans); conn.Insert(GetInsertionTree(claimedStdsEv), trans); conn.Insert(GetInsertionTree(claimedCapsRev), trans); conn.Insert(GetInsertionTree(claimedStdsRev), trans); trans.Commit(); } Console.WriteLine("Finished!"); } }