Exemplo n.º 1
0
        private static async Task RenderOptions(ContentDeliveryService service, string projectAlias)
        {
            System.Console.WriteLine(" ");
            // List options for Content Delivery (Content + Media)
            System.Console.WriteLine("[A] Fetch and show Content tree");
            System.Console.WriteLine("[B] Fetch and show Media tree");
            System.Console.WriteLine("[C] Show root Content");
            System.Console.WriteLine("[D] Show root Media");
            System.Console.WriteLine("[E] List Content URLs");
            System.Console.WriteLine("[F] Upload image to Media Library");
            System.Console.WriteLine("[X] Exit");
            System.Console.WriteLine(" ");

            System.Console.WriteLine("Enter your choice:");
            var choice = System.Console.ReadLine()?.ToUpper();

            if (string.IsNullOrEmpty(choice))
            {
                System.Console.WriteLine("Please enter option A, B, C, D or E");
                choice = System.Console.ReadLine()?.ToUpper();
            }

            // Retrieve and show based on choice
            await CmdOptions[choice](service, projectAlias);

            //Recurse unless we need to escape and quit the console
            if (!choice.Equals("X"))
            {
                await RenderOptions(service, projectAlias);
            }
        }
        public async Task Can_Retrieve_Content_By_Url(string url)
        {
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_contentBaseUrl}/url", ContentDeliveryJson.GetByUrlHomeProductsUnicorn));
            var content = await service.Content.GetByUrl(url);

            Assert.NotNull(content);
            Assert.NotEmpty(content.Properties);
        }
        public async Task Can_Retrieve_Root_Content()
        {
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_contentBaseUrl}", ContentDeliveryJson.GetRoot));
            var contentItems = await service.Content.GetRoot();

            Assert.NotNull(contentItems);
            Assert.NotEmpty(contentItems);
            Assert.Single(contentItems);
        }
        public async Task Can_Retrieve_Root_Media()
        {
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_mediaBaseUrl}", MediaDeliveryJson.GetRoot));
            var mediaItems = await service.Media.GetRoot();

            Assert.NotNull(mediaItems);
            Assert.NotEmpty(mediaItems);
            Assert.Equal(4, mediaItems.Count());
        }
        public async Task Can_Retrieve_Ancestors_By_Id(string id)
        {
            var contentId = Guid.Parse(id);
            var service   = new ContentDeliveryService(_configuration,
                                                       GetMockedHttpClient($"{_contentBaseUrl}/{id}/ancestors", ContentDeliveryJson.GetAncestors));
            var ancestors = await service.Content.GetAncestors(contentId);

            Assert.NotNull(ancestors);
            Assert.NotEmpty(ancestors);
            Assert.Equal(2, ancestors.Count());
        }
        public async Task Can_Retrieve_Media_Item_By_Id(string id)
        {
            var mediaId = Guid.Parse(id);
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_mediaBaseUrl}/*", MediaDeliveryJson.GetMediaByIdMediaItem));
            var media = await service.Media.GetById(mediaId);

            Assert.NotNull(media);
            Assert.NotEmpty(media.Properties);
            Assert.Equal(6, media.Properties.Count);
        }
        public async Task Can_Retrieve_Content_By_Id(string id)
        {
            var contentId = Guid.Parse(id);
            var service   = new ContentDeliveryService(_configuration,
                                                       GetMockedHttpClient($"{_contentBaseUrl}/*", ContentDeliveryJson.GetContentById));
            var content = await service.Content.GetById(contentId);

            Assert.NotNull(content);
            Assert.NotEmpty(content.Properties);
            Assert.Equal(16, content.Properties.Count);
        }
        public async Task Can_Search()
        {
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_contentBaseUrl}/search?term=jacket", ContentDeliveryJson.Search));
            var result = await service.Content.Search("jacket");

            Assert.NotNull(result);
            Assert.NotNull(result.Content);
            Assert.NotEmpty(result.Content.Items);
            Assert.Equal(1, result.TotalPages);
            Assert.Equal(1, result.TotalItems);
        }
        public async Task Can_Retrieve_Content_By_Type(string contentType)
        {
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_contentBaseUrl}/type?contentType={contentType}", ContentDeliveryJson.GetByType));
            var ofType = await service.Content.GetByType(contentType);

            Assert.NotNull(ofType);
            Assert.NotNull(ofType.Content);
            Assert.NotEmpty(ofType.Content.Items);
            Assert.Equal(1, ofType.TotalPages);
            Assert.Equal(8, ofType.TotalItems);
        }
Exemplo n.º 10
0
        public async Task Can_Retrieve_Typed_Content_By_Id(string id)
        {
            var contentId = Guid.Parse(id);
            var service   = new ContentDeliveryService(_configuration,
                                                       GetMockedHttpClient($"{_contentBaseUrl}/*", ContentDeliveryJson.GetContentById));
            var content = await service.Content.GetById <StarterkitHome>(contentId);

            Assert.NotNull(content);
            Assert.NotNull(content.HeroCtalink);
            Assert.NotNull(content.HeroCtalink.Links);
            Assert.NotNull(content.HeroBackgroundImage);
            Assert.False(string.IsNullOrEmpty(content.HeroHeader));
        }
        public async Task Can_Retrieve_Children_By_ParentId(string id)
        {
            var contentId = Guid.Parse(id);
            var service   = new ContentDeliveryService(_configuration,
                                                       GetMockedHttpClient($"{_contentBaseUrl}/{id}/children", ContentDeliveryJson.GetChildrenByParentId));
            var children = await service.Content.GetChildren(contentId);

            Assert.NotNull(children);
            Assert.NotNull(children.Content);
            Assert.NotEmpty(children.Content.Items);
            Assert.Equal(5, children.TotalItems);
            Assert.Equal(1, children.TotalPages);
            Assert.Equal(1, children.Page);
        }
Exemplo n.º 12
0
        public static async Task FetchMediaTree(ContentDeliveryService service, string projectAlias)
        {
            System.Console.WriteLine(" ");
            System.Console.WriteLine("Fetching and listing Media tree");
            System.Console.WriteLine(" ");

            var root = await service.Media.GetRoot();

            foreach (var media in root)
            {
                await PrintTree(service.Media, media, "", true);
            }

            System.Console.WriteLine(" ");
        }
Exemplo n.º 13
0
        public static async Task ShowRootContent(ContentDeliveryService service, string projectAlias)
        {
            System.Console.WriteLine(" ");
            System.Console.WriteLine("Fetching and showing root Content");
            System.Console.WriteLine(" ");

            var rootContentItems = await service.Content.GetRoot();

            foreach (var rootContentItem in rootContentItems)
            {
                RenderContentWithUrl(rootContentItem);
            }

            System.Console.WriteLine(" ");
        }
Exemplo n.º 14
0
        public static async Task ShowRootMedia(ContentDeliveryService service, string projectAlias)
        {
            System.Console.WriteLine(" ");
            System.Console.WriteLine("Fetching and showing root Media");
            System.Console.WriteLine(" ");

            var rootMediaItems = await service.Media.GetRoot();

            foreach (var media in rootMediaItems)
            {
                RenderMediaWithUrl(media);
            }

            System.Console.WriteLine(" ");
        }
        public async Task Can_Filter()
        {
            var filter = new ContentFilter("product",
                                           new[] { new ContentFilterProperties("productName", "Jacket", ContentFilterMatch.Contains) });

            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient(HttpMethod.Post, $"{_contentBaseUrl}/filter", ContentDeliveryJson.Search));//result is the same as with search so reusing the json
            var result = await service.Content.Filter(filter);

            Assert.NotNull(result);
            Assert.NotNull(result.Content);
            Assert.NotEmpty(result.Content.Items);
            Assert.Equal(1, result.TotalPages);
            Assert.Equal(1, result.TotalItems);
        }
        public async Task Can_Retrieve_Root_Media_as_Typed_Folders()
        {
            // NOTE: One remark here, as we currently don't have a ContentType filter for these types of calls
            // this will try to deserialize the entire list to the specified type.
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_mediaBaseUrl}", MediaDeliveryJson.GetRoot));
            var mediaItems = await service.Media.GetRoot <Folder>();

            Assert.NotNull(mediaItems);
            Assert.NotEmpty(mediaItems);

            foreach (var folder in mediaItems)
            {
                Assert.Equal("Folder", folder.MediaTypeAlias);
            }
        }
Exemplo n.º 17
0
        public async Task Can_Retrieve_Content_Children_Typed(string id)
        {
            var parentId = Guid.Parse(id);
            var service  = new ContentDeliveryService(_configuration,
                                                      GetMockedHttpClient($"{_contentBaseUrl}/*", ContentDeliveryJson.GetChildrenOfProducts));
            var pagedContent = await service.Content.GetChildren <Product>(parentId);

            Assert.NotNull(pagedContent);
            Assert.NotNull(pagedContent.Content);
            Assert.NotEmpty(pagedContent.Content.Items);
            foreach (var contentItem in pagedContent.Content.Items)
            {
                Assert.NotNull(contentItem);
                Assert.False(string.IsNullOrEmpty(contentItem.ProductName));
            }
        }
        public async Task Can_Retrieve_Typed_MediaFile_By_Id(string id)
        {
            var mediaId = Guid.Parse(id);
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_mediaBaseUrl}/*", MediaDeliveryJson.GetMediaByIdMediaItem));
            var media = await service.Media.GetById <Image>(mediaId);

            Assert.NotNull(media);
            Assert.NotNull(media.File);
            Assert.Null(media.File.Crops);
            Assert.Null(media.File.FocalPoint);
            Assert.Equal("/media/l3ifqpfg/chewbacca.png", media.File.Src);
            Assert.Equal("png", media.Extension);
            Assert.Equal(288031, media.Bytes);
            Assert.Equal(450, media.Width);
            Assert.Equal(600, media.Height);
        }
Exemplo n.º 19
0
        public static async Task ListAllContentUrls(ContentDeliveryService service, string projectAlias)
        {
            System.Console.WriteLine(" ");
            System.Console.WriteLine("Fetching and showing all Content Urls");
            System.Console.WriteLine(" ");

            var rootContentItems = await service.Content.GetRoot();

            foreach (var rootContentItem in rootContentItems)
            {
                RenderContentWithUrl(rootContentItem);
                var descendants = await service.Content.GetDescendants(rootContentItem.Id);
                await PageAndRenderDescendants(service.Content, descendants, rootContentItem.Id, descendants.Page);
            }

            System.Console.WriteLine(" ");
        }
        public async Task Can_Retrieve_Descendants_By_Id(string id, int page)
        {
            var contentId = Guid.Parse(id);
            var json      = page == 1
                ? ContentDeliveryJson.GetDescendantsPageOne
                : (page == 2 ? ContentDeliveryJson.GetDescendantsPageTwo : ContentDeliveryJson.GetDescendantsPageThree);
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_contentBaseUrl}/{id}/descendants", json));
            var descendants = await service.Content.GetDescendants(contentId, page : page);

            Assert.NotNull(descendants);
            Assert.NotNull(descendants.Content);
            Assert.NotEmpty(descendants.Content.Items);
            Assert.Equal(page, descendants.Page);
            Assert.Equal(3, descendants.TotalPages);
            Assert.Equal(23, descendants.TotalItems);
        }
Exemplo n.º 21
0
        public async Task Can_Retrieve_Content_By_TypeAlias_Typed(string contentTypeAlias)
        {
            var service = new ContentDeliveryService(_configuration,
                                                     GetMockedHttpClient($"{_contentBaseUrl}/type?contentType={contentTypeAlias}", ContentDeliveryJson.GetByType));
            var pagedContent = await service.Content.GetByTypeAlias <Product>(contentTypeAlias);

            Assert.NotNull(pagedContent);
            Assert.NotNull(pagedContent.Content);
            Assert.NotEmpty(pagedContent.Content.Items);
            Assert.Equal(1, pagedContent.TotalPages);
            Assert.Equal(8, pagedContent.TotalItems);
            foreach (var contentItem in pagedContent.Content.Items)
            {
                Assert.NotNull(contentItem);
                Assert.False(string.IsNullOrEmpty(contentItem.ProductName));
            }
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Index()
        {
            //get the Umbraco section from appsettings
            var umbracoConfig = this._configuration.GetSection("Umbraco");

            //get the project alias from the section config obtained above
            var projectAlias = umbracoConfig.GetValue <string>("ProjectAlias");

            //get an instance of the Content Delivery API
            var contentDeliveryService = new ContentDeliveryService(projectAlias);

            //get the content of type spiceFact
            var spiceFacts = await contentDeliveryService.Content.GetByType("spiceFact", null, page : 1, pageSize : 25);

            //pass the content obtained as the model to my View
            return(this.View(spiceFacts));
        }
Exemplo n.º 23
0
        public async Task Can_Retrieve_Filtered_Content_As_Typed_Object(string alias, string value, ContentFilterMatch match)
        {
            var service = new ContentDeliveryService(_configuration, GetMockedHttpClient($"{_contentBaseUrl}/filter", ContentDeliveryJson.Filter));
            var filters = new List <ContentFilterProperties>();

            filters.Add(new ContentFilterProperties(alias, value, match));
            var contentFilter = new ContentFilter(filters.ToArray());
            var pagedContent  = await service.Content.Filter <Product>(contentFilter);

            Assert.NotNull(pagedContent);
            Assert.NotNull(pagedContent.Content);
            Assert.NotEmpty(pagedContent.Content.Items);
            Assert.Equal(1, pagedContent.TotalPages);
            Assert.Equal(1, pagedContent.TotalItems);
            foreach (var contentItem in pagedContent.Content.Items)
            {
                Assert.NotNull(contentItem);
                Assert.False(string.IsNullOrEmpty(contentItem.ProductName));
            }
        }
Exemplo n.º 24
0
        static async Task Main(string[] args)
        {
            System.Console.Write(Bootloader.Load());
            System.Console.WriteLine(" ");
            System.Console.WriteLine("Booting Umbraco Headless console");
            System.Console.WriteLine(" ");

            //Enter Project Alias
            System.Console.WriteLine("Enter the Project Alias of your Headless Project");
            var projectAlias = System.Console.ReadLine();

            //New up service with the entered Headless Project Alias
            var service = new ContentDeliveryService(new ContentDeliveryConfiguration(projectAlias));

            //Output options to the console and record the user's choice
            await RenderOptions(service, projectAlias);

            System.Console.WriteLine(" ");
            System.Console.WriteLine("Press ENTER to exit");
            System.Console.ReadLine();
        }
        public async Task OnGet()
        {
            try
            {
                // Ugly way...
                var headlessClient = new ContentDeliveryService(new ContentDeliveryConfiguration("marcin-headless-uk-fest"));

                // Pure HttpClient way...
                var headlessHttpClient = _clientFactory.CreateClient("headless");

                var test = await headlessClient.Content.GetRoot();

                var test2 = await headlessHttpClient.GetAsync("/").ConfigureAwait(false);

                // Not yet possible...?
                //var test3 = await _contentDeliveryClient.Content.GetRoot();

                Events = await headlessClient.Content.GetByType("event");
            }
            catch (Exception _)
            {
            }
        }
 public EventsHeadlessClient(string projectAlias)
 {
     _headlessClient = new ContentDeliveryService(new ContentDeliveryConfiguration(projectAlias));
 }
Exemplo n.º 27
0
 public HeartcoreCache(ContentDeliveryService contentDelivery, IMemoryCache memoryCache)
 {
     _contentDelivery = contentDelivery ?? throw new ArgumentNullException(nameof(contentDelivery));
     _memoryCache     = memoryCache;
 }
 public HeartcoreContentService(ContentDeliveryService contentDelivery, ITypeResolver typeResolver)
 {
     _contentDelivery = contentDelivery ?? throw new ArgumentNullException(nameof(contentDelivery));
     _typeResolver    = typeResolver;
 }
 public UmbracoCache(ContentDeliveryService contentDelivery, IHttpContextAccessor httpContextAccessor)
 {
     _contentDelivery     = contentDelivery ?? throw new ArgumentNullException(nameof(contentDelivery));
     _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
 }
 public MainNavigationViewComponent(ContentDeliveryService contentDeliveryService, UmbracoCache umbracoCache)
 {
     _contentDeliveryService = contentDeliveryService ?? throw new ArgumentNullException(nameof(contentDeliveryService));
     _umbracoCache           = umbracoCache ?? throw new ArgumentNullException(nameof(umbracoCache));
 }