コード例 #1
0
        public async Task <ActionResult> DeleteById(int id)
        {
            _parsedRepository.DeleteById(id);

            //Notify client to update history
            await _socketManager.SendMessageToAllAsync(string.Format("{{event: Deleted, id: {0} }}", id));

            return(Ok());
        }
コード例 #2
0
        public async Task <ActionResult> ParsePage(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(BadRequest("Invalid Argument Exception. Please, provide a link in the query string"));
            }

            ResponseHttp responseHttp;
            Uri          uri = new UriBuilder(url).Uri;

            try
            {
                responseHttp = await _httpRequest.SendAsync(uri);
            }
            catch (HttpRequestException ex)
            {
                return(BadRequest("The site cannot be reached"));
            }
            SiteDetails parsingResult;

            try
            {
                parsingResult = _parser.ParseHTML(responseHttp.Body);
            }
            catch (Exception ex)
            {
                return(BadRequest("Error was occurred when the site was parsed"));
            }

            ParsedSiteDTO result = new ParsedSiteDTO
            {
                Uri         = uri.AbsoluteUri,
                Title       = parsingResult.Title,
                Description = parsingResult.Description,
                HeadersH1   = parsingResult.HeadersH1,
                Images      = parsingResult.Images.imageLinksToAbsoluteLinks(responseHttp.ResponseUri),
                Links       = parsingResult.Links.RelativeToAbsoluteLinks(responseHttp.ResponseUri),

                ResponseTime   = responseHttp.TimeToFirstByte,
                ServerResponse = new ServerResponseDTO
                {
                    Code        = (int)responseHttp.Status.Code,
                    Description = responseHttp.Status.Description
                }
            };

            _parsedRepository.Add(result);
            //Notify client to update history
            await _socketManager.SendMessageToAllAsync(string.Format("{{event: ItemAdded, id: {0} }}", result.Id));

            return(Ok(result));
        }