public async Task <IActionResult> AddScan(int id) { List <SourceSite> sites = await _context.Set <SourceSite>().AsNoTracking().TagWith("Creator Scan API") .Where(x => x.Creator.ID == id) .ToListAsync(); List <RecurringJobDto> recurringJobs = new List <RecurringJobDto>(); recurringJobs = JobStorage.Current.GetConnection().GetRecurringJobs().ToList(); //Default value string cronString = "0 0 * * 1"; if (recurringJobs.Any()) { cronString = CalculateNextCron(recurringJobs.OrderBy(j => j.CreatedAt).Last().Cron); } foreach (SourceSite site in sites) { if (recurringJobs.Any(j => j.Id == site.ID.ToString())) { continue; } _recurringJobManager.AddOrUpdate(site.ID.ToString(), () => _httpClient.GetAsync("http://miniindexprofileparser.azurewebsites.net/api/ProfileParser?code=" + _configuration["FunctionsCode"] + "&url=" + site.CreatorPageUri), cronString, null); cronString = CalculateNextCron(cronString); } return(Ok()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } FunctionsCode = _configuration["FunctionsCode"]; Creator = await _context .Set <Creator>() .AsNoTracking() .Include(x => x.Sites) .FirstOrDefaultAsync(m => m.ID == id); if (Creator == null) { return(NotFound()); } _telemetry.TrackEvent("ViewedCreator", new Dictionary <string, string> { { "CreatorId", Creator.ID.ToString() } }); AllCreatorsMinis = _context.Mini.AsNoTracking().TagWith("Creator Mini List") .Where(m => m.Creator.ID == Creator.ID) .Where(m => (m.Status != Status.Deleted && m.Status != Status.Rejected)) .OrderByDescending(m => m.ID).ToList(); return(Page()); }
public async Task <SearchSupportingInfo> Handle(GetSearchInfoRequest request, CancellationToken cancellationToken) { var tags = await _context.Set <Tag>() .ToListAsync(cancellationToken); return(new SearchSupportingInfo { Tags = tags }); }
public async Task OnGetAsync() { List <Creator> countQuery = await _context.Set <Mini>() .Include(m => m.Creator).ThenInclude(c => c.Sites) .Select(m => m.Creator) .ToListAsync(); CreatorCounts = countQuery .GroupBy(x => x) .OrderByDescending(x => x.Count()) .ToDictionary(k => k.Key, v => v.Count()); }
public async Task OnGetAsync() { if (User.IsInRole("Moderator")) { Creators = await _context.Set <Creator>().AsNoTracking().TagWith("Creator Admin List") .Include(c => c.Sites) .OrderBy(c => c.Name) .ToListAsync(); List <RecurringJobDto> recurringJobs = new List <RecurringJobDto>(); HangFireJobs = JobStorage.Current.GetConnection().GetRecurringJobs().ToList(); } }
private async Task CorrectMiniCreator(Mini mini, CancellationToken cancellationToken) { MiniSourceSite currentSource = mini.Sources.Single(); //Find a SourceSite that has both the same UserName and SiteName as the Mini's current SourceSite matchingSource = await _context.Set <SourceSite>().TagWith("MiniSubmissionHandler.cs 2") .Include(s => s.Creator).ThenInclude(c => c.Sites) .FirstOrDefaultAsync((s => s.CreatorUserName == currentSource.Site.CreatorUserName && s.SiteName == currentSource.Site.SiteName), cancellationToken); Creator foundCreator = matchingSource?.Creator; if (foundCreator != null) { _context.Remove(mini.Creator); mini.Creator = foundCreator; _context.Remove(currentSource.Site); currentSource.Site = matchingSource; return; } //If we didn't find a "perfect" match, try matching just off of the creator's names foundCreator = await _context.Set <Creator>().TagWith("MiniSubmissionHandler.cs 3") .Include(c => c.Sites) .FirstOrDefaultAsync(c => c.Name == mini.Creator.Name, cancellationToken); if (foundCreator != null) { mini.Creator = foundCreator; if (!foundCreator.Sites.Any(s => s.SiteName == currentSource.Site.SiteName)) { foundCreator.Sites.Add(currentSource.Site); } } }
public async Task <PaginatedList <Mini> > Handle(MiniSearchRequest request, CancellationToken cancellationToken) { /* * * Section 1: No filtering, most recently approved first, then IDs * */ IQueryable <Mini> search = _context .Set <Mini>() .Include(m => m.Creator) .OrderByDescending(m => m.ApprovedTime) .ThenByDescending(m => m.ID); /* * * Section 2: Basic filtering on creator and Free Only * */ if (request.Creator != null && request.Creator.ID > 0) { search = search.Where(m => m.Creator == request.Creator); } else { search = search.Where(m => (m.Status == Status.Approved || m.Status == Status.Pending)); } if (request.FreeOnly) { search = search.Where(m => m.Cost == 0); } //TODO: Move this section lower //TODO: Tag status needs to be approved lol /* * * Section 3: Only Minis with the given tag(s) * */ foreach (var tag in request.Tags) { search = search .Where(m => m.MiniTags .Where(x => x.Status == Status.Approved) .Select(x => x.Tag) .Any(t => t.TagName == tag) ); } /* * * Section 4: Analyze the search terms * */ //TODO: If SearchString can be deconstructed into tags, do it and then do a tag search (swap this section and the one above). /* * * Section 5: Text search * */ /* * * Section 6: Sort each result set * */ /* * * Section 7: Concat the two sets of results * */ if (!String.IsNullOrEmpty(request.SearchString)) { //TODO: Also include pairs of words here. string[] searchTerms = request.SearchString .Split(" ", StringSplitOptions.RemoveEmptyEntries) .Distinct() .Select(s => s.Trim().ToUpperInvariant()) .Where(s => !String.IsNullOrEmpty(s)) .ToArray(); IQueryable <Mini> tagSearch = search; //TODO: Move sort to end foreach (string term in searchTerms) { search = search .Where(m => m.Name.Contains(term)) .OrderByDescending(m => m.Name.ToUpper().Equals(term)) // match where the term *is* the model name .ThenByDescending(m => m.Name.ToUpper().StartsWith($"{term} ")) // \ .ThenByDescending(m => m.Name.ToUpper().Contains($" {term} ")) // -- these three lines do whole-word matching; there's a more concise way, but not if we want it to translate to SQL .ThenByDescending(m => m.Name.ToUpper().EndsWith($" {term}")) // / .ThenBy(m => m.Name.ToUpper().IndexOf(term)) // the earlier our term appears in the name, the more likely it is to be relevant (particularly with substring matches) .ThenByDescending(m => m.ApprovedTime) .ThenBy(m => m.Name); //Lots of people are trying to search only with one or two words that really should just be tag searches //If there's no tags passed, this try to do a tag search in addition to the text-based search if (request.Tags.Count() == 0) { tagSearch = tagSearch .Where(m => m.MiniTags .Where(x => x.Status == Status.Approved) .Select(x => x.Tag) .Any(t => t.TagName == term) ); } } if (request.Tags.Count() == 0) { search = tagSearch.Union(search); } } //TODO: Just hacking this in for now. We're double sorting... if (request.SortType == "newest") { search = search.OrderByDescending(m => m.ID); } return(await PaginatedList.CreateAsync(search, request.PageInfo)); }