protected string GetPageTemplatePath(OrganizationServiceContext context, Entity entity, Entity website, out string webTemplateId) { webTemplateId = null; 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 pageTemplate = entity.GetRelatedEntity(context, "adx_pagetemplate_event"); if (pageTemplate == null) { return(OrganizationServiceContextExtensions.GetSiteSettingValueByName(context, website, "events/event/templatepath") ?? "~/Pages/Event.aspx"); } if (TryGetWebTemplateId(pageTemplate, out webTemplateId)) { return(pageTemplate.GetAttributeValue <bool?>("adx_usewebsiteheaderandfooter").GetValueOrDefault(true) ? "~/Pages/WebTemplate.aspx" : "~/Pages/WebTemplateNoMaster.aspx"); } return(pageTemplate.GetAttributeValue <string>("adx_rewriteurl") ?? "~/Pages/Event.aspx"); }
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 virtual bool EntityHasPath(OrganizationServiceContext context, Entity entity, string path) { var entityPath = OrganizationServiceContextExtensions.GetApplicationPath(context, entity); if (entityPath == null) { return(false); } return(string.Equals(path, entityPath.PartialPath)); }
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); }
public override SiteMapNode GetParentNode(SiteMapNode node) { var crmNode = node as CrmSiteMapNode; if (crmNode == null) { return(null); } var portal = PortalContext; var context = portal.ServiceContext; var website = portal.Website; var entity = context.MergeClone(crmNode.Entity); if (crmNode.HasCrmEntityName("adx_communityforum")) { var parentPage = entity.GetRelatedEntity(context, "adx_webpage_communityforum"); // If this association doesn't exist, this is an old schema, return the "Forums" page as the parent. if (parentPage == null) { var forumsRootPage = OrganizationServiceContextExtensions.GetPageBySiteMarkerName(context, website, "Forums"); return(SiteMap.Provider.FindSiteMapNode(context.GetUrl(forumsRootPage))); } return(SiteMap.Provider.FindSiteMapNode(context.GetUrl(parentPage))); } if (crmNode.HasCrmEntityName("adx_communityforumthread")) { var parentForum = entity.GetRelatedEntity(context, "adx_communityforum_communityforumthread"); if (parentForum == null) { return(null); } var parentForumNode = GetForumNode(context, parentForum); return(NodeValidator.Validate(context, parentForumNode) ? parentForumNode : null); } return(null); }
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 virtual bool EntityHasPath(OrganizationServiceContext context, Entity entity, string path) { var entityPath = OrganizationServiceContextExtensions.GetApplicationPath(context, entity); if (entityPath == null) { return(false); } var resultPath = entityPath.PartialPath; var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo(); if (contextLanguageInfo.IsCrmMultiLanguageEnabled && ContextLanguageInfo.DisplayLanguageCodeInUrl) { resultPath = contextLanguageInfo.StripLanguageCodeFromAbsolutePath(entityPath.PartialPath); } return(string.Equals(path, resultPath)); }
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); }
private ApplicationPath GetApplicationPathForSiteMarker(OrganizationServiceContext serviceContext, Entity website, IDictionary cache) { if (serviceContext == null || website == null) { return(null); } return(GetApplicationPathForSiteMarker(cache, () => { var page = OrganizationServiceContextExtensions.GetPageBySiteMarkerName(serviceContext, website, SiteMarker); if (page == null) { return null; } var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency <IEntityUrlProvider>(); return urlProvider.GetApplicationPath(serviceContext, page); })); }
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 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)))); }
protected void Page_Load(object sender, EventArgs e) { var reference = Entity.GetAttributeValue <EntityReference>("adx_entityform"); var entityFormRecord = XrmContext.CreateQuery("adx_entityform").FirstOrDefault(ef => ef.GetAttributeValue <Guid>("adx_entityformid") == reference.Id); if (entityFormRecord != null) { var recordEntityLogicalName = entityFormRecord.GetAttributeValue <string>("adx_entityname"); Guid recordId; if (Guid.TryParse(Request["id"], out recordId)) { var metadataRequest = new RetrieveEntityRequest { LogicalName = recordEntityLogicalName, EntityFilters = EntityFilters.Attributes }; var metadataResponse = (RetrieveEntityResponse)XrmContext.Execute(metadataRequest); var primaryFieldLogicalName = metadataResponse.EntityMetadata.PrimaryIdAttribute; var permitRecord = XrmContext.CreateQuery(recordEntityLogicalName).FirstOrDefault(r => r.GetAttributeValue <Guid>(primaryFieldLogicalName) == recordId); var permitTypeReference = permitRecord.GetAttributeValue <EntityReference>("adx_permittype"); var permitType = XrmContext.CreateQuery("adx_permittype").FirstOrDefault( srt => srt.GetAttributeValue <Guid>("adx_permittypeid") == permitTypeReference.Id); var entityName = permitType.GetAttributeValue <string>("adx_entityname"); RegardingContactFieldName = permitType.GetAttributeValue <string>("adx_regardingcontactfieldname"); var trueMetadataRequest = new RetrieveEntityRequest { LogicalName = entityName, EntityFilters = EntityFilters.Attributes }; var trueMetadataResponse = (RetrieveEntityResponse)XrmContext.Execute(trueMetadataRequest); var primaryFieldName = trueMetadataResponse.EntityMetadata.PrimaryIdAttribute; var entityId = permitRecord.GetAttributeValue <string>("adx_entityid"); var trueRecordId = Guid.Parse(entityId); var trueRecord = XrmContext.CreateQuery(entityName).FirstOrDefault(r => r.GetAttributeValue <Guid>(primaryFieldName) == trueRecordId); Permit = trueRecord; var permitDataSource = CreateDataSource("PermitDataSource", entityName, primaryFieldName, trueRecordId); var permitFormView = new CrmEntityFormView() { FormName = "Details Form", Mode = FormViewMode.Edit, EntityName = entityName, CssClass = "crmEntityFormView", AutoGenerateSteps = false }; var languageCodeSetting = OrganizationServiceContextExtensions.GetSiteSettingValueByName(ServiceContext, Portal.Website, "Language Code"); if (!string.IsNullOrWhiteSpace(languageCodeSetting)) { int languageCode; if (int.TryParse(languageCodeSetting, out languageCode)) { permitFormView.LanguageCode = languageCode; permitFormView.ContextName = languageCode.ToString(CultureInfo.InvariantCulture); permitDataSource.CrmDataContextName = languageCode.ToString(CultureInfo.InvariantCulture); } } CrmEntityFormViewPanel.Controls.Add(permitFormView); permitFormView.DataSourceID = permitDataSource.ID; var regardingContact = Permit.GetAttributeValue <EntityReference>(RegardingContactFieldName); if (regardingContact == null || Contact == null || regardingContact.Id != Contact.Id) { PermitControls.Enabled = false; PermitControls.Visible = false; AddNoteInline.Visible = false; AddNoteInline.Enabled = false; } else { var dataAdapterDependencies = new PortalConfigurationDataAdapterDependencies(requestContext: Request.RequestContext, portalName: PortalName); var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies); var annotations = dataAdapter.GetAnnotations(Permit.ToEntityReference(), new List <Order> { new Order("createdon") }, respectPermissions: false); NotesList.DataSource = annotations; NotesList.DataBind(); } } } }