示例#1
0
        public ActionResult Index(string url)
        {
            try
            {
                Uri    uri  = new Uri(url);
                string host = uri.Scheme + "://" + uri.Host;

                List <string> sitemapURLs = SitemapHelper.GetSitemapURLs(host);

                if (sitemapURLs.Count > 0)
                {
                    Evaluate evaluate = new Evaluate {
                        Host = host, Date = DateTime.Now
                    };
                    db.Evaluates.Add(evaluate);
                    db.SaveChanges();

                    Task.Run(() => new EvaluateSite(sitemapURLs, evaluate.Id));

                    ViewBag.EvaluateId = evaluate.Id;
                    ViewBag.Host       = host;
                    ViewBag.URLsCount  = sitemapURLs.Count;
                }
                else
                {
                    ViewBag.Error = "Sitemap can not be found or Sitemap does not contain URLs!";
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(View());
        }
示例#2
0
        public virtual string GenerateXmlString(IEnumerable <SitemapItem> items)
        {
            var sitemapCount = (int)Math.Ceiling(items.Count() / (double)SitemapHelper.MaximumSitemapIndexCount);

            SitemapHelper.CheckSitemapCount(sitemapCount);

            if (items == null || !items.Any())
            {
                throw new ArgumentNullException($"{nameof(items)} is null");
            }

            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(Xmlns + "urlset",
                             new XAttribute("xmlns", Xmlns),
                             new XAttribute(XNamespace.Xmlns + "xsi", Xsi),
                             new XAttribute(Xsi + "schemaLocation",
                                            @"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"),
                             from item in items
                             select CreateItemElement(item)
                             )
                );

            var xml = sitemap.ToString(Encoding.UTF8);

            SitemapHelper.CheckDocumentSize(xml);

            return(xml);
        }
        public ActionResult SitemapXml()
        {
            var sitemapNodes = SitemapHelper.GetSitemapModels();
            var xml          = sitemapNodes.GetSitemapDocument();

            return(this.Content(xml, "text/Xml", Encoding.UTF8));
        }
        public ActionResult Index()
        {
            ViewBag.Title = Localization.SiteNameSiteMap;
            var sitemapNodes = SitemapHelper.GetSitemapModels(CultureHelper.GetCurrentCulture());
            var tree         = sitemapNodes.GetTreeNode();

            return(View(tree));
        }
示例#5
0
        private static void digikala_SitemapClean()
        {
            string path = @"C:\Digikala\100125842.xml";

            using (var sitemap = new SitemapHelper())
            {
                //sitemap.CleanFile(path);
            }
        }
示例#6
0
 private static void digikala_SitemapToObject(string path)
 {
     //string path = @"C:\Digikala\100125842.xml";
     using (var sitemap = new SitemapHelper())
     {
         Urlset list  = sitemap.SitemapToObject(path);
         var    _test = list.urlset.ToList();
         Console.WriteLine("Sitemap Count: " + _test.Count());
     }
 }
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <returns>
        /// Sitemap list.
        /// </returns>
        public List <SitemapViewModel> Execute()
        {
            var sitemaps        = new List <SitemapViewModel>();
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);
            IQueryable <Models.Sitemap> sitemapQuery =
                Repository.AsQueryable <Models.Sitemap>().FetchMany(map => map.AccessRules).FetchMany(map => map.Nodes).ThenFetch(node => node.Page);

            if (CmsConfiguration.EnableMultilanguage)
            {
                sitemapQuery = sitemapQuery
                               .FetchMany(map => map.Nodes)
                               .ThenFetchMany(node => node.Translations);
            }

            var allSitmaps = sitemapQuery.Distinct().ToFuture().ToList();
            var languages  = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();

            foreach (var sitemap in allSitmaps)
            {
                var model = new SitemapViewModel
                {
                    Id        = sitemap.Id,
                    Version   = sitemap.Version,
                    Title     = sitemap.Title,
                    RootNodes =
                        SitemapHelper.GetSitemapNodesInHierarchy(
                            CmsConfiguration.EnableMultilanguage,
                            sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                            sitemap.Nodes.Distinct().ToList(),
                            languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                            (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                    Languages            = languages,
                    ShowMacros           = false
                };

                if (CmsConfiguration.Security.AccessControlEnabled)
                {
                    model.UserAccessList = sitemap.AccessRules.Distinct().Select(x => new UserAccessViewModel(x)).ToList();
                    var rules = model.UserAccessList.Cast <IAccessRule>().ToList();
                    SetIsReadOnly(model, rules);
                }

                if (!model.IsReadOnly)
                {
                    sitemaps.Add(model);
                }
            }

            return(sitemaps.Count > 0 ? sitemaps.OrderBy(map => map.Title).ToList() : null);
        }
示例#8
0
        public string GetTreeJsonForMenu()
        {
            string[] roles    = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);
            var      roleList = roles.ToList();

            //if (roleList.Contains("Administrators"))
            //{
            //    roleList.Remove("Administrators");
            //}
            //roleList.Add("Users");
            SitemapHelper.Roles = roleList;
            return(SitemapHelper.GetTreeJsonForMenu());
        }
示例#9
0
        private static void digikala_SitemapFolder()
        {
            string directoryPath = @"C:\Digikala\xml";

            DirectoryInfo directorySelected = new DirectoryInfo(directoryPath);
            string        file1             = string.Empty;

            FileInfo[] fileInfos = directorySelected.GetFiles();
            foreach (FileInfo file in fileInfos)
            {
                using (var sitemap = new SitemapHelper())
                {
                    sitemap.CleanFile(file);
                }
            }
        }
示例#10
0
        private void ExtractSiteMap(Uri uri, List <string> itemsToAdd)
        {
            HttpWebRequest  request  = (HttpWebRequest)HttpWebRequest.Create(uri);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (null != response)
            {
                if (HttpStatusCode.OK == response.StatusCode)
                {
                    if (response.ContentType == "text/xml")
                    {
                        List <string> urls = new SitemapHelper().Urls(response.GetResponseStream());
                        ProcessList(urls);
                    }
                }
            }
        }
示例#11
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="versionId">The sitemap version identifier.</param>
        /// <returns>
        /// Sitemap view model.
        /// </returns>
        public SitemapViewModel Execute(Guid versionId)
        {
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);

            // Return current or old version.
            var sitemap = Repository.AsQueryable <Models.Sitemap>()
                          .Where(map => map.Id == versionId)
                          .FetchMany(map => map.Nodes)
                          .ThenFetch(node => node.Page)
                          .FetchMany(map => map.Nodes)
                          .ThenFetchMany(node => node.Translations)
                          .Distinct()
                          .ToFuture()
                          .ToList()
                          .FirstOrDefault() ?? SitemapService.GetArchivedSitemapVersionForPreview(versionId);

            if (sitemap != null)
            {
                var languages = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();
                var model     = new SitemapViewModel
                {
                    Id        = sitemap.Id,
                    Version   = sitemap.Version,
                    Title     = sitemap.Title,
                    RootNodes =
                        SitemapHelper.GetSitemapNodesInHierarchy(
                            CmsConfiguration.EnableMultilanguage,
                            sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                            sitemap.Nodes.Distinct().ToList(),
                            languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                            (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                    Languages            = languages,
                    IsReadOnly           = true,
                    ShowMacros           = false
                };

                return(model);
            }

            return(null);
        }
示例#12
0
        private static void digikala_LoadSitemap()
        {
            string        dirPath           = @"C:\Digikala\xml\clean";
            DirectoryInfo directorySelected = new DirectoryInfo(dirPath);
            string        file1             = string.Empty;

            FileInfo[]    fileInfos = directorySelected.GetFiles("*.xml");
            List <B5_Url> dkps      = new List <B5_Url>();

            for (int i = 0; i < fileInfos.Length; i++)
            {
                using (var sitemap = new SitemapHelper())
                {
                    dkps.AddRange(sitemap.SitemapToObject(fileInfos[i].ToString()).urlset.ToList());
                }
            }
            using (IWebsiteCrawler digikala = new DigikalaHelper())
            {
                digikala.AddBasePages(dkps);
            }
            int sss = 5;
        }
示例#13
0
        public virtual string GenerateXmlString(IEnumerable <SitemapImageItem> items)
        {
            if (items == null || !items.Any())
            {
                throw new ArgumentNullException($"{nameof(items)} is null");
            }

            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(Xmlns + "urlset",
                             new XAttribute("xmlns", Xmlns),
                             new XAttribute(XNamespace.Xmlns + "image", Image),
                             from item in items
                             select CreateItemElement(item)
                             )
                );

            var xml = sitemap.ToString(Encoding.UTF8);

            SitemapHelper.CheckDocumentSize(xml);
            return(xml);
        }
示例#14
0
        public virtual string GenerateXmlString(IEnumerable <SitemapIndexItem> items)
        {
            if (items?.Any() != true)
            {
                throw new ArgumentNullException($"{nameof(items)} is null");
            }

            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(Xmlns + "sitemapindex",
                             new XAttribute("xmlns", Xmlns),
                             new XAttribute(XNamespace.Xmlns + "xsi", Xsi),
                             new XAttribute(Xsi + "schemaLocation",
                                            @"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"),
                             from item in items
                             select CreateItemElement(item)
                             )
                );

            var xml = sitemap.ToString(Encoding.UTF8);

            SitemapHelper.CheckDocumentSize(xml);
            return(xml);
        }
示例#15
0
        /// <summary>
        /// Executes the specified request.
        /// </summary>
        /// <param name="sitemapId">The sitemap identifier.</param>
        /// <returns>
        /// Sitemap view model.
        /// </returns>
        public SitemapViewModel Execute(Guid sitemapId)
        {
            if (sitemapId.HasDefaultValue())
            {
                var langs = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues().ToList() : new List <LookupKeyValue>();
                return(new SitemapViewModel()
                {
                    AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                    UserAccessList = AccessControlService.GetDefaultAccessList(SecurityService.GetCurrentPrincipal()).Select(f => new UserAccessViewModel(f)).ToList(),
                    ShowLanguages = CmsConfiguration.EnableMultilanguage && langs.Any(),
                    Languages = langs,
                    ShowMacros = CmsConfiguration.EnableMacros
                });
            }

            IEnumerable <AccessRule> userAccessFuture;

            if (CmsConfiguration.Security.AccessControlEnabled)
            {
                userAccessFuture = Repository
                                   .AsQueryable <Models.Sitemap>()
                                   .Where(x => x.Id == sitemapId && !x.IsDeleted)
                                   .SelectMany(x => x.AccessRules)
                                   .OrderBy(x => x.Identity)
                                   .ToFuture();
            }
            else
            {
                userAccessFuture = null;
            }

            var tagsFuture      = TagService.GetSitemapTagNames(sitemapId);
            var languagesFuture = CmsConfiguration.EnableMultilanguage ? LanguageService.GetLanguagesLookupValues() : null;
            var pagesToFuture   = SitemapHelper.GetPagesToFuture(CmsConfiguration.EnableMultilanguage, Repository);

            IQueryable <Models.Sitemap> sitemapQuery = Repository.AsQueryable <Models.Sitemap>()
                                                       .Where(map => map.Id == sitemapId)
                                                       .FetchMany(map => map.Nodes)
                                                       .ThenFetch(node => node.Page);

            if (CmsConfiguration.EnableMultilanguage)
            {
                sitemapQuery = sitemapQuery
                               .FetchMany(map => map.Nodes)
                               .ThenFetchMany(node => node.Translations);
            }

            var sitemap   = sitemapQuery.Distinct().ToFuture().ToList().First();
            var languages = CmsConfiguration.EnableMultilanguage ? languagesFuture.ToList() : new List <LookupKeyValue>();
            var model     = new SitemapViewModel
            {
                Id        = sitemap.Id,
                Version   = sitemap.Version,
                Title     = sitemap.Title,
                RootNodes =
                    SitemapHelper.GetSitemapNodesInHierarchy(
                        CmsConfiguration.EnableMultilanguage,
                        sitemap.Nodes.Distinct().Where(f => f.ParentNode == null).ToList(),
                        sitemap.Nodes.Distinct().ToList(),
                        languages.Select(l => l.Key.ToGuidOrDefault()).ToList(),
                        (pagesToFuture ?? new List <SitemapHelper.PageData>()).ToList()),
                Tags = tagsFuture.ToList(),
                AccessControlEnabled = CmsConfiguration.Security.AccessControlEnabled,
                ShowLanguages        = CmsConfiguration.EnableMultilanguage && languages.Any(),
                Languages            = languages,
                ShowMacros           = CmsConfiguration.EnableMacros
            };

            if (userAccessFuture != null)
            {
                model.UserAccessList = userAccessFuture.Select(x => new UserAccessViewModel(x)).ToList();

                var rules = model.UserAccessList.Cast <IAccessRule>().ToList();

                SetIsReadOnly(model, rules);
            }

            return(model);
        }
示例#16
0
 public string GetTreeJsonForMenu()
 {
     string[] roles = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);
     SitemapHelper.Roles = roles.ToList();
     return(SitemapHelper.GetTreeJsonForMenu());
 }
示例#17
0
        public GetSitemapTreeResponse Get(GetSitemapTreeRequest request)
        {
            var pagesToFuture        = SitemapHelper.GetPagesToFuture(cmsConfiguration.EnableMultilanguage, repository);
            var translationsToFuture = cmsConfiguration.EnableMultilanguage && request.Data.LanguageId.HasValue
                                           ? repository.AsQueryable <Module.Pages.Models.SitemapNodeTranslation>()
                                       .Where(t => t.Node.Sitemap.Id == request.SitemapId && t.Language.Id == request.Data.LanguageId.Value && !t.IsDeleted && !t.Node.IsDeleted)
                                       .Select(t => new SitemapTreeNodeTranslationModel
            {
                Id             = t.Id,
                Version        = t.Version,
                CreatedBy      = t.CreatedByUser,
                CreatedOn      = t.CreatedOn,
                LastModifiedBy = t.ModifiedByUser,
                LastModifiedOn = t.ModifiedOn,

                NodeId     = t.Node.Id,
                LanguageId = t.Language.Id,
                Title      = t.Title,
                Url        = t.Url,
                UsePageTitleAsNodeTitle = t.UsePageTitleAsNodeTitle,
                Macro = t.Macro
            })
                                       .ToFuture()
                                           : null;

            var allNodes = repository
                           .AsQueryable <Module.Pages.Models.SitemapNode>()
                           .Where(node => node.Sitemap.Id == request.SitemapId && !node.IsDeleted)
                           .OrderBy(node => node.DisplayOrder)
                           .Select(node => new SitemapTreeNodeModel
            {
                Id             = node.Id,
                Version        = node.Version,
                CreatedBy      = node.CreatedByUser,
                CreatedOn      = node.CreatedOn,
                LastModifiedBy = node.ModifiedByUser,
                LastModifiedOn = node.ModifiedOn,

                ParentId                = node.ParentNode != null && !node.ParentNode.IsDeleted ? node.ParentNode.Id : (Guid?)null,
                Title                   = node.Page != null && node.UsePageTitleAsNodeTitle ? node.Page.Title : node.Title,
                Url                     = node.Page != null ? node.Page.PageUrl : node.Url,
                PageId                  = node.Page != null ? node.Page.Id : (Guid?)null,
                PageIsPublished         = node.Page != null && !node.Page.IsDeleted && node.Page.Status == PageStatus.Published,
                UsePageTitleAsNodeTitle = node.UsePageTitleAsNodeTitle,
                DisplayOrder            = node.DisplayOrder,
                Macro                   = node.Macro
            })
                           .ToFuture()
                           .ToList();

            var nodes = GetChildren(allNodes, request.Data.NodeId);

            if (pagesToFuture != null && translationsToFuture != null)
            {
                Translate(nodes, request.Data.LanguageId, translationsToFuture.ToList(), pagesToFuture.ToList());
            }

            return(new GetSitemapTreeResponse {
                Data = nodes
            });
        }