Example #1
0
        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);
        }
        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);
        }
        private CrmSiteMapNode GetWebFileNode(OrganizationServiceContext serviceContext, Entity file, HttpStatusCode statusCode)
        {
            if (file == null)
            {
                return(null);
            }

            var url     = OrganizationServiceContextExtensions.GetUrl(serviceContext, file);
            var name    = file.GetAttributeValue <string>("adx_name");
            var summary = file.GetAttributeValue <string>("adx_summary");

            var fileAttachmentProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency <ICrmEntityFileAttachmentProvider>();

            var attachmentInfo = fileAttachmentProvider.GetAttachmentInfo(serviceContext, file).FirstOrDefault();

            // apply a detached clone of the entity since the SiteMapNode is out of the scope of the current OrganizationServiceContext
            var fileClone = file.Clone(false);

            // If there's no file attached to the webfile, return a NotFound node with no rewrite path.
            if (attachmentInfo == null)
            {
                return(new CrmSiteMapNode(
                           this,
                           url,
                           url,
                           name,
                           summary,
                           null,
                           file.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
                           fileClone,
                           HttpStatusCode.NotFound));
            }

            return(new CrmSiteMapNode(
                       this,
                       url,
                       url,
                       name,
                       summary,
                       attachmentInfo.Url,
                       attachmentInfo.LastModified.GetValueOrDefault(DateTime.UtcNow),
                       file,
                       statusCode));
        }
        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);
        }
        public override SiteMapNode GetParentNode(SiteMapNode node)
        {
            TraceInfo("GetParentNode({0})", node.Key);

            var crmNode = node as CrmSiteMapNode;

            if (crmNode == null || !crmNode.HasCrmEntityName("adx_event"))
            {
                return(null);
            }

            var portal  = PortalContext;
            var context = portal.ServiceContext;

            var entity = context.MergeClone(crmNode.Entity);

            var parentPage = entity.GetRelatedEntity(context, "adx_webpage_event");

            return(SiteMap.Provider.FindSiteMapNode(OrganizationServiceContextExtensions.GetUrl(context, parentPage)));
        }
        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 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 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);
        }
Example #10
0
        protected virtual IEnumerable <SyndicationItem> GetSyndicationItems()
        {
            var portalContext  = PortalCrmConfigurationManager.CreatePortalContext();
            var serviceContext = PortalCrmConfigurationManager.CreateServiceContext();

            var query = from jp in serviceContext.CreateQuery("adx_jobposting")
                        where jp.GetAttributeValue <EntityReference>("adx_websiteid") == portalContext.Website.ToEntityReference()
                        where jp.GetAttributeValue <OptionSetValue>("statecode") != null && jp.GetAttributeValue <OptionSetValue>("statecode").Value == 0
                        orderby jp.GetAttributeValue <DateTime?>("adx_name")
                        select jp;

            var postings = query.ToArray().Where(e => IsOpen(e.GetAttributeValue <DateTime?>("adx_closingon")));

            var applicationPage    = OrganizationServiceContextExtensions.GetPageBySiteMarkerName(portalContext.ServiceContext, portalContext.Website, "Job Application");
            var applicationPageUrl = applicationPage == null ? null : OrganizationServiceContextExtensions.GetUrl(portalContext.ServiceContext, applicationPage);

            return(postings.Select(posting => new SyndicationItem(
                                       posting.GetAttributeValue <string>("adx_name"),
                                       SyndicationContent.CreateHtmlContent(posting.GetAttributeValue <string>("adx_description")),
                                       GetSyndicationItemUri(portalContext, applicationPageUrl, posting),
                                       posting.GetAttributeValue <Guid>("adx_jobpostingid").ToString(),
                                       posting.GetAttributeValue <DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow))));
        }