public AppMain() { InitializeComponent(); lstOutputType.SelectedItem = "JSON Export"; //load settings this.txtDataFolderPath.Text = Settings.Default.Import_DataFolder; this.txtGeonamesAPIUserID.Text = Settings.Default.Geonames_API_Username; this.txtAPIIdentifier.Text = Settings.Default.OCM_API_Identitifer; this.txtAPISessionToken.Text = Settings.Default.OCM_API_SessionToken; this.txtAPIKey_Coulomb.Text = Settings.Default.APIKey_Coulomb; this.txtAPIPwd_Coulomb.Text = Settings.Default.APIPwd_Coulomb; this.txtImportJSONPath.Text = ConfigurationManager.AppSettings["ImportBasePath"]; var settings = new ImportSettings { GeolocationShapefilePath = ConfigurationManager.AppSettings["GeolocationShapefilePath"], ImportUserAPIKey = ConfigurationManager.AppSettings["APIKey"], MasterAPIBaseUrl = ConfigurationManager.AppSettings["APIBaseUrl"], TempFolderPath = ConfigurationManager.AppSettings["ImportBasePath"] }; _importManager = new ImportManager(settings); //populate provider list _providers = new List <IImportProvider>(); _providers = _importManager.GetImportProviders(new List <DataProvider>()); lstProvider.DataSource = _providers.ToArray().Select(s => s.GetProviderName()).ToList(); }
public AppMain() { InitializeComponent(); lstOutputType.SelectedItem = "JSON Export"; //load settings this.txtDataFolderPath.Text = Settings.Default.Import_DataFolder; this.txtGeonamesAPIUserID.Text = Settings.Default.Geonames_API_Username; this.txtAPIIdentifier.Text = Settings.Default.OCM_API_Identitifer; this.txtAPISessionToken.Text = Settings.Default.OCM_API_SessionToken; this.txtAPIKey_Coulomb.Text = Settings.Default.APIKey_Coulomb; this.txtAPIPwd_Coulomb.Text = Settings.Default.APIPwd_Coulomb; this.txtImportJSONPath.Text = System.Configuration.ConfigurationManager.AppSettings["ImportBasePath"]; var settings = new ImportSettings { GeolocationShapefilePath = System.Configuration.ConfigurationManager.AppSettings["GeolocationShapefilePath"], ImportUserAPIKey = System.Configuration.ConfigurationManager.AppSettings["APIKey"], MasterAPIBaseUrl = System.Configuration.ConfigurationManager.AppSettings["APIBaseUrl"], TempFolderPath = System.Configuration.ConfigurationManager.AppSettings["ImportBasePath"] }; var configPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var config = new ConfigurationBuilder() .SetBasePath(configPath) .AddJsonFile("appsettings.json", optional: true) .Build(); var appsettings = new OCM.Core.Settings.CoreSettings(); config.GetSection("ImportSettings").Bind(appsettings); _importManager = new ImportManager(settings); //populate provider list _providers = new List <IImportProvider>(); _providers = _importManager.GetImportProviders(new List <DataProvider>()); lstProvider.DataSource = _providers.ToArray().Select(s => s.GetProviderName()).ToList(); }
private async void PerformTasks(object?state) { if (!_isImportInProgress) { _isImportInProgress = true; _logger.LogInformation("Checking import status.."); var tempPath = Path.GetTempPath(); var importManager = new ImportManager(_settings, _logger); try { var status = new ImportStatus { DateLastImport = DateTime.UtcNow, LastImportedProvider = "", LastImportStatus = "Started" }; var statusPath = Path.Combine(tempPath, "import_status.json"); if (File.Exists(statusPath)) { status = System.Text.Json.JsonSerializer.Deserialize <ImportStatus>(File.ReadAllText(statusPath)); } var allProviders = _settings.EnabledImports; var indexOfLastProvider = allProviders.IndexOf(status.LastImportedProvider ?? ""); var indexOfNextProvider = 0; // if there is a next provider use that, otherwise use first provider if (indexOfLastProvider > -1) { if (indexOfLastProvider < allProviders.Count - 1) { // next provider indexOfNextProvider = indexOfLastProvider + 1; } } status.LastImportedProvider = allProviders[indexOfNextProvider]; status.DateLastImport = DateTime.UtcNow; _logger.LogInformation($"Performing Import [{status.LastImportedProvider}], Publishing via API: {status.DateLastImport.Value.ToShortTimeString()}"); try { var stopwatch = Stopwatch.StartNew(); var importedOK = await importManager.PerformImportProcessing( new ImportProcessSettings { ExportType = Providers.ExportType.JSONAPI, DefaultDataPath = tempPath, FetchLiveData = true, FetchExistingFromAPI = true, PerformDeduplication = true, ProviderName = status.LastImportedProvider // leave blank to do all }); //TODO: notify API of last date of import for each provider status.LastImportStatus = importedOK ? "Imported" : "Failed"; status.DateLastImport = DateTime.UtcNow; status.ProcessingTimeSeconds = stopwatch.Elapsed.TotalSeconds; // update import date on provider var providers = importManager.GetImportProviders(new List <API.Common.Model.DataProvider>()); var providerId = (providers.FirstOrDefault(p => p.GetProviderName() == status.LastImportedProvider) as BaseImportProvider)?.DataProviderID; if (providerId != null) { await importManager.UpdateLastImportDate((int)providerId); } } catch (Exception exp) { _logger.LogError("Import failed: " + exp); status.LastImportStatus = "Failed with unknown exception"; } File.WriteAllText(statusPath, System.Text.Json.JsonSerializer.Serialize <ImportStatus>(status)); } catch (Exception exp) { _logger.LogError("Import failed: " + exp.ToString()); } _isImportInProgress = false; } else { _logger.LogInformation("Import already in progress.."); } }