public void MainThread()
        {
            // Every minute.
            Thread.Sleep(60000);

            // Loop all import tasks.
            var importSettingsService = new ImportSettingsService();
            var importProcessService = new ImportProcessService();
            var importSettings = importSettingsService.GetAll();

            foreach (var importSetting in importSettings)
            {
                if (importSetting.Enabled && !importSetting.IsRunning() &&
                    importSetting.LastStartedAt.AddMinutes(importSetting.RepeatIntervalInMinutes) < DateTime.Now)
                    importProcessService.StartImport(importSetting);
            }
            this.MainThread();
        }
        public void StartAllIntegrations()
        {
            var importSettingsService = new ImportSettingsService();
            var importProcessService = new ImportProcessService();
            var importSettings = importSettingsService.GetAll();

            foreach (var importSetting in importSettings)
            {
                if (importSetting.Enabled && importSetting.RunOnApplicationStartup)
                    importProcessService.StartImport(importSetting);
            }

            var importService = new ImportService();
            var mainIntegrationThread = new Thread(importService.MainThread);
            mainIntegrationThread.Start();
        }