Microsoft.Xrm.Sdk.Entity.GetAttributeValue(string)

Here are the examples of the csharp api Microsoft.Xrm.Sdk.Entity.GetAttributeValue(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

748 Examples 7

19 View Source File : CrmSessionHistoryProvider.cs
License : MIT License
Project Creator : Adoxio

public Guid PersistSessionHistory(OrganizationServiceContext context, SessionHistory sessionHistory)
		{
			if (sessionHistory == null)
			{
				return Guid.Empty;
			}

			var webFormSession = sessionHistory.Id != Guid.Empty ? context.CreateQuery("adx_webformsession").FirstOrDefault(s => s.GetAttributeValue<OptionSetValue>("statecode") != null && s.GetAttributeValue<OptionSetValue>("statecode").Value == 0 && s.GetAttributeValue<Guid>("adx_webformsessionid") == sessionHistory.Id) : null;

			var addNew = webFormSession == null;

			if (addNew)
			{
				webFormSession = new Enreplacedy("adx_webformsession");

				if (sessionHistory.WebFormId != Guid.Empty)
				{
					webFormSession.Attributes["adx_webform"] = new EnreplacedyReference("adx_webform", sessionHistory.WebFormId);
				}
			}

			if (sessionHistory.PrimaryRecord != null && sessionHistory.PrimaryRecord.ID != Guid.Empty)
			{
				webFormSession.Attributes["adx_primaryrecordid"] = sessionHistory.PrimaryRecord.ID.ToString();
			}

			if (sessionHistory.CurrentStepId != Guid.Empty)
			{
				webFormSession.Attributes["adx_currentwebformstep"] = new EnreplacedyReference("adx_webformstep", sessionHistory.CurrentStepId);
			}

			if (sessionHistory.PrimaryRecord != null && !string.IsNullOrWhiteSpace(sessionHistory.PrimaryRecord.LogicalName))
			{
				webFormSession.Attributes["adx_primaryrecordenreplacedylogicalname"] = sessionHistory.PrimaryRecord.LogicalName;
			}

			if (sessionHistory.PrimaryRecord != null && !string.IsNullOrWhiteSpace(sessionHistory.PrimaryRecord.PrimaryKeyLogicalName))
			{
				webFormSession.Attributes["adx_primaryrecordenreplacedykeyname"] = sessionHistory.PrimaryRecord.PrimaryKeyLogicalName;
			}

			webFormSession.Attributes["adx_currentstepindex"] = sessionHistory.CurrentStepIndex;

			if (sessionHistory.ContactId != Guid.Empty)
			{
				webFormSession.Attributes["adx_contact"] = new EnreplacedyReference("contact", sessionHistory.ContactId);
			}

			if (sessionHistory.QuoteId != Guid.Empty)
			{
				webFormSession.Attributes["adx_quoteid"] = new EnreplacedyReference("quote", sessionHistory.QuoteId);
			}

			if (sessionHistory.SystemUserId != Guid.Empty)
			{
				webFormSession.Attributes["adx_systemuser"] = new EnreplacedyReference("systemuser", sessionHistory.SystemUserId);
			}

			if (!string.IsNullOrWhiteSpace(sessionHistory.AnonymousIdentification))
			{
				webFormSession.Attributes["adx_anonymousidentification"] = sessionHistory.AnonymousIdentification;
			}

			webFormSession.Attributes["adx_stephistory"] = ConvertListToJsonString(sessionHistory.StepHistory);

			if (!string.IsNullOrWhiteSpace(sessionHistory.UserHostAddress))
			{
				webFormSession.Attributes["adx_userhostaddress"] = sessionHistory.UserHostAddress;
			}

			if (!string.IsNullOrWhiteSpace(sessionHistory.UserIdenreplacedyName))
			{
				webFormSession.Attributes["adx_useridenreplacedyname"] = sessionHistory.UserIdenreplacedyName;
			}
			
			if (addNew)
			{
				context.AddObject(webFormSession);
			}
			else
			{
				context.UpdateObject(webFormSession);
			}

			context.SaveChanges();

			return webFormSession.Id;
		}

19 View Source File : CmsEntityEditingMetadataProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual void AddEnreplacedyMetadata(ICmsEnreplacedyEditingMetadataContainer container, EnreplacedyReference enreplacedyReference, IPortalContext portal, bool addSiteMapNodeMetadata, string portalName = null, string enreplacedyDisplayName = null)
		{
			if (container == null)
			{
				throw new ArgumentNullException("container");
			}

			if (enreplacedyReference == null)
			{
				throw new ArgumentNullException("enreplacedyReference");
			}

			if (portal == null)
			{
				throw new ArgumentNullException("portal");
			}

			container.AddLabel(enreplacedyDisplayName ?? enreplacedyReference.Name);
			container.AddAttribute("data-xrm-base", VirtualPathUtility.ToAbsolute("~/xrm-adx/"));
			container.AddAttribute("data-logicalname", enreplacedyReference.LogicalName);
			container.AddAttribute("data-id", enreplacedyReference.Id.ToString());

			AddRouteServiceReferenceAttribute(container, "data-parentoptions", "CmsParent_GetParentOptions", new
			{
				__portalScopeId__ = portal.Website.Id
			});

			container.AddAttribute("data-parentoptions-uritemplate", VirtualPathUtility.ToAbsolute(CmsParentController.GetAppRelativePathTemplate(portal.Website.Id, "LogicalName", "Id")));

			portalName = portalName ?? PortalName;

			var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(portalName);
			var enreplacedy = GetEnreplacedy(serviceContext, enreplacedyReference);

			AddEnreplacedyTemplateServiceReference(container, portal, enreplacedyReference);
			AddFileBrowserServiceReference(container, portal, FileBrowserDirectoryEnreplacedyNames.Contains(enreplacedy.LogicalName));

			if (enreplacedyReference.LogicalName == "adx_weblinkset")
			{
				// Output the service reference for the web link set itself.
				AddEnreplacedyServiceReference(container, portal, enreplacedyReference, enreplacedyDisplayName ?? enreplacedy.GetAttributeValue<string>("adx_name"));

				// Output the service reference for the child web links of the set.
				AddEnreplacedyRelationshipServiceReference(container, portal, enreplacedyReference, new Relationship("adx_weblinkset_weblink"));
				AddEnreplacedyRelationshipServiceReference(container, portal, enreplacedyReference, new Relationship("adx_weblinkset_weblink"), "xrm-enreplacedy-{0}-update-ref");

				AddEnreplacedyDeleteServiceReferenceTemplate(container, portal, "adx_weblink");

				// Output the service reference and schema map for site web pages (required to create new web links).
				AddEnreplacedySetServiceReference(container, portal, "adx_webpage");

				// Output the service reference and schema map for site publishing states (required to create new web links).
				AddEnreplacedySetServiceReference(container, portal, "adx_publishingstate");

				return;
			}

			var allEnreplacedies = GetEnreplacedyDictionary(serviceContext);

			AddEnreplacedyServiceReference(container, portal, enreplacedyReference);
			AddEnreplacedyUrlServiceReference(container, portal, enreplacedyReference);

			// If the enreplacedy is deletable, add a service reference for delete of the enreplacedy. 
			if (DeletableEnreplacedyNames.Contains(enreplacedyReference.LogicalName))
			{
				AddEnreplacedyDeleteServiceReference(container, portal, enreplacedyReference);
			}

			if (FileAttachmentEnreplacedyNames.Contains(enreplacedyReference.LogicalName))
			{
				AddEnreplacedyFileAttachmentServiceReference(container, portal, enreplacedyReference);
			}

			// Add the service references on which the creation of various enreplacedies are dependent.
			foreach (var dependencyEnreplacedyName in DependencyEnreplacedyNames)
			{
				AddEnreplacedySetServiceReference(container, portal, dependencyEnreplacedyName);
			}

			// Add the service reference URI Templates for the notes replacedociated with given enreplacedy types.
			foreach (var fileAttachmentEnreplacedy in FileAttachmentEnreplacedyNames)
			{
				AddEnreplacedyFileAttachmentServiceReferenceTemplate(container, portal, fileAttachmentEnreplacedy);
			}

			// Add the service reference URI Templates for getting URLs for specific enreplacedy types.
			foreach (var urlEnreplacedyName in UrlEnreplacedyNames.Where(enreplacedyName => EnreplacedyNameExistsInSchema(enreplacedyName, allEnreplacedies)))
			{
				AddEnreplacedyUrlServiceReferenceTemplate(container, portal, urlEnreplacedyName);
			}

			IEnumerable<Relationship> childRelationships;

			if (ChildRelationshipsByEnreplacedyName.TryGetValue(enreplacedyReference.LogicalName, out childRelationships))
			{
				foreach (var relationship in childRelationships.Where(relationship => RelationshipExistsInSchema(relationship, allEnreplacedies)))
				{
					AddEnreplacedyRelationshipServiceReference(container, portal, enreplacedyReference, relationship);
				}
			}

			var previewPermission = new PreviewPermission(portal.ServiceContext, portal.Website);

			if (previewPermission.IsPermitted)
			{
				container.AddPreviewPermittedMetadata();
			}

			Relationship parentalRelationship;

			// Output the URL path of parent enreplacedy to the DOM (mostly to be read if the enreplacedy is deleted--the user
			// will then be redirected to the parent).
			if (ParentalRelationshipsByEnreplacedyName.TryGetValue(enreplacedyReference.LogicalName, out parentalRelationship))
			{
				var parent = enreplacedy.GetRelatedEnreplacedy(serviceContext, parentalRelationship);

				var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(portalName).GetDependency<IEnreplacedyUrlProvider>();

				var parentPath = urlProvider.GetApplicationPath(serviceContext, parent ?? enreplacedy);

				if (parentPath != null)
				{
					AddServiceReference(container, parentPath.AbsolutePath, "xrm-adx-enreplacedy-parent-url-ref");
				}
			}

			// Output the sitemarkers of the current web page into the DOM.
			if (enreplacedyReference.LogicalName == "adx_webpage")
			{
				foreach (var siteMarker in enreplacedy.GetRelatedEnreplacedies(serviceContext, "adx_webpage_sitemarker"))
				{
					container.AddSiteMarkerMetadata(enreplacedyReference.LogicalName, siteMarker.GetAttributeValue<string>("adx_name"));
				}

				if (EnreplacedyNameExistsInSchema("adx_communityforum", allEnreplacedies))
				{
					AddEnreplacedySetServiceReference(container, portal, "adx_communityforum");
				}

				if (EnreplacedyNameExistsInSchema("adx_event", allEnreplacedies))
				{
					AddEnreplacedySetServiceReference(container, portal, "adx_event");
				}

				if (EnreplacedyNameExistsInSchema("adx_enreplacedyform", allEnreplacedies))
				{
					AddEnreplacedySetServiceReference(container, portal, "adx_enreplacedyform");
				}

				if (EnreplacedyNameExistsInSchema("adx_enreplacedylist", allEnreplacedies))
				{
					AddEnreplacedySetServiceReference(container, portal, "adx_enreplacedylist");
				}

				if (EnreplacedyNameExistsInSchema("adx_webform", allEnreplacedies))
				{
					AddEnreplacedySetServiceReference(container, portal, "adx_webform");
				}

				if (EnreplacedyNameExistsInSchema("adx_weblinkset", allEnreplacedies))
				{
					AddEnreplacedySetServiceReference(container, portal, "adx_weblinkset");
				}

				AddEnreplacedySetServiceReference(container, portal, "adx_webpage");
				AddEnreplacedySetServiceReference(container, portal, "adx_webfile");
				
				AddPublishingStateSetServiceReference(container, portal);

				AddPicklistMetadata(container, serviceContext, "adx_webpage", "adx_feedbackpolicy");

				AddEnreplacedyRelationshipServiceReferenceTemplate(container, portal, "adx_webpage", "adx_webpage_navigation_weblinkset".ToRelationship());

				if (enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_parentpageid") == null && string.Equals(enreplacedy.GetAttributeValue<string>("adx_partialurl"), "/", StringComparison.OrdinalIgnoreCase))
				{
					container.AddAttribute("data-root", "true");
				}

				var langContext = HttpContext.Current.GetContextLanguageInfo();

				// For multi language portals, add root webpage id to the dom
				if (langContext.IsCrmMultiLanguageEnabled)
				{
					//add language information
					container.AddAttribute("data-languagename", langContext.ContextLanguage.Name);
					container.AddAttribute("data-languageid", langContext.ContextLanguage.EnreplacedyReference.Id.ToString());
					
					var rootPageReference = portal.Enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_rootwebpageid");
					
					if (rootPageReference != null)
					{
						container.AddAttribute("data-rootwebpageid", rootPageReference.Id.ToString());
					}
					else
					{
						ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Root page for current content page is null, id ={0}", enreplacedyReference.Id));
					}
				}
			}

			if (enreplacedyReference.LogicalName == "adx_event")
			{
				AddPicklistMetadata(container, serviceContext, "adx_eventschedule", "adx_recurrence");
				AddPicklistMetadata(container, serviceContext, "adx_eventschedule", "adx_week");
			}

			if (addSiteMapNodeMetadata && SiteMapChildEnreplacediesByEnreplacedyName.ContainsKey(enreplacedyReference.LogicalName))
			{
				container.AddCssClreplaced("xrm-editable-sitemapchildren");

				AddEnreplacedyChildrenServiceReference(container, portal, enreplacedyReference, "xrm-enreplacedy-ref-sitemapchildren", GetEnreplacedyName(enreplacedy));

				AddSiteMapNodeMetadata(container, enreplacedyReference, portal, portalName);
			}

			if (enreplacedyReference.LogicalName == "adx_blog" || enreplacedyReference.LogicalName == "adx_webpage")
			{
				AddPicklistMetadata(container, serviceContext, "adx_blog", "adx_commentpolicy");
			}

			if (enreplacedyReference.LogicalName == "adx_blog" || enreplacedyReference.LogicalName == "adx_blogpost")
			{
				AddPicklistMetadata(container, serviceContext, "adx_blogpost", "adx_commentpolicy");

				var tags = GetWebsiteTags(portal, serviceContext);

				AddTagMetadata(container, "adx_blogpost", tags);
			}

			if (enreplacedyReference.LogicalName == "adx_communityforumthread")
			{
				AddEnreplacedySetServiceReference(container, portal, "adx_forumthreadtype");

				var tags = GetWebsiteTags(portal, serviceContext);

				AddTagMetadata(container, "adx_communityforumthread", tags);
			}

			AddPicklistMetadata(container, serviceContext, "adx_webfile", "adx_contentdisposition");
			AddEnreplacedySetServiceReference(container, portal, "subject");
		}

19 View Source File : CmsEntityEditingMetadataProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual IEnumerable<string> GetWebsiteTags(IPortalContext portal, OrganizationServiceContext serviceContext)
		{
			return serviceContext.CreateQuery("adx_tag")
				.Where(e => e.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == portal.Website.ToEnreplacedyReference())
				.Select(e => new { Tag = e.GetAttributeValue<string>("adx_name") })
				.ToArray()
				.Select(t => t.Tag);
		}

19 View Source File : CmsEntityEditingMetadataProvider.cs
License : MIT License
Project Creator : Adoxio

private static string GetEnreplacedyName(Enreplacedy enreplacedy)
		{
			if (enreplacedy == null)
			{
				throw new ArgumentNullException("enreplacedy");
			}

			if (enreplacedy.Attributes.Contains("adx_name"))
			{
				return enreplacedy.GetAttributeValue<string>("adx_name");
			}

			if (enreplacedy.Attributes.Contains("name"))
			{
				return enreplacedy.GetAttributeValue<string>("name");
			}

			return null;
		}

19 View Source File : CmsEntityEditingMetadataProvider.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetEnreplacedy(OrganizationServiceContext serviceContext, EnreplacedyReference enreplacedy)
		{
			if (serviceContext == null)
			{
				throw new ArgumentNullException("serviceContext");
			}

			if (enreplacedy == null)
			{
				throw new ArgumentNullException("enreplacedy");
			}

			var primaryIdAttribute = GetPrimaryIdAttributeLogicalName(serviceContext, enreplacedy.LogicalName);

			return serviceContext.CreateQuery(enreplacedy.LogicalName)
				.FirstOrDefault(e => e.GetAttributeValue<Guid>(primaryIdAttribute) == enreplacedy.Id);
		}

19 View Source File : SavedQueryColumnsGenerator.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetSavedQuery(OrganizationServiceContext serviceContext, string enreplacedyLogicalName, string savedQueryName)
		{
			if (serviceContext == null)
			{
				throw new ArgumentNullException("serviceContext");
			}

			var savedQuery = serviceContext.CreateQuery("savedquery")
				.FirstOrDefault(e => e.GetAttributeValue<string>("name") == savedQueryName
					&& e.GetAttributeValue<string>("returnedtypecode") == enreplacedyLogicalName);

			if (savedQuery == null)
			{
				throw new ArgumentException("A saved query for enreplacedy {0} with the name {1} couldn't be found.".FormatWith(enreplacedyLogicalName, savedQueryName), "savedQueryName");
			}

			return savedQuery;
		}

19 View Source File : SavedQueryView.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetSavedQuery(OrganizationServiceContext serviceContext, string enreplacedyLogicalName, string savedQueryName)
		{
			if (string.IsNullOrWhiteSpace(enreplacedyLogicalName))
			{
				throw new ArgumentNullException("enreplacedyLogicalName");
			}

			if (string.IsNullOrWhiteSpace(savedQueryName))
			{
				throw new ArgumentNullException("savedQueryName");
			}

			var savedQuery = serviceContext.CreateQuery("savedquery")
				.FirstOrDefault(e => e.GetAttributeValue<string>("name") == savedQueryName
					&& e.GetAttributeValue<string>("returnedtypecode") == enreplacedyLogicalName);

			if (savedQuery == null)
			{
				throw new SavedQueryNotFoundException(enreplacedyLogicalName);
			}

			return savedQuery;
		}

19 View Source File : SavedQueryView.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetSavedQuery(OrganizationServiceContext serviceContext, string enreplacedyLogicalName, int queryType, bool isDefault)
		{
			if (string.IsNullOrWhiteSpace(enreplacedyLogicalName))
			{
				throw new ArgumentNullException("enreplacedyLogicalName");
			}

			var savedQuery =
				serviceContext.CreateQuery("savedquery")
					.FirstOrDefault(
						s =>
							s.GetAttributeValue<string>("returnedtypecode") == enreplacedyLogicalName &&
							s.GetAttributeValue<bool>("isdefault") == isDefault && s.GetAttributeValue<int>("querytype") == queryType);

			if (savedQuery == null)
			{
				throw new SavedQueryNotFoundException(enreplacedyLogicalName, queryType, isDefault);
			}

			return savedQuery;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy)
		{
			enreplacedy.replacedertEnreplacedyName("adx_blog");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var blog = serviceContext.IsAttached(enreplacedy) && Equals(enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_websiteid"), website)
				? enreplacedy
				: GetBlog(serviceContext, website, enreplacedy.Id);

			if (blog == null)
			{
				return null;
			}

			var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, blog);
			var pageTemplate = blog.GetRelatedEnreplacedy(serviceContext, "adx_pagetemplate_blog_home");

			// apply a detached clone of the enreplacedy 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;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogMonthArchiveNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy, DateTime month)
		{
			enreplacedy.replacedertEnreplacedyName("adx_blog");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var blog = serviceContext.IsAttached(enreplacedy) && Equals(enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_websiteid"), website)
				? enreplacedy
				: GetBlog(serviceContext, website, enreplacedy.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, enreplacedy, 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;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogTagArchiveNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy, string tagSlug)
		{
			enreplacedy.replacedertEnreplacedyName("adx_blog");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var blog = serviceContext.IsAttached(enreplacedy) && Equals(enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_websiteid"), website)
				? enreplacedy
				: GetBlog(serviceContext, website, enreplacedy.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, enreplacedy, out webTemplateId),
				blog.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
				blogClone);

			node[TagArchiveNodeAttributeKey] = tag;

			if (webTemplateId != null)
			{
				node["adx_webtemplateid"] = webTemplateId;
			}

			return node;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogAggregationMonthArchiveNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy, DateTime month)
		{
			enreplacedy.replacedertEnreplacedyName("adx_webpage");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var page = serviceContext.IsAttached(enreplacedy) && Equals(enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_websiteid"), website)
				? enreplacedy
				: GetPage(serviceContext, website, enreplacedy.Id);

			var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, page);
			var archiveUrl = "{0}{1}{2:yyyy}/{2:MM}/".FormatWith(url, url.EndsWith("/") ? string.Empty : "/", month);

			var pageTemplate = page.GetRelatedEnreplacedy(serviceContext, "adx_pagetemplate_webpage");
			var pageClone = page.Clone(false);

			string webTemplateId;

			var node = new CrmSiteMapNode(
				this,
				archiveUrl,
				archiveUrl,
				month.ToString("y", CultureInfo.CurrentCulture),
				page.GetAttributeValue<string>("adx_summary"),
				GetRewriteUrl(pageTemplate, out webTemplateId),
				page.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
				pageClone);

			node[MonthArchiveNodeAttributeKey] = month.ToString("o", CultureInfo.InvariantCulture);
			node["IsAggregationArchiveNode"] = "true";

			if (webTemplateId != null)
			{
				node["adx_webtemplateid"] = webTemplateId;
			}

			return node;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogAggregationTagArchiveNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy, string tagSlug)
		{
			enreplacedy.replacedertEnreplacedyName("adx_webpage");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var page = serviceContext.IsAttached(enreplacedy) && Equals(enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_websiteid"), website)
				? enreplacedy
				: GetPage(serviceContext, website, enreplacedy.Id);

			var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, page);
			var tagUrl = "{0}{1}{2}".FormatWith(url, url.EndsWith("/") ? string.Empty : "/", tagSlug);
			var tag = HttpUtility.UrlDecode(tagSlug).Trim();

			var pageTemplate = page.GetRelatedEnreplacedy(serviceContext, "adx_pagetemplate_webpage");
			var pageClone = page.Clone(false);

			string webTemplateId;

			var node = new CrmSiteMapNode(
				this,
				tagUrl,
				tagUrl,
				tag,
				page.GetAttributeValue<string>("adx_summary"),
				GetRewriteUrl(pageTemplate, out webTemplateId),
				page.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
				pageClone);

			node[TagArchiveNodeAttributeKey] = tag;
			node["IsAggregationArchiveNode"] = "true";

			if (webTemplateId != null)
			{
				node["adx_webtemplateid"] = webTemplateId;
			}

			return node;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogPostNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy)
		{
			enreplacedy.replacedertEnreplacedyName("adx_blogpost");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var post = serviceContext.IsAttached(enreplacedy)
				? enreplacedy
				: GetBlogPost(serviceContext, enreplacedy.Id);

			if (post == null || post.GetAttributeValue<EnreplacedyReference>("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<EnreplacedyReference>("adx_blogpostpagetemplateid").Id
				where b.GetAttributeValue<EnreplacedyReference>("adx_blogpostpagetemplateid") != null && b.GetAttributeValue<Guid>("adx_blogid") == post.GetAttributeValue<EnreplacedyReference>("adx_blogid").Id
				where p.GetAttributeValue<EnreplacedyReference>("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;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual bool TryGetAuthorArchiveNode(OrganizationServiceContext serviceContext, EnreplacedyReference website, string path, out CrmSiteMapNode node)
		{
			node = null;

			var pathMatch = AuthorArchivePathRegex.Match(path);

			if (!pathMatch.Success)
			{
				return false;
			}

			var archiveRootPath = Regex.Replace(path, @"author/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/$", string.Empty);

			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<EnreplacedyReference>("adx_pageid").Id
				where siteMarker.GetAttributeValue<EnreplacedyReference>("adx_pageid") != null && siteMarker.GetAttributeValue<string>("adx_name") == AggregationArchiveSiteMarkerName
				where page.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website
				select page;

			var blogAggregationArchivePageMatch = blogAggregationArchivePageQuery.ToArray().FirstOrDefault(e => EnreplacedyHasPath(serviceContext, e, archiveRootPath));

			Guid authorId;

			if (blogAggregationArchivePageMatch != null && Guid.TryParse(pathMatch.Groups["author"].Value, out authorId))
			{
				node = GetBlogAggregationAuthorArchiveNode(serviceContext, blogAggregationArchivePageMatch, authorId);

				return true;
			}

			var blogsByAuthorArchivePathMatch = from blog in serviceContext.CreateQuery("adx_blog")
				where blog.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website
				where blog.GetAttributeValue<string>("adx_partialurl") == pathMatch.Groups["blog"].Value
				select blog;

			var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo();
			if (contextLanguageInfo.IsCrmMultiLanguageEnabled)
			{
				blogsByAuthorArchivePathMatch = blogsByAuthorArchivePathMatch.Where(
					blog => blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid") == null ||
						blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid").Id == contextLanguageInfo.ContextLanguage.EnreplacedyReference.Id);
			}

			var blogByAuthorArchivePathMatch = blogsByAuthorArchivePathMatch.ToArray().FirstOrDefault(e => EnreplacedyHasPath(serviceContext, e, archiveRootPath));

			if (blogByAuthorArchivePathMatch != null && Guid.TryParse(pathMatch.Groups["author"].Value, out authorId))
			{
				node = GetBlogAuthorArchiveNode(serviceContext, blogByAuthorArchivePathMatch, authorId);

				return true;
			}

			return false;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual bool TryGetTagArchiveNode(OrganizationServiceContext serviceContext, EnreplacedyReference 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<EnreplacedyReference>("adx_pageid").Id
				where siteMarker.GetAttributeValue<EnreplacedyReference>("adx_pageid") != null && siteMarker.GetAttributeValue<string>("adx_name") == AggregationArchiveSiteMarkerName
				where page.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website
				select page;

			var blogAggregationArchivePageMatch = blogAggregationArchivePageQuery.ToArray().FirstOrDefault(e => EnreplacedyHasPath(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<EnreplacedyReference>("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<EnreplacedyReference>("adx_websitelanguageid") == null ||
						blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid").Id == contextLanguageInfo.ContextLanguage.EnreplacedyReference.Id);
			}

			var blogByTagArchivePath = blogsByTagArchivePathMatch.ToArray().FirstOrDefault(e => EnreplacedyHasPath(serviceContext, e, archiveRootPath));

			if (blogByTagArchivePath != null)
			{
				node = GetBlogTagArchiveNode(serviceContext, blogByTagArchivePath, tagSlug);

				return true;
			}

			return false;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetBlog(OrganizationServiceContext serviceContext, EnreplacedyReference website, Guid id)
		{
			return serviceContext.CreateQuery("adx_blog")
				.FirstOrDefault(e => e.GetAttributeValue<Guid>("adx_blogid") == id && e.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website);
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetBlogPost(OrganizationServiceContext serviceContext, Guid id)
		{
			return serviceContext.CreateQuery("adx_blogpost").FirstOrDefault(e => e.GetAttributeValue<Guid>("adx_blogpostid") == id);
		}

19 View Source File : CrmSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetShortcutCrmNode(OrganizationServiceContext serviceContext, Enreplacedy shortcut, CrmSiteMapNode targetNode)
		{
			if (shortcut == null)
			{
				throw new ArgumentNullException("shortcut");
			}

			if (shortcut.LogicalName != "adx_shortcut")
			{
				throw new ArgumentException("Enreplacedy {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_replacedle") ?? shortcut.GetAttributeValue<string>("adx_name"),
				description,
				targetNode != null ? targetNode.RewriteUrl : url,
				shortcut.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
				shortcut);
		}

19 View Source File : ForumSiteMapHandler.cs
License : MIT License
Project Creator : Adoxio

public void ProcessNode(XmlTextWriter xml, string urlPrefix, Enreplacedy forum)
		{
			forum.replacedertEnreplacedyName("adx_communityforum");

			var context = PortalContext.Current.ServiceContext;

			var threads = forum.GetRelatedEnreplacedies(context, "adx_communityforum_communityforumthread");

			foreach (var thread in threads)
			{
				xml.WriteStartElement("url");
				xml.WriteElementString("loc", urlPrefix + context.GetUrl(thread));
				xml.WriteElementString("lastmod", thread.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow).ToString("yyyy-MM-dd"));
				xml.WriteEndElement();
			}
		}

19 View Source File : ForumSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual IEnumerable<Enreplacedy> FindForums(OrganizationServiceContext context, Enreplacedy website, Enreplacedy webpage)
		{
			var forumsInCurrentWebsite = context.CreateQuery("adx_communityforum")
				.Where(e => e.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website.ToEnreplacedyReference());

			EnreplacedyReference rootPage = webpage.ToEnreplacedyReference();

			ContextLanguageInfo languageInfo = HttpContext.Current.GetContextLanguageInfo();

			IEnumerable<Enreplacedy> forums = null;

			if (languageInfo.IsCrmMultiLanguageEnabled)
			{
				if (!webpage.GetAttributeAliasedValue<bool>("adx_isroot") && webpage.GetAttributeAliasedValue<EnreplacedyReference>("adx_rootwebpageid") != null)
				{
					rootPage = webpage.GetAttributeAliasedValue<EnreplacedyReference>("adx_rootwebpageid");
				}

				forums = forumsInCurrentWebsite
					.Where(e => e.GetAttributeValue<EnreplacedyReference>("adx_parentpageid") == rootPage
					&& (e.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid") == null
					|| e.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid") == languageInfo.ContextLanguage.EnreplacedyReference));
			}
			else
			{
				forums = forumsInCurrentWebsite
					.Where(e => e.GetAttributeValue<EnreplacedyReference>("adx_parentpageid") == webpage.ToEnreplacedyReference());
			} 

			return forums.ToList();
		}

19 View Source File : ForumSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetForumThreadNode(OrganizationServiceContext context, Enreplacedy thread)
		{
			thread.replacedertEnreplacedyName("adx_communityforumthread");

			var forum = thread.GetRelatedEnreplacedy(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;
		}

19 View Source File : ForumSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

private bool TryGetWebTemplateId(Enreplacedy pageTemplate, out string webTemplateId)
		{
			webTemplateId = null;

			if (pageTemplate == null)
			{
				return false;
			}

			var type = pageTemplate.GetAttributeValue<OptionSetValue>("adx_type");
			var webTemplate = pageTemplate.GetAttributeValue<EnreplacedyReference>("adx_webtemplateid");

			if (type == null || type.Value != (int)PageTemplateNode.TemplateType.WebTemplate || webTemplate == null)
			{
				return false;
			}
				
			webTemplateId = webTemplate.Id.ToString();

			return true;
		}

19 View Source File : SurveyReporter.cs
License : MIT License
Project Creator : Adoxio

public void Write(HtmlTextWriter writer)
		{
			writer.RenderBeginTag(HtmlTextWriterTag.Table);

			writer.RenderBeginTag(HtmlTextWriterTag.Tr);

			writer.RenderBeginTag(HtmlTextWriterTag.Th);
			writer.Write("Submission name");
			writer.RenderEndTag();

			writer.RenderBeginTag(HtmlTextWriterTag.Th);
			writer.Write("Visitor ID");
			writer.RenderEndTag();

			writer.RenderBeginTag(HtmlTextWriterTag.Th);
			writer.Write("Contact Name");
			writer.RenderEndTag();

			foreach (var question in _surveyChoiceQuestions)
			{
				writer.RenderBeginTag(HtmlTextWriterTag.Th);
				writer.Write(question.GetAttributeValue<string>("adx_name"));
				writer.RenderEndTag();

				writer.RenderBeginTag(HtmlTextWriterTag.Th);
				writer.Write(question.GetAttributeValue<string>("adx_question"));
				writer.RenderEndTag();

			}

			foreach (var question in _surveyTextQuestions)
			{
				writer.RenderBeginTag(HtmlTextWriterTag.Th);
				writer.Write(question.GetAttributeValue<string>("adx_name") + " : " + question.GetAttributeValue<string>("adx_question"));
				writer.RenderEndTag();

			}

			writer.RenderEndTag();

			if (_surveySubmissions == null)
			{
				writer.RenderEndTag();
				return;
			}


			for (int i = 0; i < _surveySubmissions.Count; i++)
			{
				writer.RenderBeginTag(HtmlTextWriterTag.Tr);
				writer.RenderBeginTag(HtmlTextWriterTag.Td);
				writer.Write(_surveySubmissions[i].GetAttributeValue<string>("adx_name"));
				writer.RenderEndTag();

				var contact = _surveyContacts[i];

				if (contact != null)
				{
					writer.RenderBeginTag(HtmlTextWriterTag.Td);
					writer.Write(@" ");
					writer.RenderEndTag();
					writer.RenderBeginTag(HtmlTextWriterTag.Td);
					writer.Write(contact.GetAttributeValue<string>("fullname"));
					writer.RenderEndTag();
				}
				else
				{
					writer.RenderBeginTag(HtmlTextWriterTag.Td);
					writer.Write(_surveySubmissions[i].GetAttributeValue<string>("adx_visitorid"));
					writer.RenderEndTag();
					writer.RenderBeginTag(HtmlTextWriterTag.Td);
					writer.Write(@" ");
					writer.RenderEndTag();
				}

				var thisSubmissionTextAnswers = _submissionTextAnswers[i];
				var thisSubmissionChoiceAnswers = _submissionChoiceAnswers[i];

				var crm = CrmConfigurationManager.CreateContext(ContextName);

				foreach (var question in _surveyChoiceQuestions)
				{
					bool answered = false;
					foreach (var answer in thisSubmissionChoiceAnswers)
					{
						var anses = crm.CreateQuery("adx_surveychoiceanswer");
						Enreplacedy answer1 = answer;
						var ans = anses.Where(a => a.GetAttributeValue<Guid>("adx_surveychoiceanswerid") == answer1.GetAttributeValue<Guid>("adx_surveychoiceanswerid")).First();
						if (ans.GetRelatedEnreplacedy(crm, "adx_choicequestion_choiceanswer").GetAttributeValue<Guid?>("adx_surveychoicequestionid")
							== question.GetAttributeValue<Guid?>("adx_surveychoicequestionid"))
						{
							string partialChoiceList = string.Empty;
							var choices = ans.GetRelatedEnreplacedies(crm, "adx_surveychoiceanswer_surveychoice");
							foreach (var enreplacedy in choices)
							{
								partialChoiceList = partialChoiceList + enreplacedy.GetAttributeValue<string>("adx_name") + "|";
							}
							string pattern = @"\|$";
							string replacement = " ";

							writer.RenderBeginTag(HtmlTextWriterTag.Td);

							if (partialChoiceList != null)
							{
								string result = Regex.Replace(partialChoiceList, pattern, replacement);
								writer.Write(result);
							}
							else
							{
								writer.Write(partialChoiceList);
							}
							writer.RenderEndTag();

							writer.RenderBeginTag(HtmlTextWriterTag.Td);

							string input = ans.GetAttributeValue<string>("adx_answer");
							
							if (input != null)
							{
								string result = Regex.Replace(input, pattern, replacement);
								writer.Write(result);
							}
							else
							{
								writer.Write(input);
							}
							writer.RenderEndTag();
							answered = true;
						}
					}
					if (!answered)
					{
						writer.RenderBeginTag(HtmlTextWriterTag.Td);
						writer.Write(@" ");
						writer.RenderEndTag();
					}
				}
				foreach (var question in _surveyTextQuestions)
				{
					bool answered = false;
					foreach (var answer in thisSubmissionTextAnswers)
					{
						var anses = crm.CreateQuery("adx_surveytextanswer");
						Enreplacedy answer1 = answer;
						var ans = anses.Where(a => a.GetAttributeValue<Guid>("adx_surveytextanswerid") == answer1.GetAttributeValue<Guid>("adx_surveytextanswerid")).First();
						if (ans.GetRelatedEnreplacedy(crm, "adx_textareaquestion_textanswer").GetAttributeValue<Guid?>("adx_surveytextareaquestionid")
							== question.GetAttributeValue<Guid?>("adx_surveytextareaquestionid"))
						{
							writer.RenderBeginTag(HtmlTextWriterTag.Td);
							if (string.IsNullOrEmpty(ans.GetAttributeValue<string>("adx_answer")))
							{
								writer.Write(@" ");
							}
							else
							{
								writer.Write(ans.GetAttributeValue<string>("adx_answer"));
							}
							//writer.Write(answer.GetAttributeValue<string>("adx_answer"));
							writer.RenderEndTag();
							answered = true;
						}
					}
					if (!answered)
					{
						writer.RenderBeginTag(HtmlTextWriterTag.Td);
						writer.Write(@" ");
						writer.RenderEndTag();
					}
				}

				writer.RenderEndTag();

			}

			writer.RenderEndTag();
			writer.Flush();



		}

19 View Source File : CrmSubjectDropDownList.cs
License : MIT License
Project Creator : Adoxio

protected void AddChildItems(List<Enreplacedy> subjects, IEnumerable<Enreplacedy> children, int depth)
		{
			foreach (var child in children)
			{
				if (child == null)
				{
					continue;
				}

				var padding = HttpUtility.HtmlDecode(string.Concat(Enumerable.Repeat(" - ", depth)));

				Items.Add(new Lisreplacedem(string.Format("{0}{1}", padding, child.GetAttributeValue<string>("replacedle")), child.Id.ToString()));

				var childId = child.Id;

				var grandchildren = subjects.Where(s => s.GetAttributeValue<EnreplacedyReference>("parentsubject") != null && s.GetAttributeValue<EnreplacedyReference>("parentsubject").Id == childId).OrderBy(s => s.GetAttributeValue<string>("replacedle"));

				depth++;

				AddChildItems(subjects, grandchildren, depth);

				depth--;
			}
		}

19 View Source File : CrmTimeZone.cs
License : MIT License
Project Creator : Adoxio

protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			if (Items.Count > 0)
			{
				return;
			}
			
			var empty = new Lisreplacedem(string.Empty, string.Empty);
			empty.Attributes["label"] = " ";
			Items.Add(empty);

			var context = CrmConfigurationManager.CreateContext(ContextName);

			if (LanguageCode == 0)
			{
				var organization = context.CreateQuery("organization").FirstOrDefault();

				if (organization == null)
				{
                    ADXTrace.Instance.TraceError(TraceCategory.Application, "Failed to retrieve organization.");
                }
				else
				{
					LanguageCode = organization.GetAttributeValue<int?>("languagecode") ?? 0;
				}
			}

			if (LanguageCode == 0)
			{
				LanguageCode = 1033;
			}
			
			var request = new GetAllTimeZonesWithDisplayNameRequest { LocaleId = LanguageCode };
			
			var response = (GetAllTimeZonesWithDisplayNameResponse)context.Execute(request);

			foreach (var timeZoneDefinition in response.EnreplacedyCollection.Enreplacedies.OrderBy(o => o.GetAttributeValue<string>("userinterfacename")))
			{
				Items.Add(new Lisreplacedem(timeZoneDefinition.GetAttributeValue<string>("userinterfacename"), timeZoneDefinition.GetAttributeValue<int>("timezonecode").ToString(CultureInfo.InvariantCulture)));
			}


		}

19 View Source File : EntityList.cs
License : MIT License
Project Creator : Adoxio

protected override void CreateChildControls()
		{
			Controls.Clear();

			var portalContext = PortalCrmConfigurationManager.CreatePortalContext(PortalName);
			var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(PortalName);

			Enreplacedy enreplacedylist;
			bool updateEnreplacedyListReference;

			if (!TryGetEnreplacedyList(portalContext, serviceContext, out enreplacedylist, out updateEnreplacedyListReference))
			{
				Visible = false;

				return;
			}

			if (updateEnreplacedyListReference) { EnreplacedyListReference = enreplacedylist.ToEnreplacedyReference(); }

			if (LanguageCode <= 0) { LanguageCode = this.Context.GetPortalSolutionsDetails().OrganizationBaseLanguageCode; }

			RegisterClientSideDependencies(this);

			var registerStartupScript = enreplacedylist.GetAttributeValue<string>("adx_registerstartupscript");

			if (!string.IsNullOrWhiteSpace(registerStartupScript))
			{
				var html = Mvc.Html.EnreplacedyExtensions.GetHtmlHelper(PortalName, Page.Request.RequestContext, Page.Response);

				var control = new HtmlGenericControl() { };

				var script = html.ScriptAttribute(serviceContext, enreplacedylist, "adx_registerstartupscript");

				control.InnerHtml = script.ToString();

				Controls.Add(control);
			}

			var enreplacedyName = enreplacedylist.GetAttributeValue<string>("adx_enreplacedyname");
			var primaryKeyName = enreplacedylist.GetAttributeValue<string>("adx_primarykeyname");
			var view = enreplacedylist.GetAttributeValue<string>("adx_view"); // old comma delimited list of views
			var viewMetadataJson = enreplacedylist.GetAttributeValue<string>("adx_views");
			EnableEnreplacedyPermissions = enreplacedylist.GetAttributeValue<bool?>("adx_enreplacedypermissionsenabled").GetValueOrDefault(false);

			if (string.IsNullOrWhiteSpace(enreplacedyName))
			{
				throw new ApplicationException("Enreplacedy Name (adx_enreplacedyname) attribute on Enreplacedy List (adx_enreplacedylist) is null or empty. Please specify the logical name of the enreplacedy.");
			}

			if (!string.IsNullOrWhiteSpace(enreplacedyName) && string.IsNullOrWhiteSpace(primaryKeyName))
			{
				primaryKeyName = MetadataHelper.GetEnreplacedyPrimaryKeyAttributeLogicalName(serviceContext, enreplacedyName);
			}

			if (string.IsNullOrWhiteSpace(primaryKeyName))
			{
				throw new ApplicationException(string.Format("The enreplacedy primary key logical name couldn't be determined.", enreplacedyName));
			}

			if (string.IsNullOrWhiteSpace(view) && string.IsNullOrWhiteSpace(viewMetadataJson))
			{
				throw new ApplicationException("View selection on Enreplacedy List (adx_enreplacedylist) is null or empty. Specify the savedquery views.");
			}

			var gridMetadataJson = enreplacedylist.GetAttributeValue<string>("adx_settings");
			GridMetadata gridMetadata = null;
			if (!string.IsNullOrWhiteSpace(gridMetadataJson))
			{
				try
				{
					gridMetadata = JsonConvert.DeserializeObject<GridMetadata>(gridMetadataJson,
						new JsonSerializerSettings
						{
							ContractResolver = JsonConfigurationContractResolver.Instance,
							TypeNameHandling = TypeNameHandling.Objects,
							Converters = new List<JsonConverter> { new GuidConverter() },
							Binder = new ActionSerializationBinder()
						});
				}
				catch (Exception e)
				{
					ADXTrace.Instance.TraceError(TraceCategory.Application, e.ToString());
				}
			}

			var viewConfigurations = new List<ViewConfiguration>();

			if (string.IsNullOrWhiteSpace(viewMetadataJson))
			{
				if (string.IsNullOrWhiteSpace(view)) return;
				var viewids = view.Split(',');
				var viewGuids = viewids.Length < 1 ? null : Array.ConvertAll(viewids, Guid.Parse);

				if (viewGuids == null || !viewGuids.Any())
				{
					throw new ApplicationException(
						ResourceManager.GetString("ADX_View_Attribute_On_Enreplacedy_List_Contains_Invalid_Data_Exception"));
				}

				viewConfigurations =
					viewGuids.Select(
						viewGuid =>
							new ViewConfiguration(portalContext, serviceContext, enreplacedylist, enreplacedyName, primaryKeyName, viewGuid,
								gridMetadata, PortalName, LanguageCode, EnableEnreplacedyPermissions, PageQueryStringField, FilterQueryStringField,
								SearchQueryStringField, SortQueryStringField, FilterByUserOptionLabel, ActionLinksColumnWidth,
								MetadataFilterQueryStringField, DefaultDetailsButtonLabel, ActionLinkDetailsViewTooltipLabel,
								DefaultCreateButtonLabel, ActionLinkInsertTooltipLabel, DefaultEmptyListText)).ToList();
			}
			else
			{
				ViewMetadata viewMetadata = null;
				try
				{
					viewMetadata = JsonConvert.DeserializeObject<ViewMetadata>(viewMetadataJson,
						new JsonSerializerSettings { ContractResolver = JsonConfigurationContractResolver.Instance, TypeNameHandling = TypeNameHandling.Objects, Binder = new ActionSerializationBinder(), Converters = new List<JsonConverter> { new GuidConverter() } });
				}
				catch (Exception e)
				{
					ADXTrace.Instance.TraceError(TraceCategory.Application, e.ToString());
				}

				if (viewMetadata != null && viewMetadata.Views != null && viewMetadata.Views.Any())
				{
					foreach (var viewMeta in viewMetadata.Views)
					{
						var viewConfiguration = new ViewConfiguration(portalContext, serviceContext, enreplacedylist, enreplacedyName,
							primaryKeyName, viewMeta.ViewId,
							gridMetadata, PortalName, LanguageCode, EnableEnreplacedyPermissions, PageQueryStringField, FilterQueryStringField,
							SearchQueryStringField, SortQueryStringField, FilterByUserOptionLabel, ActionLinksColumnWidth,
							MetadataFilterQueryStringField, DefaultDetailsButtonLabel, ActionLinkDetailsViewTooltipLabel,
							DefaultCreateButtonLabel, ActionLinkInsertTooltipLabel, DefaultEmptyListText);
						if (viewMeta.DisplayName != null)
						{
							var displayName = Localization.GetLocalizedString(viewMeta.DisplayName, LanguageCode);
							if (!string.IsNullOrWhiteSpace(displayName))
							{
								viewConfiguration.ViewDisplayName = displayName;
							}
						}
						viewConfigurations.Add(viewConfiguration);
					}
				}
			}

			var crmEnreplacedyListView = new CrmEnreplacedyListView
			{
				EnableEnreplacedyPermissions = EnableEnreplacedyPermissions,
				EnreplacedyListReference = EnreplacedyListReference,
				ViewConfigurations = viewConfigurations,
				ListCssClreplaced = ListCssClreplaced,
				PortalName = PortalName,
				LanguageCode = LanguageCode,
				ViewQueryStringParameterName = ViewQueryStringField,
				IsGallery = IsGallery
			};

			if (gridMetadata != null)
			{
				if (gridMetadata.ErrorDialog != null)
				{
					crmEnreplacedyListView.ErrorModal = new ViewErrorModal
					{
						CloseButtonCssClreplaced = gridMetadata.ErrorDialog.CloseButtonCssClreplaced,
						CloseButtonText = gridMetadata.ErrorDialog.CloseButtonText.GetLocalizedString(LanguageCode),
						CssClreplaced = gridMetadata.ErrorDialog.CssClreplaced,
						DismissButtonSrText = gridMetadata.ErrorDialog.DismissButtonSrText.GetLocalizedString(LanguageCode),
						Body = gridMetadata.ErrorDialog.Body.GetLocalizedString(LanguageCode),
						Size = gridMetadata.ErrorDialog.Size,
						replacedle = gridMetadata.ErrorDialog.replacedle.GetLocalizedString(LanguageCode),
						replacedleCssClreplaced = gridMetadata.ErrorDialog.replacedleCssClreplaced
					};
				}
			}

			Controls.Add(crmEnreplacedyListView);
		}

19 View Source File : SurveySiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected override CrmSiteMapNode GetNode(OrganizationServiceContext context, Enreplacedy enreplacedy)
		{
			if (enreplacedy == null)
			{
				throw new ArgumentNullException("enreplacedy");
			}

			if (enreplacedy.LogicalName != "adx_survey")
			{
				throw new ArgumentException("Enreplacedy {0} ({1}) is not of a type supported by this provider.".FormatWith(enreplacedy.Id, enreplacedy.GetType().FullName), "enreplacedy");
			}

			var url = context.GetUrl(enreplacedy);

			var portal = PortalContext;
			var serviceContext = portal.ServiceContext;
			var website = portal.Website;

			var surveyID = enreplacedy.GetAttributeValue<Guid>("adx_surveyid");

			var webSurvey =
				website.GetRelatedEnreplacedies(serviceContext, "adx_website_survey")
					.SingleOrDefault(e => e.GetAttributeValue<Guid>("adx_surveyid") == surveyID);

			var pageTemplate = enreplacedy.GetRelatedEnreplacedy(context, "adx_pagetemplate_survey");
			string partialURL;
			if (pageTemplate != null)
			{
				partialURL = pageTemplate.GetAttributeValue<string>("adx_rewriteurl") ?? "~/Pages/Survey.aspx";
			}
			else
			{
				partialURL = "~/Pages/Survey.aspx";
			}

			return new CrmSiteMapNode(
				this,
				url,
				url,
				enreplacedy.GetAttributeValue<string>("adx_name"),
				enreplacedy.GetAttributeValue<string>("adx_description"),
				partialURL + "?id=" + surveyID,
				enreplacedy.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
				webSurvey);
		}

19 View Source File : CrmSessionHistoryProvider.cs
License : MIT License
Project Creator : Adoxio

public SessionHistory GetSessionHistoryBySystemUser(OrganizationServiceContext context, Guid webFormId, Guid systemUserId)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			var webFormSession = context.CreateQuery("adx_webformsession").Where(s => s.GetAttributeValue<OptionSetValue>("statecode") != null && s.GetAttributeValue<OptionSetValue>("statecode").Value == 0).OrderByDescending(s => s.GetAttributeValue<DateTime>("modifiedon")).FirstOrDefault(s => s.GetAttributeValue<EnreplacedyReference>("adx_webform") == new EnreplacedyReference("adx_webform", webFormId) && s.GetAttributeValue<EnreplacedyReference>("adx_systemuser") == new EnreplacedyReference("systemuser", systemUserId));

			return GetSessionHistory(webFormSession);
		}

19 View Source File : CrmSessionHistoryProvider.cs
License : MIT License
Project Creator : Adoxio

public SessionHistory GetSessionHistoryByUserIdenreplacedyName(OrganizationServiceContext context, Guid webFormId, string userIdenreplacedyName)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			var webFormSession = context.CreateQuery("adx_webformsession").Where(s => s.GetAttributeValue<OptionSetValue>("statecode") != null && s.GetAttributeValue<OptionSetValue>("statecode").Value == 0).OrderByDescending(s => s.GetAttributeValue<DateTime>("modifiedon")).FirstOrDefault(s => s.GetAttributeValue<EnreplacedyReference>("adx_webform") == new EnreplacedyReference("adx_webform", webFormId) && s.GetAttributeValue<string>("adx_useridenreplacedyname") == userIdenreplacedyName);

			return GetSessionHistory(webFormSession);
		}

19 View Source File : CrmSessionHistoryProvider.cs
License : MIT License
Project Creator : Adoxio

public SessionHistory GetSessionHistoryByPrimaryRecord(OrganizationServiceContext context, Guid webFormId, Guid recordId)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			var webFormSession = context.CreateQuery("adx_webformsession").FirstOrDefault(s => s.GetAttributeValue<OptionSetValue>("statecode") != null && s.GetAttributeValue<OptionSetValue>("statecode").Value == 0 && s.GetAttributeValue<EnreplacedyReference>("adx_webform") == new EnreplacedyReference("adx_webform", webFormId) && s.GetAttributeValue<string>("adx_primaryrecordid") == recordId.ToString());

			return GetSessionHistory(webFormSession);
		}

19 View Source File : CrmSessionHistoryProvider.cs
License : MIT License
Project Creator : Adoxio

public SessionHistory GetSessionHistory(OrganizationServiceContext context, Guid sessionID)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			var webFormSession = context.CreateQuery("adx_webformsession").FirstOrDefault(s => s.GetAttributeValue<OptionSetValue>("statecode") != null && s.GetAttributeValue<OptionSetValue>("statecode").Value == 0 && s.GetAttributeValue<Guid>("adx_webformsessionid") == sessionID);

			return GetSessionHistory(webFormSession);
		}

19 View Source File : CrmSessionHistoryProvider.cs
License : MIT License
Project Creator : Adoxio

public void DeactivateSessionHistory(OrganizationServiceContext context, Guid id)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}

			if (id == Guid.Empty)
			{
				throw new ArgumentNullException("id");
			}

			var webFormSession = context.CreateQuery("adx_webformsession").FirstOrDefault(s => s.GetAttributeValue<Guid>("adx_webformsessionid") == id);

			if (webFormSession == null)
			{
				return;
			}

			context.SetState(1, 2, webFormSession.ToEnreplacedyReference());
		}

19 View Source File : SavedQueryColumnsGenerator.cs
License : MIT License
Project Creator : Adoxio

public ICollection GenerateFields(Control control)
		{
			var layoutXml = XElement.Parse(SavedQuery.GetAttributeValue<string>("layoutxml"));
			var cellNames = layoutXml.Element("row").Elements("cell").Select(cell => cell.Attribute("name")).Where(name => name != null);
			var disabledSortCellNames = layoutXml.Element("row").Elements("cell")
						.Where(cell => cell.Attribute("disableSorting") != null && cell.Attribute("disableSorting").Value == "1")
						.Where(cell => cell.Attribute("name") != null)
						.Select(cell => cell.Attribute("name").Value);
			var fetchXml = XElement.Parse(SavedQuery.GetAttributeValue<string>("fetchxml"));
			var enreplacedyName = fetchXml.Element("enreplacedy").Attribute("name").Value;

			var response = (RetrieveEnreplacedyResponse)ServiceContext.Execute(new RetrieveEnreplacedyRequest
			{
				LogicalName = enreplacedyName,
				EnreplacedyFilters = EnreplacedyFilters.Attributes
			});

			if (response == null || response.EnreplacedyMetadata == null)
			{
				return new DataControlFieldCollection();
			}
			
			if (LanguageCode == 0)
			{
				LanguageCode = HttpContext.Current?.GetCrmLcid() ?? CultureInfo.CurrentCulture.LCID;
			}
			
			var fields =
				from name in cellNames
				let label = GetLabel(ServiceContext, response.EnreplacedyMetadata, name.Value, fetchXml, LanguageCode)
				where label != null
				select new BoundField
				{
					DataField = name.Value,
					SortExpression = disabledSortCellNames.Contains(name.Value) ? string.Empty : name.Value,
					HeaderText = label
				};

			return fields.ToArray();
		}

19 View Source File : SavedQueryView.cs
License : MIT License
Project Creator : Adoxio

private static Enreplacedy GetSavedQuery(OrganizationServiceContext serviceContext, Guid id)
		{
			var savedQuery = serviceContext.CreateQuery("savedquery").FirstOrDefault(e => e.GetAttributeValue<Guid>("savedqueryid") == id);

			if (savedQuery == null)
			{
				throw new SavedQueryNotFoundException(id);
			}

			return savedQuery;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual IEnumerable<Enreplacedy> FindBlogs(OrganizationServiceContext context, Enreplacedy website, Enreplacedy webpage)
		{
			var blogsInCurrentWebsite = context.CreateQuery("adx_blog")
				.Where(b => b.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website.ToEnreplacedyReference()).ToArray();

			// Since blogs can only be children of language-root web pages, if the given web page is not a root, then use its root for query instead.
			EnreplacedyReference rootWebPage = webpage.ToEnreplacedyReference();
			var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo();
			if (contextLanguageInfo.IsCrmMultiLanguageEnabled && !webpage.GetAttributeValue<bool>("adx_isroot"))
			{
				rootWebPage = webpage.GetAttributeValue<EnreplacedyReference>("adx_rootwebpageid");
			}

			var blogs = blogsInCurrentWebsite
				.Where(e => Equals(e.GetAttributeValue<EnreplacedyReference>("adx_parentpageid"), rootWebPage))
				.OrderBy(e => e.GetAttributeValue<string>("adx_name"));
			
			// Only find blogs that match the current language. 
			var blogsInCurrentLanguage = contextLanguageInfo.IsCrmMultiLanguageEnabled
				? blogs.Where(blog => blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid") == null || blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid").Id == contextLanguageInfo.ContextLanguage.EnreplacedyReference.Id)
				: blogs;

			return blogsInCurrentLanguage;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected CrmSiteMapNode GetBlogAggregationAuthorArchiveNode(OrganizationServiceContext serviceContext, Enreplacedy enreplacedy, Guid authorId)
		{
			enreplacedy.replacedertEnreplacedyName("adx_webpage");

			var portal = PortalContext;
			var website = portal.Website.ToEnreplacedyReference();

			var page = serviceContext.IsAttached(enreplacedy) && Equals(enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_websiteid"), website)
				? enreplacedy
				: GetPage(serviceContext, website, enreplacedy.Id);

			var url = OrganizationServiceContextExtensions.GetUrl(serviceContext, page);
			var archiveUrl = "{0}{1}author/{2}/".FormatWith(url, url.EndsWith("/") ? string.Empty : "/", authorId);

			var pageTemplate = page.GetRelatedEnreplacedy(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;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual bool TryGetMonthArchiveNode(OrganizationServiceContext serviceContext, EnreplacedyReference website, string path, out CrmSiteMapNode node)
		{
			node = null;

			var pathMatch = MonthArchivePathRegex.Match(path);

			if (!pathMatch.Success)
			{
				return false;
			}

			DateTime date;

			try
			{
				date = new DateTime(
					int.Parse(pathMatch.Groups["year"].Value),
					int.Parse(pathMatch.Groups["month"].Value),
					1, 0, 0, 0,
					DateTimeKind.Utc);
			}
			catch
			{
				return false;
			}

			var archiveRootPath = Regex.Replace(path, @"\d{4}/\d{2}/$", string.Empty);

			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<EnreplacedyReference>("adx_pageid").Id
				where siteMarker.GetAttributeValue<EnreplacedyReference>("adx_pageid") != null && siteMarker.GetAttributeValue<string>("adx_name") == AggregationArchiveSiteMarkerName
				where page.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website
				select page;

			var blogAggregationArchivePageMatch = blogAggregationArchivePageQuery.ToArray().FirstOrDefault(e => EnreplacedyHasPath(serviceContext, e, archiveRootPath));

			if (blogAggregationArchivePageMatch != null)
			{
				node = GetBlogAggregationMonthArchiveNode(serviceContext, blogAggregationArchivePageMatch, date);

				return true;
			}

			var blogsByMonthArchivePathMatch = from blog in serviceContext.CreateQuery("adx_blog")
				where blog.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website
				where blog.GetAttributeValue<string>("adx_partialurl") == pathMatch.Groups["blog"].Value
				select blog;

			var contextLanguageInfo = HttpContext.Current.GetContextLanguageInfo();
			if (contextLanguageInfo.IsCrmMultiLanguageEnabled)
			{
				blogsByMonthArchivePathMatch = blogsByMonthArchivePathMatch.Where(
					blog => blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid") == null ||
						blog.GetAttributeValue<EnreplacedyReference>("adx_websitelanguageid").Id == contextLanguageInfo.ContextLanguage.EnreplacedyReference.Id);
			}

			var blogByMonthArchivePath = blogsByMonthArchivePathMatch.ToArray().FirstOrDefault(e => EnreplacedyHasPath(serviceContext, e, archiveRootPath));

			if (blogByMonthArchivePath != null)
			{
				node = GetBlogMonthArchiveNode(serviceContext, blogByMonthArchivePath, date);

				return true;
			}

			return false;
		}

19 View Source File : BlogSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

private CrmSiteMapNode GetWebFileNode(OrganizationServiceContext serviceContext, Enreplacedy 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<ICrmEnreplacedyFileAttachmentProvider>();

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

			// apply a detached clone of the enreplacedy 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);
		}

19 View Source File : EventSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected virtual Enreplacedy FindEvent(OrganizationServiceContext context, Enreplacedy website, string path)
		{
			var eventsInCurrentWebsite = context.CreateQuery("adx_event")
				.Where(e => e.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website.ToEnreplacedyReference())
				.ToArray();

			var foundEvent = eventsInCurrentWebsite.FirstOrDefault(e => EnreplacedyHasPath(context, e, path));

			return foundEvent;
		}

19 View Source File : EventSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected override CrmSiteMapNode GetNode(OrganizationServiceContext context, Enreplacedy enreplacedy)
		{
			if (enreplacedy == null)
			{
				throw new ArgumentNullException("enreplacedy");
			}

			if (enreplacedy.LogicalName != "adx_event")
			{
				throw new ArgumentException("Enreplacedy {0} ({1}) is not of a type supported by this provider.".FormatWith(enreplacedy.Id, enreplacedy.GetType().FullName), "enreplacedy");
			}

			var url = OrganizationServiceContextExtensions.GetUrl(context, enreplacedy);

			var portal = PortalContext;
			var serviceContext = portal.ServiceContext;
			var website = portal.Website;

			var eventId = enreplacedy.GetAttributeValue<Guid>("adx_eventid");

			var eventsInCurrentWebsite = serviceContext.CreateQuery("adx_event")
				.Where(e => e.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == website.ToEnreplacedyReference())
				.ToArray();

			var webEvent = eventsInCurrentWebsite
				.SingleOrDefault(e => e.GetAttributeValue<Guid>("adx_eventid") == eventId);

			// apply a detached clone of the enreplacedy 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,
				enreplacedy.GetAttributeValue<string>("adx_name"),
				enreplacedy.GetAttributeValue<string>("adx_description"),
				GetPageTemplatePath(serviceContext, enreplacedy, website, out webTemplateId) + "?id=" + eventId,
				enreplacedy.GetAttributeValue<DateTime?>("modifiedon").GetValueOrDefault(DateTime.UtcNow),
				webEventClone);

			if (webTemplateId != null)
			{
				node["adx_webtemplateid"] = webTemplateId;
			}
			
			return node;
		}

19 View Source File : EventSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected string GetPageTemplatePath(OrganizationServiceContext context, Enreplacedy enreplacedy, Enreplacedy website, out string webTemplateId)
		{
			webTemplateId = null;

			if (enreplacedy == null)
			{
				throw new ArgumentNullException("enreplacedy");
			}

			if (enreplacedy.LogicalName != "adx_event")
			{
				throw new ArgumentException("Enreplacedy {0} ({1}) is not of a type supported by this provider.".FormatWith(enreplacedy.Id, enreplacedy.GetType().FullName), "enreplacedy");
			}

			var pageTemplate = enreplacedy.GetRelatedEnreplacedy(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";
		}

19 View Source File : ForumSiteMapProvider.cs
License : MIT License
Project Creator : Adoxio

protected string GetForumThreadPageTemplatePath(OrganizationServiceContext context, Enreplacedy forum, out string webTemplateId)
		{
			webTemplateId = null;

			if (forum == null)
			{
				throw new ArgumentNullException("forum");
			}

			if (forum.LogicalName != "adx_communityforum")
			{
				throw new ArgumentException("Enreplacedy {0} ({1}) is not of a type supported by this provider.".FormatWith(forum.Id, forum.GetType().FullName), "forum");
			}

			var pageTemplate = context.RetrieveSingle(
				"adx_pagetemplate",
				FetchAttribute.All,
				new Condition("adx_pagetemplateid", ConditionOperator.Equal, forum.GetAttributeValue<EnreplacedyReference>("adx_threadpagetemplateid").Id));

			if (pageTemplate == null)
			{
				return HttpContext.Current.GetWebsite().Settings.Get<string>("forums/forumthread/templatepath") ?? "~/Pages/ForumThread.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/ForumThread.aspx";
		}

19 View Source File : RedirectProvider.cs
License : MIT License
Project Creator : Adoxio

public IRedirectMatch Match(Guid websiteID, UrlBuilder url)
		{
			if (url == null)
			{
				throw new ArgumentNullException("url");
			}

			var appRelativePath = VirtualPathUtility.ToAppRelative(url.PathWithQueryString);

			using (var context = CreateContext())
			{
				var redirect = context.CreateQuery("adx_redirect")
					.Where(r => r.GetAttributeValue<EnreplacedyReference>("adx_websiteid") == new EnreplacedyReference("adx_website", websiteID))
					.ToList().FirstOrDefault(
						r => {
							// replacedume an inbound path that is partial should be an app relative path instead

							var inboundPath = r.GetAttributeValue<string>("adx_inboundurl");
							var isPartial = !inboundPath.StartsWith("/") && !inboundPath.StartsWith("~");
							var appRelativeInboundPath = VirtualPathUtility.ToAppRelative((isPartial ? "~/" : string.Empty) + inboundPath);

							return string.Equals(appRelativePath, appRelativeInboundPath, StringComparison.OrdinalIgnoreCase);
						});

				if (redirect == null)
				{
					return new FailedRedirectMatch();
				}

				var inboundURL = redirect.GetAttributeValue<string>("adx_inboundurl");

				var redirectURL = redirect.GetAttributeValue<string>("adx_redirecturl");

				// Eliminate infinite loop redirecting to itself.
				if (inboundURL == redirectURL)
				{
					return new FailedRedirectMatch();
				}

				var statusOption = redirect.GetAttributeValue<OptionSetValue>("adx_statuscode");
				var statusCode = statusOption == null ? (int)HttpStatusCode.Redirect : statusOption.Value;

				if (!string.IsNullOrEmpty(redirectURL))
				{
					return new RedirectMatch(statusCode, redirectURL);
				}

				var page = redirect.GetRelatedEnreplacedy(context, "adx_webpage_redirect");

				if (page != null)
				{
					var pageUrl = context.GetUrl(page);

					if (!string.IsNullOrWhiteSpace(pageUrl))
					{
						return new RedirectMatch(statusCode, pageUrl);
					}
				}

				var siteMarker = redirect.GetRelatedEnreplacedy(context, "adx_sitemarker_redirect");

				if (siteMarker != null)
				{
					page = siteMarker.GetRelatedEnreplacedy(context, "adx_webpage_sitemarker");

					if (page != null)
					{
						var pageUrl = context.GetUrl(page);

						if (!string.IsNullOrWhiteSpace(pageUrl))
						{
							return new RedirectMatch(statusCode, pageUrl);
						}
					}
				}

				return new FailedRedirectMatch();
			}
		}

19 View Source File : UrlMapping.cs
License : MIT License
Project Creator : Adoxio

private static bool IsPartialUrlMatch(Enreplacedy webPage, string path)
		{
			return webPage != null
				&& string.Equals(webPage.GetAttributeValue<string>("adx_partialurl"), path, StringComparison.InvariantCultureIgnoreCase);
		}

19 View Source File : UrlMapping.cs
License : MIT License
Project Creator : Adoxio

private static UrlMappingResult<Enreplacedy> GetResultFromQuery(IEnumerable<Enreplacedy> query)
		{
			// select only root pages or pages where isroot = null 
			var duplicateCheckArray = query.Where(p => p.GetAttributeValue<bool?>("adx_isroot") != false).ToArray();
			var result = query.FirstOrDefault();
			return duplicateCheckArray.Length > 1
				? UrlMappingResult<Enreplacedy>.DuplicateResult(result)
				: UrlMappingResult<Enreplacedy>.MatchResult(result);
		}

19 View Source File : EntityExtensions.cs
License : MIT License
Project Creator : Adoxio

public static T GetAttributeAliasedValue<T>(this Enreplacedy enreplacedy, string attributeLogicalName, string alias = null)
		{
			if (enreplacedy == null) throw new ArgumentNullException("enreplacedy");
			if (attributeLogicalName == null) throw new ArgumentNullException("attributeLogicalName");

			var prefix = !string.IsNullOrWhiteSpace(alias) ? alias + "." : string.Empty;
			var raw = enreplacedy.GetAttributeValue(prefix + attributeLogicalName);
			var aliasdValue = raw as AliasedValue;
			var intermediate = aliasdValue != null ? aliasdValue.Value : raw;
			var value = GetPrimitiveValue<T>(intermediate);
			return value != null ? (T)value : default(T);
		}

19 View Source File : EntityExtensions.cs
License : MIT License
Project Creator : Adoxio

public static string GetEnumLabel(this Enreplacedy enreplacedy, EnreplacedyMetadata enreplacedyMetadata, string attributeLogicalName, int? languageCode)
		{
			if (enreplacedy == null) throw new ArgumentNullException("enreplacedy");
			if (enreplacedyMetadata == null) throw new ArgumentNullException("enreplacedyMetadata");
			if (string.IsNullOrWhiteSpace(attributeLogicalName)) throw new ArgumentNullException("attributeLogicalName");

			var attributeMetadata = enreplacedyMetadata.Attributes.FirstOrDefault(a => a.LogicalName == attributeLogicalName) as EnumAttributeMetadata;

			if (attributeMetadata == null)
			{
				return null;
			}

			var value = enreplacedy.GetAttributeValue<OptionSetValue>(attributeLogicalName);

			if (value == null)
			{
				return null;
			}

			var option = attributeMetadata.OptionSet.Options.FirstOrDefault(o => o.Value == value.Value);

			if (option == null)
			{
				return null;
			}

			var localizedLabel = option.Label.LocalizedLabels.FirstOrDefault(l => l.LanguageCode == (languageCode ?? 0));

			var label = localizedLabel == null ? option.Label.GetLocalizedLabelString() : localizedLabel.Label;

			return label;
		}

19 View Source File : EntityExtensions.cs
License : MIT License
Project Creator : Adoxio

public static EnreplacedyReference ToLanguageContainerEnreplacedyReference(this Enreplacedy enreplacedy)
		{
			if (enreplacedy.LogicalName == "adx_webpage")
			{
				var rootWebPage = enreplacedy.GetAttributeValue<EnreplacedyReference>("adx_rootwebpageid");
				if (rootWebPage != null)
				{
					return rootWebPage;
				}
			}

			return enreplacedy.ToEnreplacedyReference();
		}

19 View Source File : AdxCmsDataServiceCrmEntityEditingMetadataProvider.cs
License : MIT License
Project Creator : Adoxio

public override void AddEnreplacedyMetadata(string portalName, IEditableCrmEnreplacedyControl control, Control container, Enreplacedy enreplacedy)
			{
				if (control == null || container == null || enreplacedy == null)
				{
					return;
				}

				var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(portalName);
				var portalContext = PortalCrmConfigurationManager.CreatePortalContext(portalName);

				var metadata = ((RetrieveEnreplacedyResponse)serviceContext.Execute(new RetrieveEnreplacedyRequest
				{
					EnreplacedyFilters = EnreplacedyFilters.Enreplacedy,
					LogicalName = enreplacedy.LogicalName
				})).EnreplacedyMetadata;

				var refetchedEnreplacedy = serviceContext.CreateQuery(enreplacedy.LogicalName).FirstOrDefault(e => e.GetAttributeValue<Guid>(metadata.PrimaryIdAttribute) == enreplacedy.Id);

				if (enreplacedy.LogicalName == "adx_weblinkset")
				{
					// Output the service reference for the web link set itself.
					AddEnreplacedyServiceReference(control, enreplacedy, enreplacedy.GetAttributeValue<string>("adx_name"), container);

					// Output the service reference for the child web links of the set.
					AddEnreplacedyreplacedocationSetServiceReferenceForWebLinkSet(control, enreplacedy, "adx_weblinkset_weblink".ToRelationship(), container);
					AddEnreplacedyreplacedocationSetServiceReference(portalName, control, enreplacedy, "adx_weblinkset_weblink".ToRelationship(), container, "xrm-enreplacedy-{0}-update-ref");
					AddEnreplacedySetSchemaMap(control, "adx_weblink", container);

					// Output the service reference and schema map for site web pages (required to create new web links).
					AddEnreplacedySetServiceReference(control, "adx_webpage", container);
					AddEnreplacedySetSchemaMap(control, "adx_webpage", container);

					string weblinkDeleteUriTemplate;

					if (TryGetCrmEnreplacedyDeleteDataServiceUriTemplate(control, "adx_weblink", out weblinkDeleteUriTemplate))
					{
						AddServiceReference(control, weblinkDeleteUriTemplate, "xrm-uri-template xrm-enreplacedy-adx_weblink-delete-ref", container);
					}

					// Output the service reference and schema map for site publishing states (required to create new web links).
					AddEnreplacedySetServiceReference(control, "adx_publishingstate", container);
					AddEnreplacedySetSchemaMap(control, "adx_publishingstate", container);
				}
				else
				{
					string serviceUri;

					if (!TryGetDataServiceEnreplacedyUri(control, enreplacedy, out serviceUri))
					{
						return;
					}

					// Add the service reference to the bound enreplacedy.
					container.Controls.Add(new HyperLink { CssClreplaced = "xrm-enreplacedy-ref", NavigateUrl = VirtualPathUtility.ToAbsolute(serviceUri), Text = string.Empty });

					string enreplacedyUrlServiceUri;

					// Add the service reference for getting the URL of the bound enreplacedy.
					if (TryGetCrmEnreplacedyUrlDataServiceUri(control, enreplacedy, out enreplacedyUrlServiceUri))
					{
						AddServiceReference(control, enreplacedyUrlServiceUri, "xrm-enreplacedy-url-ref", container, "GetEnreplacedyUrl");
					}

					var crmEnreplacedyName = enreplacedy.LogicalName;

					AddEnreplacedySetSchemaMap(control, crmEnreplacedyName, container);

					// If the enreplacedy is "deletable", add a service reference for soft-delete of the enreplacedy.
					if (DeletableEnreplacedyNames.Contains(crmEnreplacedyName))
					{
						string deleteServiceUri;

						if (TryGetCrmEnreplacedyDeleteDataServiceUri(control, enreplacedy, out deleteServiceUri))
						{
							AddServiceReference(control, deleteServiceUri, "xrm-enreplacedy-delete-ref", container);
						}
					}

					if (FileAttachmentEnreplacedyNames.Contains(crmEnreplacedyName))
					{
						string fileAttachmentServiceUri;

						if (TryGetCrmEnreplacedyFileAttachmentDataServiceUri(control, enreplacedy, out fileAttachmentServiceUri))
						{
							AddServiceReference(control, fileAttachmentServiceUri, "xrm-enreplacedy-attachment-ref", container);
						}
					}

					// Add the service references on which the creation of various enreplacedies are dependent.
					foreach (var dependencyEnreplacedyName in DependencyEnreplacedyNames)
					{
						AddEnreplacedySetServiceReference(control, dependencyEnreplacedyName, container);
						AddEnreplacedySetSchemaMap(control, dependencyEnreplacedyName, container);
					}

					// Add the service reference URI Templates for the notes replacedociated with given enreplacedy types.
					foreach (var fileAttachmentEnreplacedy in FileAttachmentEnreplacedyNames)
					{
						string uriTemplate;

						if (TryGetCrmEnreplacedyFileAttachmentDataServiceUriTemplate(control, fileAttachmentEnreplacedy, out uriTemplate))
						{
							AddServiceReference(control, uriTemplate, "xrm-uri-template xrm-enreplacedy-{0}-attachment-ref".FormatWith(fileAttachmentEnreplacedy), container);
						}
					}

					// Add the service reference URI Templates for getting URLs for specific enreplacedy types.
					foreach (var urlEnreplacedyName in UrlEnreplacedyNames)
					{
						string uriTemplate;

						if (TryGetCrmEnreplacedyUrlDataServiceUriTemplate(control, urlEnreplacedyName, out uriTemplate))
						{
							AddServiceReference(control, uriTemplate, "xrm-uri-template xrm-enreplacedy-{0}-url-ref".FormatWith(urlEnreplacedyName), container, "GetEnreplacedyUrl");
						}
					}

					IEnumerable<Relationship> childreplacedociations;

					if (ChildreplacedociationsByEnreplacedyName.TryGetValue(crmEnreplacedyName, out childreplacedociations))
					{
						foreach (var childreplacedociation in childreplacedociations)
						{
							AddEnreplacedyreplacedocationSetServiceReference(portalName, control, enreplacedy, childreplacedociation, container);
						}
					}

					Relationship parentalRelationship2;

					// Output the URL path of parent enreplacedy to the DOM (mostly to be read if the enreplacedy is deleted--the user
					// will then be redirected to the parent).
					if (_parentalRelationshipsByEnreplacedyName.TryGetValue(crmEnreplacedyName, out parentalRelationship2))
					{
						var parent = refetchedEnreplacedy.GetRelatedEnreplacedy(serviceContext, parentalRelationship2);

						var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency<IEnreplacedyUrlProvider>();

						var parentPath = urlProvider.GetApplicationPath(serviceContext, parent ?? refetchedEnreplacedy);

						if (parentPath != null)
						{
							AddServiceReference(control, parentPath.AbsolutePath, "xrm-enreplacedy-parent-url-ref", container);
						}
					}

					// Output the sitemarkers of the current web page into the DOM.
					if (crmEnreplacedyName == "adx_webpage")
					{
						foreach (var siteMarker in refetchedEnreplacedy.GetRelatedEnreplacedies(serviceContext, "adx_webpage_sitemarker"))
						{
							var siteMarkerRef = new HtmlGenericControl("span");

							siteMarkerRef.Attributes["clreplaced"] = "xrm-enreplacedy-adx_webpage_sitemarker";
							siteMarkerRef.Attributes["replacedle"] = siteMarker.GetAttributeValue<string>("adx_name");

							container.Controls.Add(siteMarkerRef);
						}

						AddEnreplacedySetSchemaMap(control, "adx_webfile", container);

						EnreplacedySetInfo enreplacedySetInfo;

						if (OrganizationServiceContextInfo.TryGet(GetCrmDataContextType(), "adx_communityforum", out enreplacedySetInfo))
						{
							AddEnreplacedySetSchemaMap(control, "adx_communityforum", container);
							AddEnreplacedySetServiceReference(control, "adx_communityforum", container);
						}

						if (OrganizationServiceContextInfo.TryGet(GetCrmDataContextType(), "adx_event", out enreplacedySetInfo))
						{
							AddEnreplacedySetSchemaMap(control, "adx_event", container);
							AddEnreplacedySetServiceReference(control, "adx_event", container);
						}

						AddEnreplacedySetSchemaMap(control, "adx_shortcut", container);

						AddEnreplacedySetServiceReference(control, "adx_webpage", container);
						AddEnreplacedySetServiceReference(control, "adx_webfile", container);
					
						AddPublishingTransitionSetServiceReference(control, container);
					}

					if (enreplacedy.LogicalName == "adx_event")
					{
						AddEnreplacedySetSchemaMap(control, "adx_eventschedule", container);
						AddPicklistMetadata(serviceContext, control, "adx_eventschedule", "adx_recurrence", container);
					}
				}

				var previewPermission = new PreviewPermission(portalContext.ServiceContext, portalContext.Website);

				if (previewPermission.IsPermitted)
				{
					var previewPermittedMetadata = new HtmlGenericControl("span");

					previewPermittedMetadata.Attributes["clreplaced"] = "xrm-preview-permitted";
					previewPermittedMetadata.Attributes["style"] = "display:none;";

					container.Controls.Add(previewPermittedMetadata);
				}

				Relationship parentalRelationship;

				// Output the URL path of parent enreplacedy to the DOM (mostly to be read if the enreplacedy is deleted--the user
				// will then be redirected to the parent).
				if (_parentalRelationshipsByEnreplacedyName.TryGetValue(enreplacedy.LogicalName, out parentalRelationship))
				{
					var parent = refetchedEnreplacedy.GetRelatedEnreplacedy(serviceContext, parentalRelationship);

					var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency<IEnreplacedyUrlProvider>();

					var parentPath = urlProvider.GetApplicationPath(serviceContext, parent ?? refetchedEnreplacedy);

					if (parentPath != null)
					{
						AddServiceReference(control, parentPath.AbsolutePath, "xrm-adx-enreplacedy-parent-url-ref", container);
					}
				}
			}

See More Examples