string IRawDataProvider.GetPageContent(string urlPath, Localization localization)
        {
            // TODO: let the DXA Model Service provide raw Page Content too (?)
            using (new Tracer(urlPath, localization))
            {
                if (!urlPath.EndsWith(Constants.DefaultExtension) && !urlPath.EndsWith(".json"))
                {
                    urlPath += Constants.DefaultExtension;
                }
                string escapedUrlPath = Uri.EscapeUriString(urlPath);
                global::Tridion.ContentDelivery.DynamicContent.Query.Query brokerQuery = new global::Tridion.ContentDelivery.DynamicContent.Query.Query
                {
                    Criteria = CriteriaFactory.And(new Criteria[]
                    {
                        new PageURLCriteria(escapedUrlPath),
                        new PublicationCriteria(Convert.ToInt32(localization.Id)),
                        new ItemTypeCriteria(64)
                    })
                };

                string[] pageUris = brokerQuery.ExecuteQuery();
                if (pageUris.Length == 0)
                {
                    return(null);
                }
                if (pageUris.Length > 1)
                {
                    throw new DxaException($"Broker Query for Page URL path '{urlPath}' in Publication '{localization.Id}' returned {pageUris.Length} results.");
                }

                PageContentAssembler pageContentAssembler = new PageContentAssembler();
                return(pageContentAssembler.GetContent(pageUris[0]));
            }
        }
        public IEnumerable <Teaser> ExecuteQuery()
        {
            Criteria criteria = BuildCriteria();

            global::Tridion.ContentDelivery.DynamicContent.Query.Query query = new global::Tridion.ContentDelivery.DynamicContent.Query.Query(criteria);
            if (!String.IsNullOrEmpty(Sort) && Sort.ToLower() != "none")
            {
                query.AddSorting(GetSortParameter());
            }
            if (MaxResults > 0)
            {
                query.SetResultFilter(new LimitFilter(MaxResults));
            }
            if (PageSize > 0)
            {
                //We set the page size to one more than what we need, to see if there are more pages to come...
                query.SetResultFilter(new PagingFilter(Start, PageSize + 1));
            }
            try
            {
                ComponentMetaFactory componentMetaFactory = new ComponentMetaFactory(PublicationId);
                List <Teaser>        results = new List <Teaser>();
                string[]             ids     = query.ExecuteQuery();
                HasMore = ids.Length > PageSize;
                int count = 0;
                foreach (string compId in ids)
                {
                    if (count >= PageSize)
                    {
                        break;
                    }
                    IComponentMeta compMeta = componentMetaFactory.GetMeta(compId);
                    if (compMeta != null)
                    {
                        results.Add(GetTeaserFromMeta(compMeta));
                    }
                    count++;
                }
                return(results);
            }
            catch (Exception ex)
            {
                throw new DxaException("Error executing Broker Query", ex);
            }
        }
 public IEnumerable<Teaser> ExecuteQuery()
 {
     Criteria criteria = BuildCriteria();
     global::Tridion.ContentDelivery.DynamicContent.Query.Query query = new global::Tridion.ContentDelivery.DynamicContent.Query.Query(criteria);
     if (!String.IsNullOrEmpty(Sort) && Sort.ToLower() != "none")
     {
         query.AddSorting(GetSortParameter());
     }
     if (MaxResults > 0)
     {
         query.SetResultFilter(new LimitFilter(MaxResults));
     }
     if (PageSize > 0)
     {
         //We set the page size to one more than what we need, to see if there are more pages to come...
         query.SetResultFilter(new PagingFilter(Start, PageSize + 1));
     }
     try
     {
         ComponentMetaFactory componentMetaFactory = new ComponentMetaFactory(PublicationId);
         List<Teaser> results = new List<Teaser>();
         string[] ids = query.ExecuteQuery();
         HasMore = ids.Length > PageSize;
         int count = 0;
         foreach (string compId in ids)
         {
             if (count >= PageSize)
             {
                 break;
             }
             IComponentMeta compMeta = componentMetaFactory.GetMeta(compId);
             if (compMeta != null)
             {
                 results.Add(GetTeaserFromMeta(compMeta));
             }
             count++;
         }
         return results;
     }
     catch (Exception ex)
     {
         throw new DxaException("Error executing Broker Query", ex);
     }
 }
示例#4
0
        internal IEnumerable <string> ExecuteQuery()
        {
            Criteria criteria = BuildCriteria();

            global::Tridion.ContentDelivery.DynamicContent.Query.Query query = new global::Tridion.ContentDelivery.DynamicContent.Query.Query(criteria);
            if (!string.IsNullOrEmpty(_queryParameters.Sort) && _queryParameters.Sort.ToLower() != "none")
            {
                query.AddSorting(GetSortParameter());
            }
            if (_queryParameters.MaxResults > 0)
            {
                query.SetResultFilter(new LimitFilter(_queryParameters.MaxResults));
            }

            int pageSize = _queryParameters.PageSize;

            if (pageSize > 0)
            {
                //We set the page size to one more than what we need, to see if there are more pages to come...
                query.SetResultFilter(new PagingFilter(_queryParameters.Start, pageSize + 1));
            }
            try
            {
                string[] componentIds = query.ExecuteQuery();
                if (componentIds == null)
                {
                    return(new string[0]);
                }

                HasMore = componentIds.Length > pageSize;

                return((pageSize > 0) ? componentIds.Take(pageSize) : componentIds);
            }
            catch (Exception ex)
            {
                throw new DxaException("Error executing Broker Query", ex);
            }
        }
        internal IEnumerable<EntityModel> ExecuteQuery(Type resultType)
        {
            Criteria criteria = BuildCriteria();
            global::Tridion.ContentDelivery.DynamicContent.Query.Query query = new global::Tridion.ContentDelivery.DynamicContent.Query.Query(criteria);
            if (!string.IsNullOrEmpty(_queryParameters.Sort) && _queryParameters.Sort.ToLower() != "none")
            {
                query.AddSorting(GetSortParameter());
            }
            if (_queryParameters.MaxResults > 0)
            {
                query.SetResultFilter(new LimitFilter(_queryParameters.MaxResults));
            }
            if (_queryParameters.PageSize > 0)
            {
                //We set the page size to one more than what we need, to see if there are more pages to come...
                query.SetResultFilter(new PagingFilter(_queryParameters.Start, _queryParameters.PageSize + 1));
            }
            try
            {
                List<EntityModel> models = new List<EntityModel>();

                string[] componentIds = query.ExecuteQuery();
                if (componentIds == null || componentIds.Length == 0)
                {
                    return models;
                }

                ComponentMetaFactory componentMetaFactory = new ComponentMetaFactory(_queryParameters.PublicationId);
                int pageSize = _queryParameters.PageSize;
                int count = 0;
                foreach (string componentId in componentIds)
                {
                    IComponentMeta componentMeta = componentMetaFactory.GetMeta(componentId);
                    DD4T.ContentModel.IComponent dd4tComponent = CreateComponent(componentMeta);
                    EntityModel model = ModelBuilderPipeline.CreateEntityModel(dd4tComponent, resultType, _queryParameters.Localization);
                    models.Add(model);
                    if (++count == pageSize)
                    {
                        break;
                    }
                }
                HasMore = componentIds.Length > count;
                return models;
            }
            catch (Exception ex)
            {
                throw new DxaException("Error executing Broker Query", ex);
            }
        }