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 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); }
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()); }