Exemplo n.º 1
0
        public bool AddSiteUpdate(string headline, string importance)
        {
            using (var db = new BloggingContext())
            {
                try
                {
                    var user = (from u in db.Users
                        where u.Username == this.User.Identity.Name
                        select u)
                        .FirstOrDefault();
                    ;

                    var update = new SiteUpdate()
                    {
                        User = user,
                        Headline = headline,
                        Importance = importance,
                        Timestamp = DateTime.Now
                    };

                    db.SiteUpdates.Add(update);
                    db.SaveChanges();
                }
                catch
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 2
0
        private IEnumerable <string> ExtractResourcePathsFromPage(SiteUpdate index)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(Encoding.UTF8.GetString(index.Data));

            return(doc.DocumentNode.SelectNodes("//script/@src | //link[@rel='stylesheet']/@href")
                   .Select(node => node.GetAttributeValue("src", null) ?? node.GetAttributeValue("href", null))
                   .Where(s => s != null)
                   // Exclude google ads and stuff, only local/relative paths
                   .Where(s => s.StartsWith("/"))
                   .ToArray());
        }
Exemplo n.º 3
0
        private IEnumerable <Uri> ExtractResourcePathsFromPage(SiteUpdate index)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(Encoding.UTF8.GetString(index.Data));

            return(doc.DocumentNode.SelectNodes("//script/@src | //link[@rel='stylesheet']/@href")
                   .Select(node => node.GetAttributeValue("src", null) ?? node.GetAttributeValue("href", null))
                   .Where(s => s != null)
                   .Where(s => AllowedPrefixes.Any(s.StartsWith))
                   .Select(ParseRelativeUri)
                   .ToArray());
        }
Exemplo n.º 4
0
        private async Task <SiteUpdate> FetchResource(string path)
        {
            var response = await _client.GetAsync(new Uri(new Uri("https://www.blaseball.com/"), path));

            if (!response.IsSuccessStatusCode)
            {
                _logger.Warning("Got {StatusCode} response from {Path}, returning null", response.StatusCode, path);
                return(null);
            }

            var bytes = await response.Content.ReadAsByteArrayAsync();

            var lastModifiedDto = response.Content.Headers.LastModified;
            var lastModified    = lastModifiedDto != null
                ? Instant.FromDateTimeOffset(lastModifiedDto.Value)
                : (Instant?)null;

            var update = SiteUpdate.From(_sourceId, path, _clock.GetCurrentInstant(), bytes, lastModified);

            _logger.Information("- Fetched resource {Path} (hash {Hash})", path, update.Hash);
            return(update);
        }
Exemplo n.º 5
0
        public async Task UpdateSiteIsChanged(SiteUpdate updateInfo)
        {
            JObject root = await _jsonWatcher.JsonChanged;

            root.Property(SITES).Values();
        }