Ejemplo n.º 1
0
        public async Task <IActionResult> Redirect(int id)
        {
            Mini mini = await _context.Mini.AsNoTracking().TagWith("Minis API Redirect")
                        .Include(m => m.Sources)
                        .Include(m => m.Creator)
                        .FirstOrDefaultAsync(m => m.ID == id);

            if (mini == null)
            {
                return(NotFound());
            }

            MiniSourceSite Source = mini.Sources.FirstOrDefault();

            if (Source != null)
            {
                _telemetry.TrackEvent("MiniRedirect", new Dictionary <string, string> {
                    { "TargetHost", Source.Link.Host },
                    { "MiniID", id.ToString() },
                    { "CreatorID", mini.Creator.ID.ToString() }
                });

                return(Redirect(Source.Link.ToString()));
            }
            else
            {
                _telemetry.TrackEvent("MiniRedirect", new Dictionary <string, string> {
                    { "TargetHost", new Uri(mini.Link).Host },
                    { "MiniID", id.ToString() },
                    { "CreatorID", mini.Creator.ID.ToString() }
                });

                return(Redirect(mini.Link.ToString()));
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }