public async Task <IActionResult> Index() { ViewData["Agent"] = await _dbContext.Set <DownloaderAgent>().CountAsync(); ViewData["OnlineAgent"] = await _dbContext.Set <DownloaderAgent>().CountAsync(x => x.IsActive()); ViewData["Repository"] = await _dbContext.DockerRepositories.CountAsync(); ViewData["Spider"] = await _dbContext.Spiders.CountAsync(); ViewData["RunningSpider"] = await _dbContext.Set <SpiderStatistics>() .CountAsync(x => (DateTime.Now - x.LastModificationTime).TotalSeconds < 60); return(View()); }
public async Task <IActionResult> Index() { ViewData["Agent"] = await _dbContext.Set <AgentInfo>().CountAsync(); var activeTime = DateTimeOffset.Now.AddSeconds(-60); ViewData["OnlineAgent"] = await(_dbContext.Set <AgentInfo>().CountAsync(x => x.LastModificationTime > activeTime)); ViewData["Spider"] = await _dbContext.Spiders.CountAsync(); ViewData["RunningSpider"] = await _dbContext.Set <SpiderStatistics>() .CountAsync(x => x.LastModificationTime > activeTime); return(View()); }
public async Task <IActionResult> Retrieve() { try { var agents = await _dbContext.Set <DownloaderAgent>().ToListAsync(); return(View(agents)); } catch (Exception e) { if (e.Message.Contains("doesn't exist")) { _logger.LogInformation("下载中心尚未启动"); return(View()); } throw; } }
public async Task <PagedResult <ListSpiderViewObject> > PagedQueryAsync(string keyword, int page, int limit) { PagedResult <Data.Spider> @out; if (!string.IsNullOrWhiteSpace(keyword)) { @out = await _dbContext .Set <Data.Spider>() .PagedQueryAsync(page, limit, x => x.Name.Contains(keyword), new OrderCondition <Data.Spider, DateTimeOffset>(x => x.LastModificationTime)); } else { @out = await _dbContext .Set <Data.Spider>() .PagedQueryAsync(page, limit, null, new OrderCondition <Data.Spider, DateTimeOffset>(x => x.LastModificationTime)); } return(_mapper.ToPagedQueryResult <Data.Spider, ListSpiderViewObject>(@out)); }
public async Task <PagedResult <AgentViewObject> > PagedQueryAsync(string keyword, int page, int limit) { PagedResult <AgentInfo> @out; if (!string.IsNullOrWhiteSpace(keyword)) { @out = await _dbContext .Set <AgentInfo>() .PagedQueryAsync(page, limit, x => x.Name.Contains(keyword) || x.Id.Contains(keyword), new OrderCondition <AgentInfo, DateTimeOffset>(x => x.CreationTime)); } else { @out = await _dbContext .Set <AgentInfo>() .PagedQueryAsync(page, limit, null, new OrderCondition <AgentInfo, DateTimeOffset>(x => x.CreationTime)); } return(_mapper.ToPagedQueryResult <AgentInfo, AgentViewObject>(@out)); }
public void Create() { var catalogs = _context.Set <BookCatalog>(); var programming = new BookCatalog { Name = "Programming", Order = 1, Childrens = new List <BookCatalog> { new BookCatalog { Name = ".NET", Order = 1 }, new BookCatalog { Name = "Python", Order = 3 }, new BookCatalog { Name = "JavaScript", Order = 2 } } }; var webDesign = new BookCatalog { Name = "Web Design", Order = 2, Childrens = new List <BookCatalog> { new BookCatalog { Name = "HTML", Order = 1 }, new BookCatalog { Name = "CSS", Order = 2 } } }; var other = new BookCatalog { Name = "Other", Order = 3 }; catalogs.AddOrUpdate(x => x.Name, programming, webDesign, other); _context.SaveChanges(); }
public async Task <IActionResult> Retrieve(int id, int page, int size) { page = page <= 1 ? 1 : page; size = size <= 20 ? 20 : size; var containers = await _dbContext.SpiderContainers.Where(x => x.SpiderId == id) .OrderByDescending(x => x.Id) .ToPagedListAsync(page, size); var batches = await containers.Select(x => x.Batch).ToListAsync(); var dict = await _dbContext.Set <SpiderStatistics>().Where(x => batches.Contains(x.OwnerId)) .ToDictionaryAsync(x => x.OwnerId, x => x); var list = new List <ListSpiderContainerViewModel>(); foreach (var container in containers) { var item = new ListSpiderContainerViewModel { Batch = container.Batch, ContainerId = container.ContainerId, SpiderId = container.SpiderId, Status = container.Status, CreationTime = container.CreationTime }; if (dict.ContainsKey(item.Batch)) { item.Total = dict[item.Batch].Total; item.Failed = dict[item.Batch].Failed; item.Success = dict[item.Batch].Success; item.Start = dict[item.Batch].Start; item.Exit = dict[item.Batch].Exit; item.Left = item.Total - item.Success; } list.Add(item); } return(View(new StaticPagedList <ListSpiderContainerViewModel>(list, page, size, containers.GetMetaData().TotalItemCount))); }
public void Create() { #region Authors var authors = _context.Set <Author>(); var author1 = new Author { Name = "AuthorName#1" }; var author2 = new Author { Name = "AuthorName#2" }; var author3 = new Author { Name = "AuthorName#3" }; authors.AddOrUpdate(x => x.Name, author1, author2, author3); #endregion #region Tags var tags = _context.Set <Tag>(); var tag1 = new Tag { Name = "TagName#1" }; var tag2 = new Tag { Name = "TagName#2" }; var tag3 = new Tag { Name = "TagName#3" }; var tag4 = new Tag { Name = "TagName#4" }; tags.AddOrUpdate(x => x.Name, tag1, tag2, tag3, tag4); #endregion #region Language var languages = _context.Set <Language>(); var language = new Language { Name = "LanguageName" }; languages.AddOrUpdate(x => x.Name, language); #endregion #region Publisher var publishers = _context.Set <Publisher>(); var publisher = new Publisher { Name = "PublisherName" }; publishers.AddOrUpdate(x => x.Name, publisher); #endregion #region Issue var issues = _context.Set <Issue>(); var issue = new Issue { Name = "IssueName" }; issues.AddOrUpdate(x => x.Name, issue); #endregion AddBooks( catalogName: ".NET", size: 15, authors: new List <Author> { author1, author3 }, tags: new List <Tag>(), language: null, publisher: publisher, issue: issue ); AddBooks( catalogName: "Python", size: 5, authors: new List <Author>(), tags: new List <Tag> { tag1, tag4 }, language: language, publisher: null, issue: issue ); AddBooks( catalogName: "HTML", size: 12, authors: new List <Author> { author2, author1 }, tags: new List <Tag> { tag3, tag2, tag1 }, language: language, publisher: publisher, issue: null ); AddBooks( catalogName: "Other", size: 2, authors: new List <Author> { author3 }, tags: new List <Tag> { tag3, tag2, tag1, tag4 }, language: language, publisher: publisher, issue: issue ); _context.SaveChanges(); }
public ICollection <TObject> GetAll() { return(DbContext.Set <TObject>().ToList()); }
/// <summary> /// Gets all records from a entity /// </summary> /// <returns>IQuerable</returns> public IQueryable <TEntity> GetAll <TEntity>() where TEntity : class { DbSet <TEntity> dbSet = _context.Set <TEntity>(); return(dbSet.AsQueryable()); }