Exemplo n.º 1
0
        internal static async Task <ContentItemModel> PrepareTestItem(ContentManagementClient client, string typeCodename, string externalId = null)
        {
            var type = ContentTypeIdentifier.ByCodename(typeCodename);

            if (externalId != null)
            {
                // We use upsert for preparing item by external ID in order to be able to recover from situation when previous test run didn't clean up properly
                var item = new ContentItemUpsertModel()
                {
                    Name = "Hooray!",
                    Type = type,
                };

                return(await client.UpsertContentItemByExternalIdAsync(externalId, item));
            }
            else
            {
                var item = new ContentItemCreateModel()
                {
                    Name = "Hooray!",
                    Type = type,
                };

                return(await client.CreateContentItemAsync(item));
            }
        }
Exemplo n.º 2
0
        private static void ImportMovies(string folderPath, ContentManagementClient client)
        {
            foreach (var movie in DatabaseEntry.CreateFromFolder(Path.Combine(folderPath, "Movies")))
            {
                Console.WriteLine($"Importing {movie.GetText("Name")}");

                var imageExternalIds = ImportMoviePhotos(movie, folderPath, client);

                var externalId = $"Movie - {movie.ExternalId}";

                var item = new ContentItemUpsertModel
                {
                    Name             = movie.GetText("Name"),
                    Type             = ContentTypeIdentifier.ByCodename("movie"),
                    SitemapLocations = movie.GetListItems("Sitemap location").Select(x => SitemapNodeIdentifier.ByCodename(GetCodename(x)))
                };

                client.UpsertContentItemByExternalIdAsync(externalId, item);

                var itemIdentifier     = ContentItemIdentifier.ByExternalId(externalId);
                var languageIdentifier = LanguageIdentifier.DEFAULT_LANGUAGE;

                var variant = new ContentItemVariantUpsertModel
                {
                    Elements = new
                    {
                        name         = movie.GetText("Name"),
                        description  = movie.GetText("Description"),
                        synopsis     = movie.GetText("Synopsis"),
                        release_date = movie.GetDateTime("Release date"),
                        genre        = movie.GetListItems("Genres").Select(x => TaxonomyTermIdentifier.ByCodename(GetCodename(x))),
                        cast         = movie.GetListItems("Cast").Select(x => ContentItemIdentifier.ByExternalId($"Actor - {x}")),
                        imdb_rating  = movie.GetNumber("IMDB rating"),
                        rating       = new [] { MultipleChoiceOptionIdentifier.ByCodename(GetCodename(movie.GetText("Rating"))) },
                        slug         = movie.GetText("Slug"),
                        photos       = imageExternalIds.Select(imageExternalId => AssetIdentifier.ByExternalId(imageExternalId))
                    },
                };

                client.UpsertContentItemVariantAsync(new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier), variant);
            }
        }
Exemplo n.º 3
0
        private static void ImportActors(string folderPath, ContentManagementClient client)
        {
            foreach (var actor in DatabaseEntry.CreateFromFolder(Path.Combine(folderPath, "Actors")))
            {
                Console.WriteLine($"Importing {actor.GetText("Name")}");

                var imageExternalId = ImportActorPhoto(actor, folderPath, client);

                var externalId = $"Actor - {actor.ExternalId}";

                var item = new ContentItemUpsertModel
                {
                    Name = actor.GetText("Name"),
                    Type = ContentTypeIdentifier.ByCodename("actor"),
                };

                client.UpsertContentItemByExternalIdAsync(externalId, item);

                var itemIdentifier     = ContentItemIdentifier.ByExternalId(actor.ExternalId);
                var languageIdentifier = LanguageIdentifier.DEFAULT_LANGUAGE;

                var variant = new ContentItemVariantUpsertModel
                {
                    Elements = new
                    {
                        name  = actor.GetText("Name"),
                        born  = actor.GetDateTime("Born"),
                        bio   = actor.GetText("Bio"),
                        photo = new [] { AssetIdentifier.ByExternalId(imageExternalId) }
                    },
                };

                client.UpsertContentItemVariantAsync(
                    new ContentItemVariantIdentifier(itemIdentifier, languageIdentifier),
                    variant
                    );
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// Updates the given content item.
    /// </summary>
    /// <param name="client">Content management client instance.</param>
    /// <param name="identifier">Identifies which content item will be updated. </param>
    /// <param name="contentItem">Specifies data for updated content item.</param>
    /// <returns>The <see cref="ContentItemModel"/> instance that represents updated content item.</returns>
    public async static Task <ContentItemModel> UpsertContentItemAsync(this IManagementClient client, Reference identifier, ContentItemModel contentItem)
    {
        if (identifier == null)
        {
            throw new ArgumentNullException(nameof(identifier));
        }

        if (contentItem == null)
        {
            throw new ArgumentNullException(nameof(contentItem));
        }

        var contentItemUpdateModel = new ContentItemUpsertModel
        {
            Name             = contentItem.Name,
            Codename         = contentItem.Codename,
            Collection       = contentItem.Collection,
            ExternalId       = contentItem.ExternalId,
            SitemapLocations = contentItem.SitemapLocations,
            Type             = contentItem.Type
        };

        return(await client.UpsertContentItemAsync(identifier, contentItemUpdateModel));
    }
        /// <summary>
        /// Inserts or updates content item according to external identifier.
        /// </summary>
        /// <param name="externalId">The external identifier of the content item.</param>
        /// <param name="contentItem">Represents inserted or updated content item.</param>
        /// <returns>The <see cref="ContentItemModel"/> instance that represents inserted or updated content item.</returns>
        public async Task <ContentItemModel> UpsertContentItemByExternalIdAsync(string externalId, ContentItemUpsertModel contentItem)
        {
            if (string.IsNullOrEmpty(externalId))
            {
                throw new ArgumentException("The external id is not specified.", nameof(externalId));
            }

            if (contentItem == null)
            {
                throw new ArgumentNullException(nameof(contentItem));
            }

            var endpointUrl = _urlBuilder.BuildItemUrl(ContentItemIdentifier.ByExternalId(externalId));
            var response    = await _actionInvoker.InvokeMethodAsync <ContentItemUpsertModel, ContentItemModel>(endpointUrl, HttpMethod.Put, contentItem);

            return(response);
        }
Exemplo n.º 6
0
    /// <inheritdoc />
    public async Task <ContentItemModel> UpsertContentItemAsync(Reference identifier, ContentItemUpsertModel contentItem)
    {
        if (identifier == null)
        {
            throw new ArgumentNullException(nameof(identifier));
        }

        if (contentItem == null)
        {
            throw new ArgumentNullException(nameof(contentItem));
        }

        var endpointUrl = _urlBuilder.BuildItemUrl(identifier);
        var response    = await _actionInvoker.InvokeMethodAsync <ContentItemUpsertModel, ContentItemModel>(endpointUrl, HttpMethod.Put, contentItem);

        return(response);
    }