Exemple #1
0
        public async Task <bool> CreateAsync(SpiderDto viewModel)
        {
            if (ModelState.IsValid)
            {
                var exists = await _dockerCrawlerService.CountAsync <SpiderDto>(x =>
                                                                                x.Name == viewModel.Name);

                if (exists > 0)
                {
                    ModelState.AddModelError("Name", "名称已经存在");
                }

                try
                {
                    CrontabSchedule.Parse(viewModel.Cron);
                }
                catch
                {
                    ModelState.AddModelError("Cron", "Cron 表达式不正确");
                }

                viewModel.CreationTime         = DateTimeOffset.Now;
                viewModel.LastModificationTime = DateTimeOffset.Now;
                viewModel = await _dockerCrawlerService.AddAsync(viewModel);


                var id = viewModel.Id;

                return(true);
            }
            else
            {
                throw new ApplicationException("ModelState is invalid");
            }
        }
Exemple #2
0
        public async Task <IActionResult> Index()
        {
            //ViewData["Agent"] = await _dbContext.Set<DownloaderAgent>().CountAsync();
            //ViewData["OnlineAgent"] = await _dbContext.Set<DownloaderAgent>().CountAsync();

            ViewData["Spider"] = await _dockerCrawlerService.CountAsync <SpiderDto>();

            ViewData["RunningSpider"] = await _dockerCrawlerService.CountRunningContainers();

            return(View());
        }