private void CreateSitemapXmlFile(List <Feature> features)
 {
     using (var fileStream = _fileSystemHelper.CreateWriteStream(Path.Combine(_environment.WebRootPath, "sitemap.xml")))
     {
         var list = features.Select(p =>
         {
             var dateString = DateTime.Now.ToUniversalTime().ToString("o");
             if (p.Attributes.Exists(FeatureAttributes.POI_LAST_MODIFIED))
             {
                 if (p.Attributes[FeatureAttributes.POI_LAST_MODIFIED] is DateTime dateTime)
                 {
                     dateString = dateTime.ToUniversalTime().ToString("o");
                 }
                 else
                 {
                     dateString = p.Attributes[FeatureAttributes.POI_LAST_MODIFIED].ToString();
                 }
             }
             return(new tUrl
             {
                 lastmod = dateString,
                 loc = "https://israelhiking.osm.org.il/poi/" + p.Attributes[FeatureAttributes.POI_SOURCE] + "/" + p.Attributes[FeatureAttributes.ID],
             });
         });
         var siteMap = new urlset
         {
             url = list.Concat(new[] { new tUrl {
                                           loc     = "https://israelhiking.osm.org.il/",
                                           lastmod = DateTime.Now.ToUniversalTime().ToString("o")
                                       } }).ToArray()
         };
         var serializer = new XmlSerializer(typeof(urlset));
         serializer.Serialize(fileStream, siteMap);
     }
 }
        public async Task CreateFileSitemapAsync()
        {
            TextWriter writer = new StreamWriter(Server.MapPath("~/sitemap.xml"));

            try
            {
                List <url> listUrl = new List <url>();
                //заполняем статическимим ссылками

                listUrl.Add(new url
                {
                    changefreq = "daily",
                    loc        = "http://baeroff.com",
                    priority   = 1.0
                });

                listUrl.Add(new url
                {
                    changefreq = "monthly",
                    lastmod    = Helpers.Services.ConvertDateToW3CTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)),
                    loc        = "http://baeroff.com/home/register",
                    priority   = 1.0
                });

                //заполняем статьями
                using (EFArticleContext articleContext = new EFArticleContext())
                {
                    List <url> listArticle = await(from article in articleContext.Articles.AsQueryable()
                                                   where article.IsVisible == true
                                                   select new url
                    {
                        changefreq = "monthly",
                        lastmod    = article.DatePublish.ToString(),
                        loc        = "http://baeroff.com/articles/article/" + article.Link,
                        priority   = 0.8
                    }).ToListAsync();
                    foreach (var la in listArticle)
                    {
                        la.lastmod = Helpers.Services.ConvertDateToW3CTime(DateTime.Parse(la.lastmod));
                    }
                    listUrl.AddRange(listArticle);
                }

                urlset data = new urlset();
                data.urls = listUrl;

                XmlSerializer serializer = new XmlSerializer(typeof(urlset));
                serializer.Serialize(writer, data);
            }
            finally
            {
                writer.Close();
            }
        }
        protected string GenerateSiteMap(List <SiteMapUrl> siteMapItems, int startIndex, int count)
        {
            urlset siteMap = new urlset();
            url    url;

            List <url> urlList  = new List <url>();
            int        endIndex = startIndex + count;
            SiteMapUrl urlItem;

            for (int i = startIndex; i < endIndex; i++)
            {
                urlItem = siteMapItems[i];
                url     = new url();
                url.loc = urlItem.Location;
                if (urlItem.LastModified != DateTime.MinValue)
                {
                    url.lastmod = urlItem.LastModified.ToString("yyyy-MM-ddTHH:mm:sszzzzzz");
                }
                if (urlItem.ChangeFrequencySpecified)
                {
                    url.changefreqSpecified = true;
                    url.changefreq          = urlItem.ChangeFrequency;
                }
                else
                {
                    url.changefreqSpecified = false;
                }

                if (urlItem.Priority >= 0 && urlItem.Priority <= 1)
                {
                    url.priority          = urlItem.Priority;
                    url.prioritySpecified = true;
                }
                else
                {
                    url.prioritySpecified = false;
                }

                urlList.Add(url);
            }

            siteMap.url = urlList.ToArray();

            return(XmlUtility.Utf8BytesToString(XmlUtility.Serialize(siteMap)));
        }
Ejemplo n.º 4
0
        public override bool Execute()
        {
            List <tUrl> urls = new List <tUrl>();
            DateTime    mostRecentlyModified = DateTime.MinValue;

            WarnIfUneven(Tuple.Create("Inputs", Inputs), Tuple.Create("Locations", Locations));
            foreach (var tuple in Zip(Inputs, Locations))
            {
                tUrl url = new tUrl();
                url.loc = tuple.Item2.ItemSpec.Replace('\\', '/');
                DateTime lastmod = tuple.Item1.GetTimestamp();
                if (lastmod > mostRecentlyModified)
                {
                    mostRecentlyModified = lastmod;
                }
                //http://www.w3.org/TR/NOTE-datetime
                //http://stackoverflow.com/questions/7281995/how-can-i-get-this-datetime-format-in-net
                url.lastmod = lastmod.ToString("yyyy-MM-ddTHH:mmK", CultureInfo.InvariantCulture);
                urls.Add(url);
            }

            urlset urlset = new urlset();

            urlset.url = urls.ToArray();
            Output.RequireParentDirectory(Log);
            XmlSerializer serializer = new XmlSerializer(typeof(urlset));

            using (Stream stream = File.OpenWrite(Output.ItemSpec))
            {
                serializer.Serialize(stream, urlset);
            }

            if (mostRecentlyModified > DateTime.MinValue)
            {
                File.SetLastWriteTime(Output.ItemSpec, mostRecentlyModified);
            }
            return(true);
        }
Ejemplo n.º 5
0
        private void CreateSiteMap(SortedDictionary <string, HelpEntity> topicsAndAnchors)
        {
            SortedDictionary <string, url> dictionaryOfUrl = new SortedDictionary <string, url>();
            url    url;
            Topic  topic;
            string topicTitle;

            url                     = new url();
            url.loc                 = Properties.Settings.Default.website;
            url.priority            = (decimal)1;
            url.prioritySpecified   = true;
            url.changefreq          = changefreq.monthly;
            url.changefreqSpecified = true;
            url.lastmod             = System.DateTime.Now.Date.ToString("yyyy\"-\"MM\"-\"dd");
            dictionaryOfUrl.Add("AAARootElement", url);

            foreach (HelpEntity he in topicsAndAnchors.Values)
            {
                topic                   = he as Topic;
                url                     = new url();
                topicTitle              = topic.TopicsTitle.Replace(" ", "");
                url.loc                 = Properties.Settings.Default.website + "?topic=" + "html/" + topic.TopicsGuid.ToString() + ".htm";
                url.priority            = (decimal)0.8;
                url.prioritySpecified   = true;
                url.changefreq          = changefreq.monthly;
                url.changefreqSpecified = true;
                url.lastmod             = System.DateTime.Now.Date.ToString("yyyy\"-\"MM\"-\"dd");
                if (!dictionaryOfUrl.ContainsKey(topicTitle))
                {
                    dictionaryOfUrl.Add(topicTitle, url);
                }
            }
            urlset   urlSet      = new urlset(dictionaryOfUrl);
            FileInfo siteMapFile = new FileInfo(builder.OutputFolder.ToString() + "/" + Properties.Settings.Default.SiteMapFile);

            urlSet.WriteToXML(siteMapFile);
        }
Ejemplo n.º 6
0
        public urlset GetGoogleSiteMap()
        {
            urlset root = new urlset();

            root.url = new urlCollection();

            //Default first...
            url basePage = new url(dasBlogSettings.GetBaseUrl(), DateTime.Now, changefreq.daily, 1.0M);

            root.url.Add(basePage);

            //Archives next...
            url archivePage = new url(dasBlogSettings.RelativeToRoot("archives"), DateTime.Now, changefreq.daily, 1.0M);

            root.url.Add(archivePage);

            //All Pages
            EntryCollection entryCache = dataService.GetEntries(false);

            foreach (Entry e in entryCache)
            {
                if (e.IsPublic)
                {
                    //Start with a RARE change freq...newer posts are more likely to change more often.
                    // The older a post, the less likely it is to change...
                    changefreq freq = changefreq.daily;

                    //new stuff?
                    if (e.CreatedLocalTime < DateTime.Now.AddMonths(-9))
                    {
                        freq = changefreq.yearly;
                    }
                    else if (e.CreatedLocalTime < DateTime.Now.AddDays(-30))
                    {
                        freq = changefreq.monthly;
                    }
                    else if (e.CreatedLocalTime < DateTime.Now.AddDays(-7))
                    {
                        freq = changefreq.weekly;
                    }
                    if (e.CreatedLocalTime > DateTime.Now.AddDays(-2))
                    {
                        freq = changefreq.hourly;
                    }

                    //Add comments pages, since comments have indexable content...
                    // Only add comments if we aren't showing comments on permalink pages already
                    if (dasBlogSettings.SiteConfiguration.ShowCommentsWhenViewingEntry == false)
                    {
                        url commentPage = new url(dasBlogSettings.GetCommentViewUrl(e.CompressedTitle), e.CreatedLocalTime, freq, 0.7M);
                        root.url.Add(commentPage);
                    }

                    //then add permalinks
                    url permaPage = new url(dasBlogSettings.RelativeToRoot(dasBlogSettings.GetPermaTitle(e.CompressedTitle)), e.CreatedLocalTime, freq, 0.9M);
                    root.url.Add(permaPage);
                }
            }

            //All Categories
            CategoryCacheEntryCollection catCache = dataService.GetCategories();

            foreach (CategoryCacheEntry cce in catCache)
            {
                if (cce.IsPublic)
                {
                    url catPage = new url(dasBlogSettings.GetCategoryViewUrl(cce.Name), DateTime.Now, changefreq.weekly, 0.6M);
                    root.url.Add(catPage);
                }
            }

            return(root);
        }
Ejemplo n.º 7
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //Cache the sitemap for 12 hours...
                string CacheKey = "GoogleSiteMap";
                DataCache cache = CacheFactory.GetCache();

                urlset root = cache[CacheKey] as urlset;
                if (root == null) //we'll have to build it...
                {
                    ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
                    IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);
                    SiteConfig siteConfig = SiteConfig.GetSiteConfig();

                    root = new urlset();

                    root.url = new urlCollection();

                    //Default first...
                    url basePage = new url(SiteUtilities.GetBaseUrl(siteConfig), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(basePage);

                    url defaultPage = new url(SiteUtilities.GetStartPageUrl(siteConfig), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(defaultPage);

                    //Archives next...
                    url archivePage = new url(SiteUtilities.RelativeToRoot(siteConfig, "archives.aspx"), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(archivePage);

                    //All Pages
                    EntryCollection entryCache = dataService.GetEntries(false);
                    foreach (Entry e in entryCache)
                    {
                        if (e.IsPublic)
                        {
                            //Start with a RARE change freq...newer posts are more likely to change more often.
                            // The older a post, the less likely it is to change...
                            changefreq freq = changefreq.daily;

                            //new stuff?
                            if (e.CreatedLocalTime < DateTime.Now.AddMonths(-9))
                            {
                                freq = changefreq.yearly;
                            }
                            else if (e.CreatedLocalTime < DateTime.Now.AddDays(-30))
                            {
                                freq = changefreq.monthly;
                            }
                            else if (e.CreatedLocalTime < DateTime.Now.AddDays(-7))
                            {
                                freq = changefreq.weekly;
                            }
                            if (e.CreatedLocalTime > DateTime.Now.AddDays(-2))
                            {
                                freq = changefreq.hourly;
                            }

                            //Add comments pages, since comments have indexable content...
                            // Only add comments if we aren't showing comments on permalink pages already
                            if (siteConfig.ShowCommentsWhenViewingEntry == false)
                            {
                                url commentPage = new url(SiteUtilities.GetCommentViewUrl(siteConfig, e.EntryId), e.CreatedLocalTime, freq, 0.7M);
                                root.url.Add(commentPage);
                            }

                            //then add permalinks
                            url permaPage = new url(SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)e), e.CreatedLocalTime, freq, 0.9M);
                            root.url.Add(permaPage);
                        }
                    }

                    //All Categories
                    CategoryCacheEntryCollection catCache = dataService.GetCategories();
                    foreach (CategoryCacheEntry cce in catCache)
                    {
                        if (cce.IsPublic)
                        {
                            url catPage = new url(SiteUtilities.GetCategoryViewUrl(siteConfig, cce.Name), DateTime.Now, changefreq.weekly, 0.6M);
                            root.url.Add(catPage);
                        }
                    }
                    cache.Insert(CacheKey, root, DateTime.Now.AddHours(12));
                }

                XmlSerializer x = new XmlSerializer(typeof(urlset));
                x.Serialize(context.Response.OutputStream, root);
                context.Response.ContentType = "text/xml";
            }
            catch (Exception exc)
            {
                ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, exc);
            }
        }
Ejemplo n.º 8
0
        public ActionResult Map()
        {
            urlset sitemap = siteManager.GetGoogleSiteMap();

            return(Ok(sitemap));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="args">Arguments</param>
        static void Main(string[] args)
        {
            SortedDictionary <string, HelpEntity> topicsAndAnchors = HelpContentCreator.CreateListOfTopics("z:/trunk/PR34-Documentation/PR26-DataPorter_Help.shfbproj");

            SortedDictionary <string, TopicNode> dictionaryOfTopics = new SortedDictionary <string, TopicNode>();
            Topic     topic;
            TopicNode node;

            foreach (HelpEntity he in topicsAndAnchors.Values)
            {
                topic      = he as Topic;
                node       = new TopicNode();
                node.Title = topic.TopicsTitle.Replace(" ", "");
                node.Url   = "html/" + topic.TopicsGuid.ToString() + ".htm";
                if (!dictionaryOfTopics.ContainsKey(node.Title))
                {
                    dictionaryOfTopics.Add(node.Title, node);
                }
                foreach (string anchor in topic.Anchors)
                {
                    node       = new TopicNode();
                    node.Title = anchor.Replace(" ", "");
                    node.Url   = "html/" + topic.TopicsGuid.ToString() + ".htm#" + anchor;
                    if (!dictionaryOfTopics.ContainsKey(node.Title))
                    {
                        dictionaryOfTopics.Add(node.Title, node);
                    }
                }
            }
            Topics   tpcs       = new Topics(dictionaryOfTopics);
            FileInfo topicsFile = new FileInfo(Properties.Settings.Default.HelpDocumentationAllTopics);

            tpcs.WriteToXML(topicsFile);


            SortedDictionary <string, url> dictionaryOfUrl = new SortedDictionary <string, url>();
            url url;
            //Topic topic;
            string topicTitle;

            url                     = new url();
            url.loc                 = "http://www.commsvr.com/UAModelDesigner/Index.aspx";
            url.priority            = (decimal)1;
            url.prioritySpecified   = true;
            url.changefreq          = changefreq.monthly;
            url.changefreqSpecified = true;
            url.lastmod             = System.DateTime.Now.Date.ToString();
            dictionaryOfUrl.Add("RootElement", url);

            foreach (HelpEntity he in topicsAndAnchors.Values)
            {
                topic                   = he as Topic;
                url                     = new url();
                topicTitle              = topic.TopicsTitle.Replace(" ", "");
                url.loc                 = "http://www.commsvr.com/UAModelDesigner/Index.aspx" + "?topic=" + "html/" + topic.TopicsGuid.ToString() + ".htm";
                url.priority            = (decimal)0.8;
                url.prioritySpecified   = true;
                url.changefreq          = changefreq.monthly;
                url.changefreqSpecified = true;
                url.lastmod             = System.DateTime.Now.Date.ToString();
                if (!dictionaryOfUrl.ContainsKey(topicTitle))
                {
                    dictionaryOfUrl.Add(topicTitle, url);
                }
            }
            urlset   urlSet      = new urlset(dictionaryOfUrl);
            FileInfo siteMapFile = new FileInfo("z:/trunk/PR34-Documentation" + "/" + "sitMap.xml");

            urlSet.WriteToXML(siteMapFile);
        }
Ejemplo n.º 10
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                List <url> urlList    = null;
                urlset     urlsetList = new urlset();

                ArrayList listinfo = GetWebModelInfo();
                urlList = new List <url>();
                for (int i = 0; i < listinfo.Count; i++)
                {
                    WebSiteInfo    webInfo     = listinfo[i] as WebSiteInfo;
                    List <display> displayList = new List <display>();
                    display        display     = new display();
                    display.website = "爱购114";
                    display.siteurl = "http://www.xxxxx.com/";
                    //城市名称
                    display.city = webInfo.cityName;
                    //商品标题
                    display.webSitetitle = webInfo.title;
                    //商品图片
                    display.image = "http://211.155.235.30/tuangou/" + webInfo.folderName + "/" + webInfo.productimg;
                    //商品开始时间
                    display.startTime = webInfo.begin_time.ToShortDateString();
                    //商品结束时间
                    display.endTime = webInfo.end_time.ToShortDateString();
                    //市场价
                    display.value = Convert.ToDouble(webInfo.market_price);
                    //团购价
                    display.price = Convert.ToDouble(webInfo.team_price);
                    //折扣价
                    display.rebate = Convert.ToDouble(webInfo.zhekou_price);
                    //现在购买的人数
                    display.bought = webInfo.nownumber;
                    displayList.Add(display);
                    List <data> dataList = new List <data>();
                    data        data     = new data();
                    data.displayList = displayList;
                    dataList.Add(data);
                    url url = new url();
                    url.loc      = String.Format("http://www.xxxxx.com/todaydetials.aspx?id={0}", webInfo.productID.ToString());
                    url.dataList = dataList;
                    urlList.Add(url);
                    urlsetList.urlList = urlList;
                }
                try
                {
                    XmlSerializerNamespaces xmlns = new XmlSerializerNamespaces();
                    xmlns.Add(String.Empty, String.Empty);
                    //构造字符串
                    StringBuilder sb = new StringBuilder();
                    //将字符串写入到stringWriter对象中
                    StringWriter sw = new StringWriter(sb);
                    //xml序列化对象 typeof(类名)
                    XmlSerializer ser = new XmlSerializer(typeof(urlset));
                    //把Stream对象和urlset一起传入,序列化出一个字符串sb
                    ser.Serialize(sw, urlsetList, xmlns);
                    sw.Close();
                    string   FILE_NAME = HttpContext.Current.Server.MapPath("test.xml");
                    FileInfo fi        = new FileInfo(FILE_NAME);
                    //如果文件己经存在则删除该文件
                    if (fi.Exists)
                    {
                        if (fi.Attributes.ToString().IndexOf("ReadOnly") >= 0)
                        {
                            fi.Attributes = FileAttributes.Normal;
                        }
                        File.Delete(fi.Name);
                    }
                    //创建文件 并写入字符串
                    using (StreamWriter sWrite = File.CreateText(FILE_NAME))
                    {
                        sWrite.Write(sb.ToString().Replace("encoding=\"utf-16\"", "encoding=\"utf-8\"").Replace("<urlList>", "").Replace("</urlList>", "").Replace("<dataList>", "").Replace("</dataList>", "").Replace("<displayList>", "").Replace("<displayList>", "").Replace("</displayList>", ""));
                        sWrite.Close();
                    }
                    //输出序列化后xml文件
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.ContentType = "application/xml";
                    Response.WriteFile(HttpContext.Current.Server.MapPath("test.xml"));
                    Response.Flush();
                    Response.Close();
                    Response.Write("生成成功!");
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
                finally
                {
                }
            }
            catch (Exception ex)
            {
                Response.Write("错误!" + ex.Message);
            }
        }
Ejemplo n.º 11
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //Cache the sitemap for 12 hours...
                string    CacheKey = "GoogleSiteMap";
                DataCache cache    = CacheFactory.GetCache();

                urlset root = cache[CacheKey] as urlset;
                if (root == null) //we'll have to build it...
                {
                    ILoggingDataService logService  = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());
                    IBlogDataService    dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService);
                    SiteConfig          siteConfig  = SiteConfig.GetSiteConfig();

                    root = new urlset();

                    root.url = new urlCollection();

                    //Default first...
                    url basePage = new url(SiteUtilities.GetBaseUrl(siteConfig), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(basePage);

                    url defaultPage = new url(SiteUtilities.GetStartPageUrl(siteConfig), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(defaultPage);

                    //Archives next...
                    url archivePage = new url(SiteUtilities.RelativeToRoot(siteConfig, "archives.aspx"), DateTime.Now, changefreq.daily, 1.0M);
                    root.url.Add(archivePage);

                    //All Pages
                    EntryCollection entryCache = dataService.GetEntries(false);
                    foreach (Entry e in entryCache)
                    {
                        if (e.IsPublic)
                        {
                            //Start with a RARE change freq...newer posts are more likely to change more often.
                            // The older a post, the less likely it is to change...
                            changefreq freq = changefreq.daily;

                            //new stuff?
                            if (e.CreatedLocalTime < DateTime.Now.AddMonths(-9))
                            {
                                freq = changefreq.yearly;
                            }
                            else if (e.CreatedLocalTime < DateTime.Now.AddDays(-30))
                            {
                                freq = changefreq.monthly;
                            }
                            else if (e.CreatedLocalTime < DateTime.Now.AddDays(-7))
                            {
                                freq = changefreq.weekly;
                            }
                            if (e.CreatedLocalTime > DateTime.Now.AddDays(-2))
                            {
                                freq = changefreq.hourly;
                            }

                            //Add comments pages, since comments have indexable content...
                            // Only add comments if we aren't showing comments on permalink pages already
                            if (siteConfig.ShowCommentsWhenViewingEntry == false)
                            {
                                url commentPage = new url(SiteUtilities.GetCommentViewUrl(siteConfig, e.EntryId), e.CreatedLocalTime, freq, 0.7M);
                                root.url.Add(commentPage);
                            }

                            //then add permalinks
                            url permaPage = new url(SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)e), e.CreatedLocalTime, freq, 0.9M);
                            root.url.Add(permaPage);
                        }
                    }

                    //All Categories
                    CategoryCacheEntryCollection catCache = dataService.GetCategories();
                    foreach (CategoryCacheEntry cce in catCache)
                    {
                        if (cce.IsPublic)
                        {
                            url catPage = new url(SiteUtilities.GetCategoryViewUrl(siteConfig, cce.Name), DateTime.Now, changefreq.weekly, 0.6M);
                            root.url.Add(catPage);
                        }
                    }
                    cache.Insert(CacheKey, root, DateTime.Now.AddHours(12));
                }

                XmlSerializer x = new XmlSerializer(typeof(urlset));
                x.Serialize(context.Response.OutputStream, root);
                context.Response.ContentType = "text/xml";
            }
            catch (Exception exc)
            {
                ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, exc);
            }
        }
Ejemplo n.º 12
0
        public ActionResult Map()
        {
            urlset sitemap = _siteRepository.GetGoogleSiteMap();

            return(Ok(sitemap));
        }