public async Task <HapiSettingsView> ReadHapi() { var result = new HapiSettingsView(); try { var response = await _restClient.Client.GetAsync("api/sync/hapi"); var data = await response.Content.ReadAsJsonAsync <HapiSettingsView>(); result = data; } catch (Exception e) { Log.Error($"error reading endpint [api/sync/hapi]"); Log.Error($"{e}"); } return(result); }
public async Task <IActionResult> ReadSetting() { try { var h = new HapiSettingsView(); h.Connection = _optionsb.Value.HapiConnection; h.Url = _options.Value.Iqcare; var dbOk = _dbManager.Verfiy(h.Connection); var urlOk = await _manager.VerfiyUrl(h.Url); h.IsVerifed = dbOk && urlOk; return(Ok(h)); } catch (Exception e) { var msg = $"Error loading Database setting"; Log.Error(msg); Log.Error($"{e}"); return(StatusCode(500, msg)); } }
static void Main(string[] args) { bool hapiOffline = true; var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); System.AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console() .WriteTo.RollingFile("logs/hapisync-{Date}.txt") .CreateLogger(); Log.Debug("initializing Sync v[1.0.1.0] ..."); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); IConfigurationRoot configuration = builder.Build(); var hapiendpoint = configuration["endpoints:hapi"]; _startup = new SyncStartup(hapiendpoint); Log.Debug($"connecting to LiveHAPI on [{hapiendpoint}]"); while (hapiOffline) { try { HapiSettingsView = _startup.LoadSettings().Result; if (null != HapiSettingsView) { Log.Debug($"LiveHAPI CONNECTED"); Log.Debug($"verifying LiveHAPI settings..."); if (HapiSettingsView.IsVerifed) { Log.Debug($"LiveHAPI settings [OK]"); Log.Debug($"starting sync..."); hapiOffline = false; } else { Log.Error($"invalid LiveHAPI settings ! please open {hapiendpoint} and verify and save all settings"); Log.Error($"Sync will retry in 30 secs..."); Thread.Sleep(30000); } } else { Log.Error($"LiveHAPI connection FAILED"); Log.Error($"Sync will retry in 30 secs..."); Thread.Sleep(30000); } } catch (Exception e) { Log.Fatal(new string('*', 50)); Log.Fatal(e, "Sync Requires LiveHAPI to be online!"); Log.Fatal(new string('*', 50)); } } var endpoint = HapiSettingsView.Url; //var endpoint = configuration["endpoints:iqcare"]; var connectionString = HapiSettingsView.Connection; //var connectionString = configuration.GetConnectionString("hAPIConnection"); var syncConfigInterval = configuration["syncInterval:config"]; var syncClientInterval = configuration["syncInterval:clients"]; var bulkConfigName = configuration["bulkConfig:name"]; var bulkConfigCode = configuration["bulkConfig:code"]; Log.Debug($"configured endpoint"); Log.Debug(new string('-', 40)); Log.Debug($" {endpoint}"); Log.Debug(new string('-', 40)); Log.Debug($"configured connection"); Log.Debug(new string('-', 40)); Log.Debug($" {connectionString}"); Log.Debug(new string('-', 40)); try { DapperPlusManager.AddLicense(bulkConfigName, bulkConfigCode); if (!Z.Dapper.Plus.DapperPlusManager.ValidateLicense(out var licenseErrorMessage)) { throw new Exception(licenseErrorMessage); } } catch (Exception e) { Log.Fatal($"{e}"); throw; } var allServices = new ServiceCollection() .AddTransient <IRestClient>(s => new RestClient(endpoint)) .AddDbContext <LiveHAPIContext>(o => o.UseSqlServer(connectionString)) .AddTransient <LiveHAPIContext>() .AddTransient <IUserRepository, UserRepository>() .AddTransient <IPracticeRepository, PracticeRepository>() .AddTransient <IPersonRepository, PersonRepository>() .AddTransient <ISubscriberTranslationRepository, SubscriberTranslationRepository>() .AddTransient <IClientRepository, ClientRepository>() .AddTransient <IClientRelationshipRepository, ClientRelationshipRepository>() .AddTransient <IClientStageRepository, ClientStageRepository>() .AddTransient <IClientStageRelationshipRepository, ClientStageRelationshipRepository>() .AddTransient <IClientPretestStageRepository, ClientPretestStageRepository>() .AddTransient <IContactsEncounterRepository, ContactsEncounterRepository>() .AddTransient <ISubscriberSystemRepository, SubscriberSystemRepository>() .AddTransient <IClientEncounterRepository, ClientEncounterRepository>() .AddTransient <IClientEncounterRepository, ClientEncounterRepository>() .AddTransient <IClientUserReader, ClientUserReader>() .AddTransient <IClientFacilityReader, ClientFacilityReader>() .AddTransient <IClientLookupReader, ClientLookupReader>() .AddTransient <IIndexClientMessageWriter, IndexClientMessageWriter>() .AddTransient <IFamilyClientMessageWriter, FamilyClientMessageWriter>() .AddTransient <IPartnerClientMessageWriter, PartnerClientMessageWriter>() .AddTransient <IFamilyWriter, FamilyWriter>() .AddTransient <IPartnerWriter, PartnerWriter>() .AddTransient <IDemographicsWriter, DemographicsWriter>() .AddTransient <IClientStageExtractor, ClientStageExtractor>() .AddTransient <IClientPretestStageExtractor, ClientPretestStageExtractor>() .AddTransient <IClientStageRelationshipExtractor, ClientStageRelationshipExtractor>() .AddTransient <IClientFamilyScreeningStageExtractor, ClientFamilyScreeningStageExtractor>() .AddTransient <IClientFamilyTracingStageExtractor, ClientFamilyTracingStageExtractor>() .AddTransient <IClientPartnerScreeningStageExtractor, ClientPartnerScreeningStageExtractor>() .AddTransient <IClientPartnerTracingStageExtractor, ClientPartnerTracingStageExtractor>() .AddTransient <IClientTracingStageExtractor, ClientTracingStageExtractor>() .AddTransient <IClientTestingStageExtractor, ClientTestingStageExtractor>() .AddTransient <IClientFinalTestStageExtractor, ClientFinalTestStageExtractor>() .AddTransient <IClientLinkageStageExtractor, ClientLinkageStageExtractor>() .AddTransient <IClientReferralStageExtractor, ClientReferralStageExtractor>() .AddTransient <IIndexClientMessageLoader, IndexClientMessageLoader>() .AddTransient <IFamilyClientMessageLoader, FamilyClientMessageLoader>() .AddTransient <IPartnerClientMessageLoader, PartnerClientMessageLoader>() .AddTransient <ISyncUserService, SyncUserService>() .AddTransient <ISyncFacilityService, SyncFacilityService>() .AddTransient <ISyncLookupService, SyncLookupService>() .AddTransient <ISyncUserService, SyncUserService>() .AddTransient <IExtractClientsService, ExtractClientsService>() .AddSingleton <ISyncConfigScheduler>(new SyncConfigScheduler(syncConfigInterval, syncClientInterval)); if (null != HapiSettingsView && HapiSettingsView.SyncVersion > 0) { allServices.AddTransient <ISyncClientsService, SyncClientsService>(); } else { allServices.AddTransient <ISyncClientsService, LegacySyncClientsService>(); Log.Error(new string('*', 50)); Log.Error(new string('*', 50)); Log.Error("YOU ARE USING AN OLD IQCARE PLEASE UPGRADE !!!"); Log.Error(new string('*', 50)); Log.Error(new string('*', 50)); } ServiceProvider = allServices.BuildServiceProvider(); Mapper.Initialize(cfg => { cfg.AddProfile <ClientProfile>(); }); Log.Debug("loading Sync..."); try { SyncConfigScheduler = ServiceProvider.GetService <ISyncConfigScheduler>(); SyncConfigScheduler.Run(); } catch (Exception e) { Log.Fatal(e, "Sync startup error"); } Console.ReadLine(); }