コード例 #1
0
        public Entry <dynamic> UpdateContent(Entry <dynamic> newData, string contenttypeid)
        {
            var current = _apiClient.GetEntry(newData.SystemProperties.Id).Result;

            newData.SystemProperties = current.SystemProperties;
            //newData.SystemProperties.Version++;
            var task = _apiClient.CreateOrUpdateEntry(newData, Space, contenttypeid, newData.SystemProperties.Version.Value).Result;

            PublishContent(current.SystemProperties.Id, task.SystemProperties.Version ?? 1);
            //_apiClient.CreateOrUpdateEntry(newData)
            return(task);
        }
コード例 #2
0
        public async Task <Contentful.Core.Models.Entry <dynamic> > GetItemFromMgmtAPI(string id)
        {
            // note: consider moving mgmt actions into a new repository so we can
            // avoid giving all requests the mgmt keys & to avoid XxxFromMgmtXxx style
            _logger.LogTrace($"GetItemFromMgmtAPI({id})");
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentException("Missing required parameter", nameof(id));
            }

            var managementClient = new ContentfulManagementClient(_httpClient, _options);

            Contentful.Core.Models.Entry <dynamic> mgmtEntry = null;

            try
            {
                mgmtEntry = await managementClient.GetEntry(id);
            }
            catch (Contentful.Core.Errors.ContentfulException ex)
            {
                var msg = "Error getting entry from mgmt api: " + ex;
                _logger.LogError(msg);
                throw new ContentException(msg, ex);
            }
            catch (Exception ex)
            {
                var msg = "Unable to get entry from mgmt api: " + ex;
                _logger.LogError(msg);
                throw new ProcessException(msg, ex);
            }

            return(mgmtEntry);
        }
コード例 #3
0
        /// <summary>
        /// Publishes the content items referenced by the project.
        /// </summary>
        /// <param name="slug">The slug identifying the project</param>
        /// <returns></returns>
        public async Task <List <string> > PublishProject(string slug)
        {
            _logger.LogTrace($"ContentfulContentRepository.PublishProject({slug})");

            if (string.IsNullOrWhiteSpace(slug))
            {
                throw new ArgumentException("Missing required parameter", nameof(slug));
            }

            try
            {
                var cful             = new ContentfulClient(_httpClient, _options);
                var managementClient = new ContentfulManagementClient(_httpClient, _options);

                var facetQuery = new QueryBuilder <Project>()
                                 .ContentTypeIs("project")
                                 .FieldEquals("fields.slug", slug)
                                 .Include(8);
                _logger.LogInformation($"executing CMS call with query: {facetQuery.Build()}");

                // Retrieve the entire content tree by starting at the project and pulling includes
                // an arbitrary depth of 8
                var entrySet = await cful.GetEntries(facetQuery);

                // todo: determine if our process will already have the actual project published or not.
                // var projectId = entrySet.Items.FirstOrDefault().Sys.Id;
                var includedEntryIds = entrySet.IncludedEntries.Select(x => x.SystemProperties.Id);
                // todo: publish assets, too.
                // var includedAssetIds = entrySet.IncludedAssets.Select(x => x.SystemProperties.Id);

                foreach (var entry in entrySet.IncludedEntries)
                {
                    var id = entry.SystemProperties.Id;
                    // Retrieve the item from mgmt API. Version is not included from delivery API so we get it again.
                    var mgmtEntry = await managementClient.GetEntry(id);

                    var latestVersion = mgmtEntry.SystemProperties.Version.GetValueOrDefault();
                    var result        = await managementClient.PublishEntry(id, latestVersion);
                }

                return(null);
            }
            catch (Contentful.Core.Errors.ContentfulException ex)
            {
                var msg = "Error retrieving content: " + ex;
                _logger.LogError(msg);
                throw new ContentException(msg, ex);
            }
            catch (Exception ex)
            {
                var msg = "Unable to retrieve content: " + ex;
                _logger.LogError(msg);
                throw new ProcessException(msg, ex);
            }
        }