Esempio n. 1
0
        private int AddNodes(SiteMapProtocol smpWriter, string countryCode, IUrlArrayFactory factory, List <string> files, int fileIndex, ILogger log)
        {
            int    nodecount   = 1;
            string urlTypeName = "";

            try
            {
                var urllist = factory.GetNext();
                if (urllist == null || urllist.Count == 0)
                {
                    log.LogInformation(string.Format("\n File not created because no nodes exists for the country : {0}.", countryCode));
                    return(fileIndex);
                }
                fileIndex++;
                log.LogInformation(string.Format("\n {0} : New file created", countryCode));
                smpWriter.StartSitemapFile(countryCode, fileIndex);
                foreach (var item in urllist)
                {
                    log.LogInformation("Looping urls");
                    log.LogInformation("node count" + nodecount);

                    if (nodecount > AppSettings.SitemapFileNodeLimit)
                    {
                        log.LogInformation("node count > limit.Start new index file");
                        files.Add(smpWriter.EndFile());

                        smpWriter.StartSitemapFile(countryCode, ++fileIndex);
                        nodecount = 1;
                    }
                    var hrefUrl = smpWriter.AddUrlNode(item, DateTime.Now);

                    urlTypeName = string.IsNullOrEmpty(urlTypeName) ? urllist.GetType().Name : urlTypeName;
                    nodecount  += 1;
                    log.LogInformation("Build hreflang url");

                    var hrefLangUrl = BuildHrefLangURL(countryCode.ToLower(), hrefUrl);

                    azureTableOperations.InsertHrefLangUrl(countryCode, hrefLangUrl, hrefUrl, log);
                }
                files.Add(smpWriter.EndFile());

                log.LogInformation(string.Format("\n {0} : File count: {1} ", countryCode, fileIndex));
            }
            catch (Exception ex)
            {
                log.LogError(ex.StackTrace + ex.Message);
            }

            return(fileIndex);
        }
Esempio n. 2
0
 public void CreateSiteMapIndex(SiteMapProtocol smpWriter, string[] filenames, ILogger log)
 {
     try
     {
         log.LogInformation("Start creating sitemap index... ");
         smpWriter.StartIndexFile();
         foreach (string filename in filenames)
         {
             smpWriter.AddIndexNode(filename, DateTime.Now);
         }
         smpWriter.EndFile();
         log.LogInformation("done!");
     }
     catch (Exception ex)
     {
         log.LogError(ex.StackTrace + ex.Message);
     }
 }