protected CrmSiteMapNode GetForumThreadNode(OrganizationServiceContext context, Entity thread) { thread.AssertEntityName("adx_communityforumthread"); var forum = thread.GetRelatedEntity(context, "adx_communityforum_communityforumthread"); var forumThreadId = thread.GetAttributeValue <Guid>("adx_communityforumthreadid"); var url = OrganizationServiceContextExtensions.GetUrl(context, forum) + "/" + forumThreadId; var threadClone = thread.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, url, url, thread.GetAttributeValue <string>("adx_name"), thread.GetAttributeValue <string>("adx_name"), GetForumThreadPageTemplatePath(context, forum, out webTemplateId) + "?id=" + forumThreadId, thread.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), threadClone); if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
public static Entity AttachTo(this CrmSiteMapNode node, OrganizationServiceContext context, bool includeRelatedEntities = false) { if (node == null) { return(null); } return(MergeClone(context, node.Entity, includeRelatedEntities)); }
protected virtual CrmSiteMapNode GetNode(ContentMap map, WebPageNode webPageNode, HttpStatusCode statusCode, IContentMapEntityUrlProvider provider, bool includeReturnUrl = false) { var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo(); WebPageNode GetLanguageNode() { ADXTrace.Instance.TraceInfo(TraceCategory.Monitoring, string.Format("SiteMapProvider.GetNode Lang:{0} ", webPageNode.IsRoot != false ? "root" : webPageNode.WebPageLanguage.PortalLanguage.Code)); var languageNode = webPageNode.LanguageContentPages.FirstOrDefault(p => p.WebPageLanguage.PortalLanguage.Code == contextLanguageInfo.ContextLanguage.Code); return(languageNode ?? webPageNode); } var page = contextLanguageInfo.IsCrmMultiLanguageEnabled ? GetLanguageNode() : webPageNode; var template = page.PageTemplate; if (template == null) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Web Page with id '{0}' does not have the required Page Template.", page.Id)); return(null); } var returnUrl = includeReturnUrl && HttpContext.Current != null ? "&ReturnUrl={0}".FormatWith(System.Web.Security.AntiXss.AntiXssEncoder.UrlEncode(HttpContext.Current.Request.Url.PathAndQuery)) : string.Empty; var rewriteUrl = template.Type == (int)PageTemplateNode.TemplateType.WebTemplate && template.WebTemplateId != null ? template.UseWebsiteHeaderAndFooter.GetValueOrDefault(true) ? "~/Pages/WebTemplate.aspx" : "~/Pages/WebTemplateNoMaster.aspx" : template.RewriteUrl; var entity = page.ToEntity(GetEntityType("adx_webpage")); var url = provider.GetUrl(map, page); var node = new CrmSiteMapNode( this, url, url, !string.IsNullOrWhiteSpace(page.Title) ? page.Title : page.Name, page.Summary, "{0}?pageid={1}{2}".FormatWith(rewriteUrl, page.Id, returnUrl), page.ModifiedOn.GetValueOrDefault(DateTime.UtcNow), entity, statusCode); if (template.WebTemplateId != null) { node["adx_webtemplateid"] = template.WebTemplateId.Id.ToString(); } return(node); }
protected override CrmSiteMapNode GetNode(OrganizationServiceContext context, Entity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } if (entity.LogicalName != "adx_event") { throw new ArgumentException("Entity {0} ({1}) is not of a type supported by this provider.".FormatWith(entity.Id, entity.GetType().FullName), "entity"); } var url = OrganizationServiceContextExtensions.GetUrl(context, entity); var portal = PortalContext; var serviceContext = portal.ServiceContext; var website = portal.Website; var eventId = entity.GetAttributeValue <Guid>("adx_eventid"); var eventsInCurrentWebsite = serviceContext.CreateQuery("adx_event") .Where(e => e.GetAttributeValue <EntityReference>("adx_websiteid") == website.ToEntityReference()) .ToArray(); var webEvent = eventsInCurrentWebsite .SingleOrDefault(e => e.GetAttributeValue <Guid>("adx_eventid") == eventId); // apply a detached clone of the entity since the SiteMapNode is out of the scope of the current OrganizationServiceContext var webEventClone = webEvent.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, url, url, entity.GetAttributeValue <string>("adx_name"), entity.GetAttributeValue <string>("adx_description"), GetPageTemplatePath(serviceContext, entity, website, out webTemplateId) + "?id=" + eventId, entity.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), webEventClone); if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetBlogPostNode(OrganizationServiceContext serviceContext, Entity entity) { entity.AssertEntityName("adx_blogpost"); var portal = PortalContext; var website = portal.Website.ToEntityReference(); var post = serviceContext.IsAttached(entity) ? entity : GetBlogPost(serviceContext, entity.Id); if (post == null || post.GetAttributeValue <EntityReference>("adx_blogid") == null) { return(null); } var pageTemplateQuery = from p in serviceContext.CreateQuery("adx_pagetemplate") join b in serviceContext.CreateQuery("adx_blog") on p.GetAttributeValue <Guid>("adx_pagetemplateid") equals b.GetAttributeValue <EntityReference>("adx_blogpostpagetemplateid").Id where b.GetAttributeValue <EntityReference>("adx_blogpostpagetemplateid") != null && b.GetAttributeValue <Guid>("adx_blogid") == post.GetAttributeValue <EntityReference>("adx_blogid").Id where p.GetAttributeValue <EntityReference>("adx_websiteid") == website select p; var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, post); var pageTemplate = pageTemplateQuery.FirstOrDefault(); var postClone = post.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, url, url, post.GetAttributeValue <string>("adx_name"), post.GetAttributeValue <string>("adx_summary"), GetRewriteUrl(pageTemplate, out webTemplateId), post.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), postClone); if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetBlogTagArchiveNode(OrganizationServiceContext serviceContext, Entity entity, string tagSlug) { entity.AssertEntityName("adx_blog"); var portal = PortalContext; var website = portal.Website.ToEntityReference(); var blog = serviceContext.IsAttached(entity) && Equals(entity.GetAttributeValue <EntityReference>("adx_websiteid"), website) ? entity : GetBlog(serviceContext, website, entity.Id); if (blog == null) { return(null); } var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, blog); var tagUrl = "{0}{1}{2}".FormatWith(url, url.EndsWith("/") ? string.Empty : "/", tagSlug); var tag = HttpUtility.UrlDecode(tagSlug).Trim(); var blogClone = blog.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, tagUrl, tagUrl, tag, blog.GetAttributeValue <string>("adx_summary"), GetBlogArchiveRewriteUrl(serviceContext, entity, out webTemplateId), blog.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), blogClone); node[TagArchiveNodeAttributeKey] = tag; if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetBlogNode(OrganizationServiceContext serviceContext, Entity entity) { entity.AssertEntityName("adx_blog"); var portal = PortalContext; var website = portal.Website.ToEntityReference(); var blog = serviceContext.IsAttached(entity) && Equals(entity.GetAttributeValue <EntityReference>("adx_websiteid"), website) ? entity : GetBlog(serviceContext, website, entity.Id); if (blog == null) { return(null); } var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, blog); var pageTemplate = blog.GetRelatedEntity(serviceContext, "adx_pagetemplate_blog_home"); // apply a detached clone of the entity since the SiteMapNode is out of the scope of the current OrganizationServiceContext var blogClone = blog.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, url, url, blog.GetAttributeValue <string>("adx_name"), blog.GetAttributeValue <string>("adx_summary"), GetRewriteUrl(pageTemplate, out webTemplateId), blog.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), blogClone); if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetBlogMonthArchiveNode(OrganizationServiceContext serviceContext, Entity entity, DateTime month) { entity.AssertEntityName("adx_blog"); var portal = PortalContext; var website = portal.Website.ToEntityReference(); var blog = serviceContext.IsAttached(entity) && Equals(entity.GetAttributeValue <EntityReference>("adx_websiteid"), website) ? entity : GetBlog(serviceContext, website, entity.Id); if (blog == null) { return(null); } var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, blog); var archiveUrl = "{0}{1}{2:yyyy}/{2:MM}/".FormatWith(url, url.EndsWith("/") ? string.Empty : "/", month); var blogClone = blog.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, archiveUrl, archiveUrl, month.ToString("y", CultureInfo.CurrentCulture), blog.GetAttributeValue <string>("adx_summary"), GetBlogArchiveRewriteUrl(serviceContext, entity, out webTemplateId), blog.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), blogClone); node[MonthArchiveNodeAttributeKey] = month.ToString("o", CultureInfo.InvariantCulture); if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetForumNode(OrganizationServiceContext context, Entity forum) { forum.AssertEntityName("adx_communityforum"); var website = HttpContext.Current.GetWebsite().Entity; var forumId = forum.GetAttributeValue <Guid>("adx_communityforumid"); var forumsInCurrentWebsite = context.RetrieveMultiple( "adx_communityforum", new string [] { }, new[] { new Condition("adx_websiteid", ConditionOperator.Equal, website.Id) }); var webForum = forumsInCurrentWebsite.Entities .SingleOrDefault(f => f.GetAttributeValue <Guid>("adx_communityforumid") == forumId); // apply a detached clone of the entity since the SiteMapNode is out of the scope of the current OrganizationServiceContext var webForumClone = webForum.Clone(false); string webTemplateId; var url = context.GetUrl(forum); var node = new CrmSiteMapNode( this, url, url, forum.GetAttributeValue <string>("adx_name"), forum.GetAttributeValue <string>("adx_description"), GetForumPageTemplatePath(context, forum, out webTemplateId) + "?id=" + forumId, forum.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), webForumClone); if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetBlogAggregationAuthorArchiveNode(OrganizationServiceContext serviceContext, Entity entity, Guid authorId) { entity.AssertEntityName("adx_webpage"); var portal = PortalContext; var website = portal.Website.ToEntityReference(); var page = serviceContext.IsAttached(entity) && Equals(entity.GetAttributeValue <EntityReference>("adx_websiteid"), website) ? entity : GetPage(serviceContext, website, entity.Id); var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, page); var archiveUrl = "{0}{1}author/{2}/".FormatWith(url, url.EndsWith("/") ? string.Empty : "/", authorId); var pageTemplate = page.GetRelatedEntity(serviceContext, "adx_pagetemplate_webpage"); var pageClone = page.Clone(false); string webTemplateId; var node = new CrmSiteMapNode( this, archiveUrl, archiveUrl, GetBlogAuthorName(serviceContext, authorId), page.GetAttributeValue <string>("adx_summary"), GetRewriteUrl(pageTemplate, out webTemplateId), page.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), pageClone); node[AuthorArchiveNodeAttributeKey] = authorId.ToString(); node["IsAggregationArchiveNode"] = "true"; if (webTemplateId != null) { node["adx_webtemplateid"] = webTemplateId; } return(node); }
protected CrmSiteMapNode GetShortcutCrmNode(OrganizationServiceContext serviceContext, Entity shortcut, CrmSiteMapNode targetNode) { if (shortcut == null) { throw new ArgumentNullException("shortcut"); } if (shortcut.LogicalName != "adx_shortcut") { throw new ArgumentException("Entity {0} ({1}) is not of a type supported by this provider.".FormatWith(shortcut.Id, shortcut.GetType().FullName), "shortcut"); } var url = !string.IsNullOrEmpty(shortcut.GetAttributeValue <string>("adx_externalurl")) ? shortcut.GetAttributeValue <string>("adx_externalurl") : serviceContext.GetUrl(shortcut); // Node does not have a valid URL, and should be filtered out of the sitemap. if (string.IsNullOrEmpty(url)) { return(null); } var shortcutDescription = shortcut.GetAttributeValue <string>("adx_description"); var description = !string.IsNullOrEmpty(shortcutDescription) ? shortcutDescription : targetNode != null ? targetNode.Description : string.Empty; return(new CrmSiteMapNode( this, url, url, shortcut.GetAttributeValue <string>("adx_title") ?? shortcut.GetAttributeValue <string>("adx_name"), description, targetNode != null ? targetNode.RewriteUrl : url, shortcut.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow), shortcut)); }
protected virtual bool TryGetBlogPostNodeByPartialUrl(OrganizationServiceContext serviceContext, EntityReference website, string path, out CrmSiteMapNode node) { node = null; Entity postWithMatchingPath; if (TryGetBlogPostByPartialUrl(serviceContext, website, path, out postWithMatchingPath)) { node = GetAccessibleNodeOrAccessDeniedNode(serviceContext, postWithMatchingPath); return(true); } return(false); }
protected virtual bool TryGetBlogPostNodeById(OrganizationServiceContext serviceContext, EntityReference website, string path, out CrmSiteMapNode node) { node = null; var pathMatch = PathRegex.Match(path); if (!pathMatch.Success) { return(false); } Guid postId; // If the right-most path segment is a Guid, try look up a post by that ID. Posts can have // their partial URL be a their ID, as the adx_partialurl attribute is not required. if (!Guid.TryParse(pathMatch.Groups["right"].Value, out postId)) { return(false); } var filter = new Filter { Conditions = new[] { new Condition("adx_websiteid", ConditionOperator.Equal, website.Id) } }; var languageInfo = HttpContext.Current.GetContextLanguageInfo(); var mlpFilter = new Filter(); if (languageInfo.IsCrmMultiLanguageEnabled) { mlpFilter.Type = LogicalOperator.Or; mlpFilter.Conditions = new[] { new Condition("adx_websitelanguageid", ConditionOperator.Null), new Condition("adx_websitelanguageid", ConditionOperator.Equal, languageInfo.ContextLanguage.EntityReference.Id) }; } var fetch = new Fetch { Entity = new FetchEntity("adx_blogpost") { Filters = new[] { new Filter { Conditions = new[] { new Condition("adx_blogid", ConditionOperator.NotNull), new Condition("adx_blogpostid", ConditionOperator.Equal, postId) } } }, Links = new[] { new Link { Name = "adx_blog", ToAttribute = "adx_blogid", FromAttribute = "adx_blogid", Filters = new[] { filter, mlpFilter } } } } }; var posts = serviceContext.RetrieveMultiple(fetch); var postWithMatchingPath = posts.Entities.FirstOrDefault(e => this.EntityHasPath(serviceContext, e, path)); if (postWithMatchingPath != null) { node = this.GetAccessibleNodeOrAccessDeniedNode(serviceContext, postWithMatchingPath); return(true); } return(false); }
protected virtual bool TryGetBlogNodeByPartialUrl(OrganizationServiceContext serviceContext, EntityReference website, string path, out CrmSiteMapNode node) { node = null; var pathMatch = PathRegex.Match(path); if (!pathMatch.Success) { return(false); } var filter = new Filter { Conditions = new[] { new Condition("adx_websiteid", ConditionOperator.Equal, website.Id), new Condition("adx_partialurl", ConditionOperator.Equal, pathMatch.Groups["right"].Value) } }; var languageInfo = HttpContext.Current.GetContextLanguageInfo(); var mlpFilter = new Filter(); if (languageInfo.IsCrmMultiLanguageEnabled) { mlpFilter.Type = LogicalOperator.Or; mlpFilter.Conditions = new[] { new Condition("adx_websitelanguageid", ConditionOperator.Null), new Condition("adx_websitelanguageid", ConditionOperator.Equal, languageInfo.ContextLanguage.EntityReference.Id) }; } var fetch = new Fetch { Entity = new FetchEntity("adx_blog") { Filters = new[] { filter, mlpFilter } } }; var blogs = serviceContext.RetrieveMultiple(fetch); var blogWithMatchingPath = blogs.Entities.FirstOrDefault(e => this.EntityHasPath(serviceContext, e, path)); if (blogWithMatchingPath != null) { node = this.GetAccessibleNodeOrAccessDeniedNode(serviceContext, blogWithMatchingPath); return(true); } return(false); }
/// <summary> /// Method to process the node of the current request and save tracking info. /// </summary> private static void LogRequest(CrmSiteMapNode node, string ipAddress, Entity user) { if (node == null) { return; } if (node.StatusCode != HttpStatusCode.OK) { return; //possbily put 404 tracking in here? } var context = CrmConfigurationManager.CreateContext(); switch (node.Entity.LogicalName) { case "adx_webpage": var webpage = context.CreateQuery("adx_webpage").FirstOrDefault(w => w.GetAttributeValue <Guid>("adx_webpageid") == node.Entity.Id); if (webpage != null && (webpage.GetAttributeValue <bool?>("adx_enabletracking") ?? false)) { var webpagelog = new Entity("adx_webpagelog"); webpagelog.SetAttributeValue("adx_name", webpage.GetAttributeValue <string>("adx_name") + " log"); webpagelog.SetAttributeValue("adx_date", DateTime.UtcNow); webpagelog.SetAttributeValue("adx_ipaddress", ipAddress); context.AddObject(webpagelog); context.AddLink(webpagelog, "adx_webpage_webpagelog".ToRelationship(), webpage); if (user != null) { var contact = context.CreateQuery("contact").FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == user.Id); if (contact != null) { context.AddLink(webpagelog, "adx_contact_webpagelog".ToRelationship(), contact); } } context.SaveChanges(); } break; case "adx_webfile": var webfile = context.CreateQuery("adx_webfile").FirstOrDefault(w => w.GetAttributeValue <Guid>("adx_webfileid") == node.Entity.Id); if (webfile != null && (webfile.GetAttributeValue <bool?>("adx_enabletracking") ?? false)) { var webfilelog = new Entity("adx_webfilelog"); webfilelog.SetAttributeValue("adx_name", webfile.GetAttributeValue <string>("adx_name") + " log"); webfilelog.SetAttributeValue("adx_date", DateTime.UtcNow); webfilelog.SetAttributeValue("adx_ipaddress", ipAddress); context.AddObject(webfilelog); context.AddLink(webfilelog, "adx_webfile_webfilelog".ToRelationship(), webfile); if (user != null) { var contact = context.CreateQuery("contact").FirstOrDefault(c => c.GetAttributeValue <Guid>("contactid") == user.Id); if (contact != null) { context.AddLink(webfilelog, "adx_contact_webfilelog".ToRelationship(), contact); } } context.SaveChanges(); } break; } }
protected virtual bool TryGetTagArchiveNode(OrganizationServiceContext serviceContext, EntityReference website, string path, out CrmSiteMapNode node) { node = null; var pathMatch = TagArchivePathRegex.Match(path); if (!pathMatch.Success) { return(false); } var archiveRootPath = Regex.Replace(path, @"tags/[^/]+$", string.Empty); var tagSlug = pathMatch.Groups["tag"].Value; var blogAggregationArchivePageQuery = from page in serviceContext.CreateQuery("adx_webpage") join siteMarker in serviceContext.CreateQuery("adx_sitemarker") on page.GetAttributeValue <Guid>("adx_webpageid") equals siteMarker.GetAttributeValue <EntityReference>("adx_pageid").Id where siteMarker.GetAttributeValue <EntityReference>("adx_pageid") != null && siteMarker.GetAttributeValue <string>("adx_name") == AggregationArchiveSiteMarkerName where page.GetAttributeValue <EntityReference>("adx_websiteid") == website select page; var blogAggregationArchivePageMatch = blogAggregationArchivePageQuery.ToArray().FirstOrDefault(e => EntityHasPath(serviceContext, e, archiveRootPath)); if (blogAggregationArchivePageMatch != null) { node = GetBlogAggregationTagArchiveNode(serviceContext, blogAggregationArchivePageMatch, tagSlug); return(true); } var blogsByTagArchivePathMatch = from blog in serviceContext.CreateQuery("adx_blog") where blog.GetAttributeValue <EntityReference>("adx_websiteid") == website where blog.GetAttributeValue <string>("adx_partialurl") == pathMatch.Groups["blog"].Value select blog; var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo(); if (contextLanguageInfo.IsCrmMultiLanguageEnabled) { blogsByTagArchivePathMatch = blogsByTagArchivePathMatch.Where( blog => blog.GetAttributeValue <EntityReference>("adx_websitelanguageid") == null || blog.GetAttributeValue <EntityReference>("adx_websitelanguageid").Id == contextLanguageInfo.ContextLanguage.EntityReference.Id); } var blogByTagArchivePath = blogsByTagArchivePathMatch.ToArray().FirstOrDefault(e => EntityHasPath(serviceContext, e, archiveRootPath)); if (blogByTagArchivePath != null) { node = GetBlogTagArchiveNode(serviceContext, blogByTagArchivePath, tagSlug); return(true); } return(false); }
private static Entity GetEntity(OrganizationServiceContext context, CrmSiteMapNode node) { return(context.MergeClone(node.Entity)); }
protected virtual bool TryGetWebFileNode(OrganizationServiceContext serviceContext, EntityReference website, string path, out CrmSiteMapNode node) { node = null; var pathMatch = WebFilePathRegex.Match(path); if (!pathMatch.Success) { return(false); } var contentMapProvider = HttpContext.Current.GetContentMapProvider(); IDictionary <EntityReference, EntityNode> webfiles = new Dictionary <EntityReference, EntityNode>(); contentMapProvider.Using(map => map.TryGetValue("adx_webfile", out webfiles)); var files = webfiles.Values.Cast <WebFileNode>() .Where(wf => wf.BlogPost != null && wf.PartialUrl.Equals(pathMatch.Groups["file"].Value) && wf.StateCode == 0); if (!files.Any()) { return(false); } Entity blogPost; if (TryGetBlogPostByPartialUrl(serviceContext, website, pathMatch.Groups["post"].Value, out blogPost)) { var file = files.FirstOrDefault(f => { var blogPostReference = f.BlogPost; return(blogPostReference != null && blogPostReference.Equals(blogPost.ToEntityReference())); }); if (file != null) { var entity = serviceContext.MergeClone(file.ToEntity()); node = GetWebFileNode(serviceContext, entity, HttpStatusCode.OK); return(true); } } return(false); }