Beispiel #1
0
 public ApiController([NotNull] SqlServerBenchmarkRepository benchmarkRepository,
                      [NotNull] ILoggerFactory loggerFactory, SitemapGenerator sitemapGenerator)
 {
     this.m_benchmarkRepository = benchmarkRepository;
     this.m_logger         = loggerFactory.CreateLogger <ApiController>();
     this.sitemapGenerator = sitemapGenerator;
 }
Beispiel #2
0
        private static async Task GenerateSitemap()
        {
            var config = new Config();
            var client = new VocaDbClient(config.SiteRootUrl);

            s_log.Info("Getting entries from VocaDB");

            var artists = await client.GetArtists();

            var albums = await client.GetAlbums();

            var events = await client.GetEvents();

            var songs = await client.GetSongs();

            var tags = await client.GetTags();

            s_log.Info("Generating sitemap");

            var generator = new SitemapGenerator(config.SiteRootUrl, config.SitemapRootUrl);

            generator.Generate(config.OutFolder, new Dictionary <EntryType, IEnumerable <EntryReference> > {
                { EntryType.Artist, artists.Select(e => new EntryReference(e)) },
                { EntryType.Album, albums.Select(e => new EntryReference(e)) },
                { EntryType.ReleaseEvent, events.Items.Select(e => new EntryReference(e.Id, e.UrlSlug)) },
                { EntryType.Song, songs.Select(e => new EntryReference(e)) },
                { EntryType.Tag, tags.Items.Select(e => new EntryReference(e.Id, e.UrlSlug)) },
            });
        }
Beispiel #3
0
        public void ProcessRequest(HttpContext context)
        {
            var sitemap = new SitemapGenerator();

            context.Response.ContentType = "Text/xml";
            context.Response.Write(sitemap.getSitemap());
        }
Beispiel #4
0
        private static async Task GenerateSitemap()
        {
            var config = new Config();
            var client = new VocaDbClient(config.SiteRootUrl);

            log.Info("Getting entries from VocaDB");

            var artists = await client.GetArtists();

            var albums = await client.GetAlbums();

            var songs = await client.GetSongs();

            var tags = await client.GetTags();

            log.Info("Generating sitemap");

            var generator = new SitemapGenerator(config.SiteRootUrl, config.SitemapRootUrl);

            generator.Generate(config.OutFolder, new Dictionary <EntryType, IEnumerable <object> > {
                { EntryType.Artist, artists.Cast <object>() },
                { EntryType.Album, albums.Cast <object>() },
                { EntryType.Song, songs.Cast <object>() },
                { EntryType.Tag, tags },
            });
        }
Beispiel #5
0
        /// <summary>
        /// Returns a sitemap.xml document string for the supplied site.
        /// </summary>
        /// <param name="site">The site to crawl.</param>
        /// <param name="forceRegenerate">Whether the document can be retrieved from cache, or whether a fresh document should be generated.</param>
        /// <returns>An XML string representing sitemap.xml document.</returns>
        public static string GetSitemap(SiteContext site, bool forceRegenerate = false)
        {
            var    key    = typeof(SitemapRepository).FullName + site.Name;
            var    cache  = Sitecore.Caching.CacheManager.GetHtmlCache(site);
            string output = null;

            if (cache != null)
            {
                output = cache.GetHtml(key);
            }

            if (SitemapXmlConfiguration.Current.CacheEnabled && cache != null)
            {
                output = cache.GetHtml(key);
            }

            if (forceRegenerate || !SitemapXmlConfiguration.Current.CacheEnabled || output == null)
            {
                var generator = new SitemapGenerator(site.SiteInfo);

                XmlDocument document = generator.Generate();
                output = document.OuterXml;


                if (SitemapXmlConfiguration.Current.CacheEnabled && cache != null)
                {
                    cache.SetHtml(key, output);
                }
            }

            return(output);
        }
Beispiel #6
0
        /// <summary>
        /// Returns a sitemap.xml XmlDocument for the supplied site.
        /// </summary>
        /// <param name="site">The site to crawl.</param>
        /// <param name="forceRegenerate">Whether the document can be retrieved from cache, or whether a fresh document should be generated.</param>
        /// <returns>An XML document representing the supplied site's crawl-able links</returns>
        public static XmlDocument GetSitemap(SiteInfo site, bool forceRegenerate = false)
        {
            var key = typeof(SitemapRepository).FullName + site.Name;

            XmlDocument document = null;

            if (SitemapXmlConfiguration.Current.CacheEnabled)
            {
                document = CachingContext.Current.Get <XmlDocument>(key);
            }

            if (document == null || forceRegenerate)
            {
                var generator = new SitemapGenerator(site);

                document = generator.Generate();

                if (SitemapXmlConfiguration.Current.CacheEnabled)
                {
                    var cacheTimeout = site.GetSitemapXmlCacheTimeout();
                    CachingContext.Current.Add(key, document, DateTime.Now.AddMinutes(cacheTimeout));
                }
            }

            return(document);
        }
        /// <summary>
        /// Required by IHttpHandler, this is called by ASP.NET when an appropriate URL match is found.
        /// </summary>
        /// <param name="context">The current request context.</param>
        public void ProcessRequest(HttpContext context)
        {
            var doc = SitemapGenerator.Generate(context.Request);

            context.Response.Clear();
            context.Response.ContentType = "text/xml";
            doc.Save(context.Response.OutputStream);
            context.Response.End();
        }
Beispiel #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType     = "text/xml";
            Response.ContentEncoding = new UTF8Encoding();

            SitemapGenerator sitemapGenerator = new SitemapGenerator();
            string           siteMap          = sitemapGenerator.Generate();

            Response.Write(siteMap);
            Response.End();
        }
        public XDocument GetSitemapXML(string siteDomain, Sitemap model)
        {
            var posts      = context.Content.Where(c => c.Type.ToLower() == "post" && c.IsDeleted == false && c.isPublished == true).ToList();
            var pages      = context.Content.Where(c => c.Type.ToLower() == "page" && c.IsDeleted == false && c.isPublished == true).ToList();
            var categories = context.Category.Where(c => c.IsDeleted == false).ToList();
            var tags       = context.Label.Where(c => c.IsDeleted == false).ToList();

            var items   = new List <SitemapItem>();
            var homeTag = new SitemapItem(siteDomain + "home/index", DateTime.UtcNow, NITASA.Areas.Admin.Helper.Sitemap.SitemapChangeFrequency.Daily, 1.0);

            items.Add(homeTag);

            foreach (var post in posts)
            {
                items.Add(new SitemapItem(
                              (siteDomain + "content/" + post.URL),
                              (post.ModifiedOn.HasValue ? post.ModifiedOn.Value : (DateTime?)null),
                              (model.postFreqency.HasValue ? model.postFreqency.Value : SitemapChangeFrequency.Never),
                              (model.postPriority.HasValue?model.postPriority.Value:1)));
            }

            foreach (var page in pages)
            {
                items.Add(new SitemapItem(
                              (siteDomain + "content/" + page.URL),
                              (page.ModifiedOn.HasValue ? page.ModifiedOn.Value : (DateTime?)null),
                              (model.postFreqency.HasValue ? model.postFreqency.Value : SitemapChangeFrequency.Monthly),
                              (model.postPriority.HasValue ? model.postPriority.Value : 1)));
            }

            foreach (var cat in categories)
            {
                items.Add(new SitemapItem(
                              (siteDomain + "category/" + cat.Slug),
                              (cat.ModifiedOn.HasValue ? cat.ModifiedOn.Value : (DateTime?)null),
                              (model.postFreqency.HasValue ? model.postFreqency.Value : SitemapChangeFrequency.Monthly),
                              (model.postPriority.HasValue ? model.postPriority.Value : 1)));
            }

            foreach (var tag in tags)
            {
                items.Add(new SitemapItem(
                              (siteDomain + "label/" + tag.Slug),
                              (tag.ModifiedOn.HasValue ? tag.ModifiedOn.Value : (DateTime?)null),
                              (model.postFreqency.HasValue ? model.postFreqency.Value : SitemapChangeFrequency.Monthly),
                              (model.postPriority.HasValue ? model.postPriority.Value : 1)));
            }

            SitemapGenerator generator = new SitemapGenerator();
            var file = generator.GenerateSiteMap(items);

            return(file);
        }
        public ActionResult GetSiteMap()
        {
            using (var dataBase = new ApplicationDbContext())
            {
                var notDeletedMessages = dataBase.Messages
                                         .Where(message => !message.IsDeleted)
                                         .OrderByDescending(message => message.Date)
                                         .ToList();

                var    sitemapGenerator = new SitemapGenerator(notDeletedMessages);
                var    sitemapNodes     = sitemapGenerator.GetSitemapNodes(this.Url);
                string xml = sitemapGenerator.GetSitemapDocument(sitemapNodes);
                return(this.Content(xml, "text/xml", Encoding.UTF8));
            }
        }
        public async void TestSitemapGenerator()
        {
            // Invoke the lambda function and confirm the string was upper cased.
            var function   = new SitemapGenerator();
            var context    = new TestLambdaContext();
            var parameters = new Parameters
            {
                Table  = "test-table",
                Host   = "host.com",
                Scheme = "https"
            };

            //var output = await function.SitemapGeneratorHandler(parameters, context);

            Assert.Equal(parameters, parameters);
        }
Beispiel #12
0
 /// <summary>
 /// Generates an XML site map.
 /// </summary>
 /// <param name="siteContent">The site content with pre-rendered HTML.</param>
 /// <param name="outputPath">The local output path to write the site map.</param>
 /// <param name="baseUrl">The base Url to use in generating the site map.</param>
 /// <returns></returns>
 private static string MapSite(SiteContent siteContent, string outputPath, string baseUrl)
 {
     try
     {
         var siteMapGenerator = new SitemapGenerator();
         var siteMap1         = siteMapGenerator.Generate(baseUrl, siteContent);
         var siteMapPath      = $"{outputPath}\\sitemap.xml";
         using (var writer = new StreamWriter(siteMapPath))
         {
             writer.WriteLine(siteMap1);
         }
         return(siteMapPath);
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error while mapping site: {ex.Message} - {ex.StackTrace}");
         throw;
     }
 }
        public IActionResult GenSiteMap()
        {
            string saveDir  = evn.WebRootPath + "\\SiteMap";
            string savePath = evn.WebRootPath + "\\SiteMap\\Sitemap.xml";

            var posts = _context.Posts.ToList();

            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }

            if (!System.IO.File.Exists(savePath))
            {
                using (var filestream = System.IO.File.Create(savePath))
                {
                }
            }
            var sitemapGeneratetor = new SitemapGenerator();

            // add the home page to the sitemap
            sitemapGeneratetor.AddUrl(AppGlobal.SiteUrl, modified: DateTime.UtcNow, changeFrequency: ChangeFrequency.Weekly, priority: 1.0);

            // add the blog posts to the sitemap
            foreach (var post in posts)
            {
                sitemapGeneratetor.AddUrl(AppGlobal.SiteUrl + post.metaTitle + "-" + post.id + ".html",
                                          modified: post.createDate, changeFrequency: ChangeFrequency.Always, priority: 1);
            }

            string content = sitemapGeneratetor.ToString();

            System.IO.File.WriteAllText(savePath, content);

            return(Redirect(AppGlobal.SiteUrl + "SiteMap/SiteMap.xml"));
        }
 public void SetUp()
 {
     _sitemapSerializerMock = Substitute.For<ISerializedXmlSaver<Sitemap>>();
     _sitemapGenerator = new SitemapGenerator(_sitemapSerializerMock);
 }
Beispiel #15
0
 public HomeController(ILogger <HomeController> logger, SitemapGenerator sitemapGenerator)
 {
     this._logger          = logger;
     this.sitemapGenerator = sitemapGenerator;
 }
 public void SetUp()
 {
     _sitemapGenerator = new SitemapGenerator();
 }
 public void SetUp()
 {
     _sitemapSerializer = new SerializedXmlSaver <Sitemap>(new FileSystemWrapper());
     _sitemapGenerator  = new SitemapGenerator(_sitemapSerializer);
 }
 public void SetUp()
 {
     _sitemapGenerator = new SitemapGenerator();
 }
Beispiel #19
0
 public void SetUp()
 {
     _sitemapSerializer = new SerializedXmlSaver <List <Url> >(new TestFileSystemWrapper());
     _sitemapGenerator  = new SitemapGenerator(_sitemapSerializer);
 }
 public ActionResult SitemapXml()
 {
     return(SitemapGenerator.GetSitemapXml(Url, HttpContext));
 }
        public async Task <ActionResult> Index()
        {
            #region Generate SiteMap

            string mainUrl          = "http://moemisto.com.ua/";
            var    siteMapPath      = Server.MapPath("/");
            var    sitemapGenerator = new SitemapGenerator();

            var years = await _context.GetYearsForSiteMap();

            foreach (var year in years)
            {
                var fileName = string.Format("{0}/sitemap{1}.xml.gz", siteMapPath, year);
                if (year != DateTime.Now.Year && System.IO.File.Exists(fileName))
                {
                    continue;
                }
                var siteMapsInfo = await _context.GetSiteMapInfoByYear(year);

                SiteMapHelper.SaveSiteMap(siteMapsInfo, fileName);
            }

            // Places
            var fileNamePlaces = string.Format("{0}/sitemap-places.xml.gz", siteMapPath);
            var siteMapsPlaces = await _context.GetSiteMapInfoPlaces();

            SiteMapHelper.SaveSiteMap(siteMapsPlaces, fileNamePlaces);

            // Site Sections
            var fileNameSections = string.Format("{0}/sitemap-sections.xml.gz", siteMapPath);
            var siteMapsSections = new List <SiteMapItemDb>
            {
                new SiteMapItemDb {
                    Url = mainUrl, ChangeFrequency = SitemapChangeFrequency.Hourly
                },
                new SiteMapItemDb {
                    Url = string.Format("{0}news", mainUrl), ChangeFrequency = SitemapChangeFrequency.Hourly
                },
                new SiteMapItemDb {
                    Url = string.Format("{0}afisha", mainUrl), ChangeFrequency = SitemapChangeFrequency.Hourly
                },
                new SiteMapItemDb {
                    Url = string.Format("{0}travel", mainUrl), ChangeFrequency = SitemapChangeFrequency.Hourly
                },
                new SiteMapItemDb {
                    Url = string.Format("{0}places", mainUrl), ChangeFrequency = SitemapChangeFrequency.Hourly
                },
                new SiteMapItemDb {
                    Url = string.Format("{0}about", mainUrl), ChangeFrequency = SitemapChangeFrequency.Monthly
                }
            };

            SiteMapHelper.SaveSiteMap(siteMapsSections, fileNameSections);

            //var listSiteMapFiles =
            //    years.Select(s => new SitemapItem(string.Format("{0}sitemap{1}.xml.gz", mainUrl, s)))
            //        .ToList();
            //
            //listSiteMapFiles.Add(new SitemapItem(string.Format("{0}sitemap-places.xml.gz", mainUrl)));
            //listSiteMapFiles.Add(new SitemapItem(string.Format("{0}sitemap-sections.xml.gz", mainUrl)));

            //var mainXmlDoc = sitemapGenerator.GenerateSiteMap(listSiteMapFiles);
            //mainXmlDoc.Save(string.Format("{0}/sitemap.xml", siteMapPath));

            #endregion

            return(View());
        }
Beispiel #22
0
        private void GetSitemap()
        {
            string sitemapName = WebUtil.GetQueryString("name");

            if (!String.IsNullOrEmpty(sitemapName))
            {
                Item sitemapRoot = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.RootPath + "/Sitemap Module/" + sitemapName);

                if (sitemapRoot != null)
                {
                    SitemapGenerator generator = new SitemapGenerator(sitemapRoot);
                    generator.Generate(Response.Output);
                    Response.Output.Flush();
                }
            }
        }
Beispiel #23
0
 private void GetSitemapIndex()
 {
     SitemapGenerator generator = new SitemapGenerator();
     generator.GenerateIndex(Response.Output);
     Response.Output.Flush();
 }
Beispiel #24
0
 public void SetUp()
 {
     _sitemapSerializerMock = Substitute.For <ISerializedXmlSaver <Sitemap> >();
     _sitemapGenerator      = new SitemapGenerator(_sitemapSerializerMock);
 }