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 override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
               ModuleName + "_default",
                ModuleName + "/{controller}/{action}",
                new { controller = "Admin", action = "Index" }
                , null
                , new[] { "AnimalFriends.Integration.Controllers", "AnimalFriends.Integration.Areas.Integration.Controllers", "Kooboo.Web.Mvc", "Kooboo.Web.Mvc.WebResourceLoader" }
            );

            var menuFile = AreaHelpers.CombineAreaFilePhysicalPath(AreaName, "Menu.config");
            if (File.Exists(menuFile))
            {
                Kooboo.Web.Mvc.Menu.MenuFactory.RegisterAreaMenu(AreaName, menuFile);
            }
            var resourceFile = Path.Combine(Settings.BaseDirectory, "Areas", AreaName, "WebResources.config");
            if (File.Exists(resourceFile))
            {
                Kooboo.Web.Mvc.WebResourceLoader.ConfigurationManager.RegisterSection(AreaName, resourceFile);
            }

            var importProcessService = new ImportProcessService();
            importProcessService.StartAllIntegrations();
        }
        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 ActionResult StopImport(string uuid)
        {
            var importProcessService = new ImportProcessService();
            var threads = importProcessService.GetThreads();
            if (threads[uuid] != null)
            {
                threads[uuid].Abort();
                var list = importProcessService.GetThreads();
                list.Remove(uuid);
                importProcessService.SetThreads(list);
            }

            importProcessService.SetProcess(new ImportProcessModel(uuid));
            return RedirectToAction("Index");
        }
        public ActionResult Import(string uuid)
        {
            var iomportProcessService = new ImportProcessService();
            var importSettingsService = new ImportSettingsService();
            iomportProcessService.StartImport(importSettingsService.Get(uuid));

            return RedirectToAction("Index");
        }
 public ActionResult GetProcessInfo(string uuid)
 {
     var importProcessService = new ImportProcessService();
     var model = importProcessService.GetProcess(uuid);
     return Json(model);
 }
 public ActionResult GetImportProcess(string uuid)
 {
     var importProcessService = new ImportProcessService();
     var model = importProcessService.GetProcess(uuid);
     return PartialView("_ImportProcess", model);
 }