private Lazy <string> GetLazyWebPageUrl(IPortalViewContext portalViewContext, EntityReference webPage) { if (portalViewContext == null) { return(new Lazy <string>(() => null, LazyThreadSafetyMode.None)); } if (webPage == null) { return(new Lazy <string>(() => null, LazyThreadSafetyMode.None)); } return(new Lazy <string>(() => { var urlProvider = portalViewContext.UrlProvider; if (urlProvider == null) { return null; } using (var serviceContext = portalViewContext.CreateServiceContext()) { var entity = serviceContext.CreateQuery("adx_webpage") .FirstOrDefault(e => e.GetAttributeValue <Guid>("adx_webpageid") == webPage.Id && e.GetAttributeValue <int?>("statecode") == 0); return entity == null ? null : urlProvider.GetUrl(serviceContext, entity); } }, LazyThreadSafetyMode.None)); }
private Tuple <ViewConfiguration, int> GetViewConfigurationFromAttributes(IPortalViewContext portalViewContext, Context context) { var view = GetViewFromAttributes(portalViewContext, context); if (view == null) { return(null); } var configuration = new ViewConfiguration(view) { EnableEntityPermissions = true }; configuration.Search.Enabled = true; string languageCode; int parsedLanguageCode; if ((TryGetAttributeValue(context, "languagecode", out languageCode) || TryGetAttributeValue(context, "language_code", out languageCode)) && int.TryParse(languageCode, out parsedLanguageCode)) { return(new Tuple <ViewConfiguration, int>(configuration, parsedLanguageCode)); } return(new Tuple <ViewConfiguration, int>(configuration, 0)); }
private Tuple <ViewConfiguration, int> GetViewConfiguration(IPortalViewContext portalViewContext, Context context) { var entityList = context[EntityList.ScopeVariableName] as EntityListDrop; return(entityList == null ? GetViewConfigurationFromAttributes(portalViewContext, context) : GetViewConfigurationFromEntityListContext(context, entityList)); }
public EntityRecordMoneyFormatInfo(IPortalViewContext portalViewContext, Entity record) : base(portalViewContext) { if (record == null) { throw new ArgumentNullException("record"); } _record = record; }
protected MoneyFormatInfo(IPortalViewContext portalViewContext) : this() { if (portalViewContext == null) { throw new ArgumentNullException("portalViewContext"); } _getServiceContext = portalViewContext.CreateServiceContext; }
private static IEnumerable <Tuple <string, string, int> > ContentStyles(IPortalViewContext portalViewContext, SiteMapNode node, IDictionary <string, object> cache) { if (node == null) { return(Enumerable.Empty <Tuple <string, string, int> >()); } var cacheKey = "{0}:ContentStyles:{1}".FormatWith(typeof(StyleExtensions).FullName, node.Url); object cached; if (cache.TryGetValue(cacheKey, out cached) && cached is IEnumerable <Tuple <string, string, int> > ) { return(cached as IEnumerable <Tuple <string, string, int> >); } // Get all adx_webpages in the site map path, starting from and including the current entity. These are // potential containers for content-managed stylesheets. var path = new List <EntityReference>(); var current = node; while (current != null) { var entityNode = current as CrmSiteMapNode; if (entityNode != null && entityNode.HasCrmEntityName("adx_webpage")) { path.Add(entityNode.Entity.ToEntityReference()); } current = current.ParentNode; } if (!path.Any()) { return(Enumerable.Empty <Tuple <string, string, int> >()); } var contentMapProvider = AdxstudioCrmConfigurationManager.CreateContentMapProvider(portalViewContext.PortalName); var styles = contentMapProvider == null ? ContentStyles(portalViewContext, path) : ContentStyles(portalViewContext, path, contentMapProvider); cache[cacheKey] = styles; return(styles); }
private static IEnumerable <Tuple <string, string, int> > ContentStyles(IPortalViewContext portalViewContext, List <EntityReference> path) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Getting content styles using query."); var serviceContext = portalViewContext.CreateServiceContext(); var parentPageConditions = path.Select(reference => new Condition("adx_parentpageid", ConditionOperator.Equal, reference.Id)).ToList(); var fetch = new Fetch { Entity = new FetchEntity("adx_webfile") { Filters = new List <Filter> { new Filter { Type = LogicalOperator.And, Conditions = new List <Condition> { new Condition("adx_websiteid", ConditionOperator.Equal, portalViewContext.Website.EntityReference.Id), new Condition("statecode", ConditionOperator.Equal, 0), new Condition("adx_partialurl", ConditionOperator.EndsWith, ".css") }, Filters = new List <Filter> { new Filter { Type = LogicalOperator.Or, Conditions = parentPageConditions } } } } } }; return(serviceContext.RetrieveMultiple(fetch).Entities .Select(e => new { PathOffset = path.FindIndex(pathItem => pathItem.Equals(e.GetAttributeValue <EntityReference>("adx_parentpageid"))), DisplayOrder = e.GetAttributeValue <int?>("adx_displayorder").GetValueOrDefault(0), Url = serviceContext.GetUrl(e), PartialUrl = e.GetAttributeValue <string>("adx_partialurl") }) .Where(e => !string.IsNullOrEmpty(e.Url)) .OrderByDescending(e => e.PathOffset) .ThenBy(e => e.DisplayOrder) .Select(e => new Tuple <string, string, int>(e.Url, e.PartialUrl, e.PathOffset)) .ToArray()); }
private void ExecuteResult(IPortalViewContext portalViewContext, HttpContextBase context) { if (portalViewContext != null) { var siteMarker = this.RestrictRead ? portalViewContext.SiteMarkers.SelectWithReadAccess(this.SiteMarker) : portalViewContext.SiteMarkers.Select(this.SiteMarker); if (siteMarker != null) { var url = this.Query != null ? siteMarker.Url.AppendQueryString(this.Query) : siteMarker.Url; context.RedirectAndEndResponse(url); } } }
private SavedQueryView GetViewFromAttributes(IPortalViewContext portalViewContext, Context context) { string viewId; Guid parsedViewId; if (TryGetAttributeValue(context, "id", out viewId) && Guid.TryParse(viewId, out parsedViewId)) { return(new SavedQueryView(portalViewContext.CreateServiceContext(), parsedViewId)); } string entityLogicalName; string viewName; if ((TryGetAttributeValue(context, "logicalname", out entityLogicalName) || TryGetAttributeValue(context, "logical_name", out entityLogicalName)) && TryGetAttributeValue(context, "name", out viewName)) { return(new SavedQueryView(portalViewContext.CreateServiceContext(), entityLogicalName, viewName)); } return(null); }
public PortalLiquidContext(HtmlHelper html, IPortalViewContext portalViewContext) { if (html == null) { throw new ArgumentNullException("html"); } if (portalViewContext == null) { throw new ArgumentNullException("portalViewContext"); } Html = html; PortalViewContext = portalViewContext; _organizationMoneyFormatInfo = new Lazy <IOrganizationMoneyFormatInfo>(GetOrganizationMoneyFormatInfo, LazyThreadSafetyMode.None); _random = new Lazy <Random>(() => new Random(), LazyThreadSafetyMode.None); _urlHelper = new Lazy <UrlHelper>(GetUrlHelper, LazyThreadSafetyMode.None); _contextLanguageInfo = new Lazy <ContextLanguageInfo>(GetContextLanguageInfo, LazyThreadSafetyMode.None); _portalOrganizationService = new Lazy <IOrganizationService>(GetPortalOrganizationService, LazyThreadSafetyMode.None); }
private static IEnumerable <Tuple <string, string, int> > ContentStyles(IPortalViewContext portalViewContext, IEnumerable <EntityReference> path, IContentMapProvider contentMapProvider) { var urlProvider = PortalCrmConfigurationManager.CreateDependencyProvider(portalViewContext.PortalName).GetDependency <IContentMapEntityUrlProvider>(); if (urlProvider == null) { return(Enumerable.Empty <Tuple <string, string, int> >()); } ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Getting content styles using Content Map."); var cssWebFileNodes = contentMapProvider.Using(map => path.SelectMany((pathItem, pathOffset) => { WebPageNode webPage; // Guard against null reference exception on webPage.WebFiles. This might happen if WebPage is a translated content, but for whatever reason has no root web page. if (!map.TryGetValue(pathItem, out webPage) || webPage.WebFiles == null) { return(Enumerable.Empty <Tuple <int, int, string, string> >()); } return(webPage.WebFiles .Where(e => e.PartialUrl != null && e.PartialUrl.EndsWith(".css")) .Select(e => new Tuple <int, int, string, string>( pathOffset, e.DisplayOrder.GetValueOrDefault(0), urlProvider.GetUrl(map, e), e.PartialUrl))); })); return(cssWebFileNodes .Where(e => !string.IsNullOrEmpty(e.Item3)) .OrderByDescending(e => e.Item1) .ThenBy(e => e.Item2) .Select(e => new Tuple <string, string, int>(e.Item3, e.Item4, e.Item1)) .ToArray()); }
private static IHtmlString EntityEditingMetadata(IPortalViewEntity entity, IPortalViewContext portalViewContext, string cssClass = null) { if (entity == null) { return(new HtmlString(string.Empty)); } if (!entity.Editable) { return(new HtmlString(string.Empty)); } if (portalViewContext == null) { throw new ArgumentNullException("portalViewContext"); } var tag = new TagBuilder("div"); tag.Attributes["style"] = "display:none;"; tag.AddCssClass("xrm-entity"); tag.AddCssClass("xrm-editable-{0}".FormatWith(entity.EntityReference.LogicalName)); if (portalViewContext.IsCurrentSiteMapNode(entity)) { tag.AddCssClass("xrm-entity-current"); } if (!String.IsNullOrEmpty(cssClass)) { tag.AddCssClass(cssClass); } portalViewContext.RenderEditingMetadata(entity, tag); return(new HtmlString(tag.ToString())); }
public EntityFileSystem(IPortalViewContext portalViewContext, string entityLogicalName, string nameAttributeLogicalName, string sourceAttributeLogicalName) { if (portalViewContext == null) { throw new ArgumentNullException("portalViewContext"); } if (entityLogicalName == null) { throw new ArgumentNullException("entityLogicalName"); } if (nameAttributeLogicalName == null) { throw new ArgumentNullException("nameAttributeLogicalName"); } if (sourceAttributeLogicalName == null) { throw new ArgumentNullException("sourceAttributeLogicalName"); } PortalViewContext = portalViewContext; EntityLogicalName = entityLogicalName; NameAttributeLogicalName = nameAttributeLogicalName; SourceAttributeLogicalName = sourceAttributeLogicalName; }
private static IEnumerable <string> ContentStyles(IPortalViewContext portalViewContext, SiteMapNode node, IDictionary <string, object> cache, IEnumerable <string> except, IEnumerable <KeyValuePair <string, string> > only) { var styles = ContentStyles(portalViewContext, node, cache).ToArray(); string[] allDisplayModes; string[] availableDisplayModes; if (TryGetDisplayModes(out allDisplayModes, out availableDisplayModes)) { var partialUrlTrie = new FileNameTrie(styles); var displayModeComparer = new DisplayModeComparer(availableDisplayModes); var groups = GetDisplayModeFileGroups(partialUrlTrie, allDisplayModes); if (only != null) { return(only.Select(o => { var extensionless = Path.GetFileNameWithoutExtension(o.Key); var matchGroup = groups.FirstOrDefault(s => string.Equals(s.Prefix, extensionless, StringComparison.OrdinalIgnoreCase)); if (matchGroup == null) { return o.Value; } var file = matchGroup.Where(f => availableDisplayModes.Contains(f.DisplayModeId)) .OrderBy(f => f, displayModeComparer) .FirstOrDefault(); return file == null ? o.Value : file.Name.Item1; })); } if (except != null) { return(groups .Where(group => !except.Any(e => string.Equals(Path.GetFileNameWithoutExtension(e), group.Prefix, StringComparison.OrdinalIgnoreCase))) .Select(group => group.Where(f => availableDisplayModes.Contains(f.DisplayModeId)) .OrderBy(f => f, displayModeComparer) .FirstOrDefault()) .Where(f => f != null) .Select(f => f.Name.Item1)); } return(groups .Select(group => group.Where(f => availableDisplayModes.Contains(f.DisplayModeId)) .OrderBy(f => f, displayModeComparer) .FirstOrDefault()) .Where(f => f != null) .Select(f => f.Name.Item1)); } if (only != null) { return(only.Select(o => { var match = styles.FirstOrDefault(s => string.Equals(s.Item2, o.Key, StringComparison.InvariantCultureIgnoreCase)); return match == null ? o.Value : match.Item1; })); } if (except != null) { return(styles .Where(s => !except.Any(e => string.Equals(e, s.Item2, StringComparison.InvariantCultureIgnoreCase))) .Select(s => s.Item1)); } return(styles.Select(s => s.Item1)); }
public OrganizationMoneyFormatInfo(IPortalViewContext portalViewContext) : base(portalViewContext) { _organization = new Lazy <Entity>(GetOrganization, LazyThreadSafetyMode.None); }