Beispiel #1
0
        public static void ZengentiSearchFunction(string apiName, string friendlyName, string url, Boolean usingSlug)
        {
            ApiName      = apiName;
            FriendlyName = friendlyName;
            Url          = url;
            UsingSlug    = usingSlug;



            Console.WriteLine("Starting Content Type type: " + ApiName);
            var query = new Query
                        (
                Op.EqualTo("sys.contentTypeId", ApiName)
                        );

            //Override the default query page size from 25 to whatever you need
            query.PageSize = 5000;

            //Initiate your connection, see https://developer.zengenti.com/contensis/api/delivery/dotnet/key-concepts/api-instantiation.html
            var client = ContensisClient.Create("");

            var results = client.Entries.Search(query);

            string fileName = friendlyName + "Sitemap.xml";

            using (XmlWriter writer = XmlWriter.Create(fileName))

            {
                writer.WriteStartDocument();
                writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");

                foreach (var result in results.Items)
                {
                    string location = "";
                    if (usingSlug == true)
                    {
                        location = "https://www.kcl.ac.uk" + url + result.Slug;
                    }
                    else
                    {
                        location = "https://www.kcl.ac.uk" + url + result.Id;
                    }


                    DateTime modified = (System.DateTime)result.Version.Modified;

                    writer.WriteStartElement("url");
                    writer.WriteElementString("loc", location);
                    writer.WriteElementString("priority", "0.7");
                    writer.WriteElementString("lastmod", modified.ToString("yyyy-MM-dd"));
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            Console.WriteLine("File: " + fileName + " created");
        }
Beispiel #2
0
        /// <summary>
        /// Uses Delivery API to get list of OpenTimePeriod from the CMS
        /// Does not use search because the search is cached whereas a list is up-to-date as soon as published
        /// </summary>
        /// <param name="client">Contensis Delivery API client</param>
        /// <param name="typeTaxonomyKey">Taxonomy key of the type to fetch, if null all OpenTimePeriods are returned</param>
        /// <param name="periodContentName">Name of the content type in the CMS default is openTimePeriod</param>
        /// <returns>List of OpenTimePeriods from CMS</returns>
        public static List <OpenTimePeriod> FetchOpenTimePeriods(ContensisClient client, string typeTaxonomyKey = null, string periodContentName = "openTimePeriod")
        {
            var allPeriods = FetchAllOpenTimePeriods(client, periodContentName);

            if (typeTaxonomyKey == null)
            {
                return(allPeriods);
            }
            else
            {
                return(FilterListByType(allPeriods, typeTaxonomyKey));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Use client to fetch all the OpenTimePeriod content type entries from CMS
        /// </summary>
        /// <param name="client">Contensis Delivery API client</param>
        /// <param name="contentName">Name of content type in the CMS</param>
        /// <returns>List of all OpenTimePeriods</returns>
        public static List <OpenTimePeriod> FetchAllOpenTimePeriods(ContensisClient client, string contentName)
        {
            bool morePages = true;
            int  pageSize  = 25;
            int  pageIndex = 0;

            var list = new List <OpenTimePeriod>();

            // NB client.Entries will throw a RestRequestException if contentName isn't found,
            // Would try catch but then will just show closed which is not ideal
            while (morePages)
            {
                var results = client.Entries.List <OpenTimePeriod>(contentName, new PageOptions(pageIndex, pageSize));
                foreach (var item in results.Items)
                {
                    list.Add(item);
                }
                pageIndex += pageSize;
                morePages  = list.Count < results.TotalCount;
            }

            return(list);
        }