public async Task Get(string[] contentTypeIds, string parent) { var contentTypes = contentTypeIds.Select(t => ContentTypeProvider.Get(t)).ToList().AsReadOnly(); if (contentTypes.Count > 1) { throw new NotImplementedException("Multi type queries are not yet implemented"); } var items = new List <object>(); var itemChildrenCounts = new Dictionary <string, int>(); var documentsQuery = ContentFinder.Find(contentTypes.Single().Type); if (parent != null) { documentsQuery.WhereParent(parent); } else { documentsQuery.WhereHasNoParent(); } var documents = (await documentsQuery.GetResultAsync().ConfigureAwait(false)).ToList(); foreach (var content in documents) { items.Add(content); if (content is IHierarchical) { var id = PrimaryKeyGetter.Get(content); itemChildrenCounts[string.Join(",", id)] = await ContentChildrenCounter.CountChildrenForAsync(id).ConfigureAwait(false); } } //var sortByPropertyName = typeof(INameable).IsAssignableFrom(contentType.Type) ? "Name" : "Id"; //var sortByProperty = PropertyDefinitionProvider.GetFor(contentType.Id).FirstOrDefault(p => p.Name == sortByPropertyName); //if (sortByProperty != null) //{ // result = result.OrderBy(i => sortByProperty.Getter(i)).ToList(); //} Response.ContentType = "application/json"; await Response.WriteAsync(JsonConvert.SerializeObject(new ContentListResult { Items = items, ItemChildrenCounts = itemChildrenCounts }, new JsonSerializerSettings { Formatting = Formatting.Indented, ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = new List <JsonConverter> { PolymorphicFormConverter } })); }
public async Task <IEnumerable <Item> > GetAll(string type, ItemQuery query) { var result = new List <Item>(); var contentType = ContentTypeProvider.Get(type); foreach (var content in await ContentFinder.Find(contentType.Type).GetResultAsync().ConfigureAwait(false)) { result.Add(GetItem(content)); } return(result.AsReadOnly()); }
public void TestFind() { using (var kernel = TestHelper.CreateKernel()) { using (ISession session = kernel.Get<ISession>()) { DatabaseHelper.GenerateDatabase(session); IContentFinder contentFinder = new ContentFinder(session); Page page = contentFinder.Find<Page>("~/child/grand-child"); Assert.NotNull(page); Assert.Equal("Grand Child", page.Title); page = contentFinder.Find<Page>("~"); Assert.NotNull(page); Assert.Equal("Parent", page.Title); Assert.Null(page.Parent); Assert.IsType<HomePage>(page); page = contentFinder.Find<Page>("~/child/other"); Assert.Null(page); } } }
public void NonUniqueUrlThrowsException() { using (var kernel = TestHelper.CreateKernel()) { using (var session = kernel.Get<ISession>()) { DatabaseHelper.GenerateDatabase(session); // Create a duplicate url (parent/child) HomePage home2 = new HomePage() { UrlSegment = "~" }; Page child2 = new Page() { UrlSegment = "child" }; home2.AddChildren(child2); session.Save(home2); IContentFinder contentFinder = new ContentFinder(session); Assert.Throws<System.Exception>(()=> contentFinder.Find<Page>("~/child") ); } } }
public IEnumerable <Option> GetAll() { var contentTypes = ContentTypeProvider.GetAll().Where(t => typeof(IHierarchical).IsAssignableFrom(t.Type)); var result = new List <Option>(); foreach (var contentType in contentTypes) { var documents = ContentFinder.Find(contentType.Type).GetResultAsync().Result.ToList(); foreach (var content in documents) { var id = "{" + string.Join(",", PrimaryKeyGetter.Get(content)) + "}"; result.Add(new Option((content as INameable).Name ?? id, id)); } } result = result.OrderBy(i => i.Value).ToList(); result.Insert(0, new Option("(root)", null)); return(result.AsReadOnly()); }