Exemplo n.º 1
0
        public void UpdateURLClicks(URLClick URLClicks)
        {
            var URLClicksToBeUpdated = _context.URLClicks.FirstOrDefault(u => u.Id == URLClicks.Id);

            URLClicksToBeUpdated.NumberOfClicks += 1;

            _context.SaveChanges();
        }
Exemplo n.º 2
0
        public IActionResult Scan(URLItem item)
        {
            // Get url from user
            string stringUrl = item.Url;
            bool   isUri     = Uri.IsWellFormedUriString(stringUrl, UriKind.RelativeOrAbsolute);

            if (!isUri)
            {
                return(BadRequest("URL is invalid"));
            }

            // Throw an error if there is no response for this URL
            if (!_scannerService.GetResponse(stringUrl))
            {
                throw new Exception("Something is wrong with file");
            }

            if (_scannerService.GetFileSize() > 209715200)
            {
                return(BadRequest("File size is too big, should be below 200 MB"));
            }

            // Write the response to the user
            item.Result = _virusScanService.GetVirusScanResult();
            item.Sha1   = _scannerService.GetCheckSum();

            _context.URLItems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetURL", new { id = item.Id, result = item.Result, sha1 = item.Sha1 }, item));
        }
Exemplo n.º 3
0
 public void RedirectTo()
 {
     try
     {
         string errorPath;
         Regex  regex = new Regex("^.*./");
         string shortUrl;
         errorPath = Request.Query.Keys.First();
         shortUrl  = regex.Replace(errorPath, "");
         string longUrl = _context.Link.Where(o => o.ShortUrl == shortUrl).Select(p => p.LongUrl).FirstOrDefault();
         _context.Link.Where(o => o.ShortUrl == shortUrl).FirstOrDefault().NumberOfTransitions++;
         _context.SaveChanges();
         Response.Redirect(longUrl, true);
     }
     catch
     {
         Response.Redirect("https://" + HttpContext.Request.Host, true);
     }
 }
Exemplo n.º 4
0
        public ScannerController(URLContext context, ScannerService scannerService, VirusScanService virusScanService)
        {
            // Initializing an in-memory database for saving requests and responses for measuring purposes
            _context          = context;
            _scannerService   = scannerService;
            _virusScanService = virusScanService;

            if (_context.URLItems.Count() == 0)
            {
                _context.URLItems.Add(new URLItem {
                    Url = "http://foobar.com"
                });
                _context.SaveChanges();
            }
        }