Beispiel #1
0
        public void GenerateSitemap(object sender, EventArgs args)
        {
            Logger.Info("Generate Sitemap local event raised.");

            if (!_shouldGenerate)
            {
                Logger.Info("Sitemap generation disabled on this server due to Sitemap.ShouldGenerate setting set to false.");
                return;
            }

            if (!(args is RemoteEventArgs <GenerateSitemapRemoteEvent> generateSitemapArgs))
            {
                throw new InvalidOperationException("Unexpected event args: {0}".FormatWith((object)args.GetType().FullName));
            }

            if (!string.IsNullOrWhiteSpace(generateSitemapArgs.Event.SiteName))
            {
                Logger.Info($"Starting generation of site: {generateSitemapArgs.Event.SiteName}.");
            }

            if (!string.IsNullOrWhiteSpace(generateSitemapArgs.Event.SiteGroupName))
            {
                Logger.Info($"Starting generation of site group: {generateSitemapArgs.Event.SiteGroupName}.");
            }

            var sitemapGenerateArgs = new SitemapGenerateArgs(generateSitemapArgs.Event.SiteName, generateSitemapArgs.Event.SiteGroupName);

            CorePipeline.Run("sitemap.Generate", sitemapGenerateArgs);
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (!args.IsSiteGroup || args.SitemapSites.Count <= 1)
            {
                return;
            }

            var sitemapindex = new Sitemapindex();

            foreach (var sitemapSite in args.SitemapSites)
            {
                var scheme = sitemapSite.SiteContext.Properties["scheme"] ?? "http";

                var groupUrl = $"{scheme}://{sitemapSite.SiteContext.TargetHostName}";

                var loc = $"{groupUrl}/sitemaps/{ItemUtil.ProposeValidItemName(sitemapSite.SiteContext.Name)}.xml";

                var sitemap = new Sitemap(loc, DateTime.Now);

                sitemapindex.Sitemaps.Add(sitemap);
            }

            Logger.Info($"Generated SiteIndex object for site group: {args.SiteGroupName}");

            var xmlString = sitemapindex.SitemapToXml();

            var indexPath = $"{args.SiteDirectoryAbsolutePath}\\index.xml";

            File.WriteAllText(indexPath, xmlString);
            Logger.Info($"Wrote SiteIndex XML for site group: {args.SiteGroupName}");
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            foreach (var sitemapSite in args.SitemapSites)
            {
                CorePipeline.Run("sitemap.GetLanguages", sitemapSite);
            }
        }
Beispiel #4
0
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            foreach (var sitemapSite in args.SitemapSites)
            {
                var sitemapWriteFileArgs = new SitemapWriteFileArgs(sitemapSite.SiteContext, sitemapSite.AbsolutePath, sitemapSite.XmlString);

                CorePipeline.Run("sitemap.WriteFile", sitemapWriteFileArgs);
            }
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            foreach (var sitemapSite in args.SitemapSites)
            {
                var sitemapGetItemsArgs = new SitemapGetItemsArgs(sitemapSite);

                CorePipeline.Run("sitemap.GetItems", sitemapGetItemsArgs);

                args.SitemapItems.AddRange(sitemapGetItemsArgs.SitemapItems);
            }
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (Directory.Exists(args.SiteDirectoryAbsolutePath))
            {
                DeleteDirectory(args.SiteDirectoryAbsolutePath);
                Logger.Info($"Deleted Sitemap site directory: {args.SiteDirectoryAbsolutePath}.");
            }

            Directory.CreateDirectory(args.SiteDirectoryAbsolutePath);
            Logger.Info($"Created Sitemap directory: {args.SiteDirectoryAbsolutePath}");
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (args.SitemapSites.Count == 1)
            {
                var sitemapBuildSitemapXmlArgs = new SitemapBuildSitemapXmlArgs(args.SitemapSites.FirstOrDefault(), args.SitemapItems);

                CorePipeline.Run("sitemap.BuildSiteXml", sitemapBuildSitemapXmlArgs);
                return;
            }

            foreach (var sitemapSite in args.SitemapSites)
            {
                var sitemapBuildSitemapXmlArgs = new SitemapBuildSitemapXmlArgs(sitemapSite, args.SitemapItems, true);

                CorePipeline.Run("sitemap.BuildSiteXml", sitemapBuildSitemapXmlArgs);
            }
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (Directory.Exists(args.GlobalDirectoryAbsolutePath))
            {
                Logger.Info($"Sitemap global directory already exists: {args.GlobalDirectoryAbsolutePath}.");
                return;
            }

            try
            {
                Directory.CreateDirectory(args.GlobalDirectoryAbsolutePath);
                Logger.Info($"Sitemap global directory created: {args.GlobalDirectoryAbsolutePath}.");
            }
            catch (Exception ex)
            {
                Logger.Error($"Error creating directory: {args.GlobalDirectoryAbsolutePath}", ex);
            }
        }
Beispiel #9
0
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (!string.IsNullOrWhiteSpace(args.SiteGroupName))
            {
                var sites = SiteContextFactory.Sites.Where(i => string.Equals(i.Properties["sitemapGroup"], args.SiteGroupName,
                                                                              StringComparison.InvariantCultureIgnoreCase));

                foreach (var site in sites)
                {
                    args.SitemapSites.Add(
                        new SitemapSiteArgs(
                            new SiteContext(site), args.SiteDirectoryAbsolutePath));
                }
                return;
            }

            if (!string.IsNullOrWhiteSpace(args.SiteName))
            {
                var site = SiteManager.GetSite(args.SiteName);

                if (site == null)
                {
                    Logger.Error($"Unable to resolve site with SiteManager: {args.SiteName}");
                    args.AbortPipeline();
                    return;
                }

                args.SitemapSites.Add(
                    new SitemapSiteArgs(
                        new SiteContext(
                            new SiteInfo(site.Properties)), args.SiteDirectoryAbsolutePath));
                return;
            }

            Logger.Error($"No SiteName or SiteGroupName found, aborting.");
            args.AbortPipeline();
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            if (!_matchPaths)
            {
                Logger.Info("Site Group languages not included due to Sitemap.Groups.MatchPaths being set to false.");
                return;
            }

            var allLanguages = new List <SitemapLanguage>();

            foreach (var sitemapSite in args.SitemapSites)
            {
                allLanguages.AddRange(sitemapSite.SitemapLanguages);
            }

            allLanguages = allLanguages.DistinctBy(lang => lang.Language.Name).ToList();

            foreach (var sitemapSite in args.SitemapSites)
            {
                sitemapSite.SitemapLanguages = allLanguages;
            }
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            args.SitemapItems = args.SitemapItems.OrderBy(i => i.Item.Paths.FullPath.Length).ToList();
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            args.SiteDirectoryAbsolutePath = SiteRelativeDirectory(args.GlobalDirectoryAbsolutePath, $"\\{args.ProposedSitemapName}");
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            args.GlobalDirectoryAbsolutePath = GlobalDirectory();
        }
        public void Process(SitemapGenerateArgs args)
        {
            Assert.ArgumentNotNull(args, nameof(args));

            CorePipeline.Run("sitemap.WriteSitemaps", args);
        }