public void Import(ImportSetting importSetting)
        {
            var stared = DateTime.Now;
            var importSettingsService = new ImportSettingsService();
            importSetting.SetLastStartedAt(DateTime.Now);
            var folder = importSetting.ContentTypeFolder;
            var textfolder = ServiceFactory.TextFolderManager.Get(Repository.Current, folder);
            var dataToImport = GetDataToImport(importSetting);
            var totalCountStart = dataToImport.Count;
            var elapsedCount = dataToImport.Count;
            var importProcessService = new ImportProcessService();
            foreach (var data in dataToImport)
            {
                var settingNow = importSettingsService.Get(importSetting.UUID);
                if (!settingNow.Enabled)
                    break;
                importProcessService.SetProcess(new ImportProcessModel(importSetting.UUID, elapsedCount, totalCountStart, true));
                IntegrationProgress.Send(new Progress { Uuid = importSetting.UUID, TotalCount = totalCountStart, ElapsedCount = elapsedCount, StartDate = stared.ToString("HH:mm:ss"), ElapsedTime = (DateTime.Now - stared).ToString(@"hh\:mm\:ss"), Active = true });
                ServiceFactory.TextContentManager.Add(Repository.Current, textfolder, data, null, null);
                elapsedCount--;
            }

            importProcessService.SetProcess(new ImportProcessModel(importSetting.UUID));
            IntegrationProgress.Send(new Progress { Uuid = importSetting.UUID, TotalCount = totalCountStart, ElapsedCount = elapsedCount, StartDate = stared.ToString("HH:mm:ss"), ElapsedTime = (DateTime.Now - stared).ToString(@"hh\:mm\:ss"), Active = false });

            // Remove the thread.
            importProcessService.GetThreads().Remove(importSetting.UUID);
        }
 public ActionResult AddMappedField(string uuid, MappedFieldModel mappedField)
 {
     var importSettingsService = new ImportSettingsService();
     var data = importSettingsService.AddMappedField(uuid, mappedField);
     ViewBag.UUID = uuid;
     return PartialView("_Connected", data);
 }
        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();
        }
 public IntegrationAdminController()
 {
     _dataService = new DataService();
     _importSettingsService = new ImportSettingsService();
 }
        public ActionResult Import(string uuid)
        {
            var iomportProcessService = new ImportProcessService();
            var importSettingsService = new ImportSettingsService();
            iomportProcessService.StartImport(importSettingsService.Get(uuid));

            return RedirectToAction("Index");
        }