Beispiel #1
0
        internal async Task <ContentItemVariantModel <UserModel> > TryGetExistingUserVariant(string userId)
        {
            if (!userItemVariants.ContainsKey(userId))
            {
                ContentItemVariantModel <UserModel> userVariant = null;
                try
                {
                    ContentItemIdentifier        userItemIdentifier = ContentItemIdentifier.ByExternalId(userId);
                    ContentItemVariantIdentifier variantIdentifier  = new ContentItemVariantIdentifier(userItemIdentifier, LanguageIdentifier.DEFAULT_LANGUAGE);
                    userVariant = await GetUserVariant(variantIdentifier);

                    logger.Debug("Downloaded existing user variant: " + userVariant.Elements.Name);
                    userItemVariants.Add(userVariant.Elements.Id, userVariant);
                }
                catch (ContentManagementException e)
                {
                    if (e.StatusCode != HttpStatusCode.NotFound)
                    {
                        throw e;
                    }

                    return(null);
                }
            }
            return(userItemVariants[userId]);
        }
Beispiel #2
0
        public void BuildItemUrl_ItemExternalId_ReturnsCorrectUrl()
        {
            var identifier  = ContentItemIdentifier.ByExternalId(ITEM_EXTERNAL_ID);
            var actualUrl   = _builder.BuildItemUrl(identifier);
            var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{EXPECTED_ITEM_EXTERNAL_ID}";

            Assert.Equal(expectedUrl, actualUrl);
        }
Beispiel #3
0
        public void BuildContentItemVariantsUrl_ItemExternalIdVariantCodename_ReturnsCorrectUrl()
        {
            var itemIdentifier    = ContentItemIdentifier.ByExternalId(ITEM_EXTERNAL_ID);
            var variantIdentifier = LanguageIdentifier.ByCodename(VARIANT_CODENAME);
            var identifier        = new ContentItemVariantIdentifier(itemIdentifier, variantIdentifier);
            var actualUrl         = _builder.BuildVariantsUrl(identifier);
            var expectedUrl       = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{EXPECTED_ITEM_EXTERNAL_ID}/variants/codename/{VARIANT_CODENAME}";

            Assert.Equal(expectedUrl, actualUrl);
        }
Beispiel #4
0
        private ConversationModel CreateConversationModel(Conversation conversation)
        {
            var    messages = CreateRichTextCompatibleConversationString(conversation);
            var    tags     = CreateTagsString(conversation);
            string intercomConversationLinkRichText = "<p><a href=\"" + IntercomFunctions.GetIntercomConversationLink(conversation) + "\">Link to intercom</a></p>";

            List <ContentItemIdentifier> assignees = new List <ContentItemIdentifier>()
            {
            };
            List <ContentItemIdentifier> author = new List <ContentItemIdentifier>()
            {
            };

            if (conversation.assignee.id != null) //unassigned conversation
            {
                assignees.Add(ContentItemIdentifier.ByExternalId(currentConversationUsers
                                                                 .Where(x => x.Id.Equals(conversation.assignee.id, StringComparison.OrdinalIgnoreCase))
                                                                 .FirstOrDefault()
                                                                 .Id));
            }

            author.Add(ContentItemIdentifier.ByExternalId(currentConversationUsers
                                                          .Where(x => x.Id.Equals(conversation.conversation_message.author.id, StringComparison.OrdinalIgnoreCase))
                                                          .FirstOrDefault()
                                                          .Id));

            ConversationModel conversationModel = new ConversationModel
            {
                IntercomLink = intercomConversationLinkRichText,
                Author       = author,
                CreatedAt    = Tools.FromUnixTimestamp(conversation.created_at),
                LastUpdated  = Tools.FromUnixTimestamp(conversation.updated_at),
                Assignee     = assignees,
                Messages     = messages,
                RatingValue  = conversation.conversation_rating.rating,
                RatingNote   = conversation.conversation_rating.remark,
                Tags         = tags,
                SearchBody   = CreateSearchBody(conversation),

                /*Participants = userItemVariants
                 *  .Where(userReferences => participants.Any(participant => participant.Id.Equals(userReferences.Key, StringComparison.OrdinalIgnoreCase)))
                 *  .Select(userReference => userReference.Value)
                 *  .ToList(),*/
                Participants = currentConversationUsers
                               .Select(x => ContentItemIdentifier.ByExternalId(x.Id))
                               .ToList(),
                MessageCount   = IntercomFunctions.GetConversationMessageCount(conversation),
                ConversationId = conversation.id
            };

            return(conversationModel);
        }
        /// <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);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        internal async Task DeleteItems(List <string> externalIds)
        {
            foreach (var itemId in externalIds)
            {
                try
                {
                    await managementClient.DeleteContentItemAsync(ContentItemIdentifier.ByExternalId(itemId));

                    //processedItems.Add(itemId, true);
                }
                catch (Exception e)
                {
                    logger.Error(e, "Deleting of item " + itemId + "failed.");
                }
                finally
                {
                    //processedItems.Add(itemId, false);
                }
            }
        }
Beispiel #8
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
                    );
            }
        }
Beispiel #9
0
 public void BuildListVariantsUrl_ItemExternalId_ReturnsCorrectUrl()
 {
     var identifier  = ContentItemIdentifier.ByExternalId(ITEM_EXTERNAL_ID);
     var actualUrl   = _builder.BuildListVariantsUrl(identifier);
     var expectedUrl = $"{ENDPOINT}/projects/{PROJECT_ID}/items/external-id/{ITEM_EXTERNAL_ID}";
 }
Beispiel #10
0
 private async Task <ContentItemModel> GetItem(string externalId)
 {
     return(await managementClient.GetContentItemAsync(ContentItemIdentifier.ByExternalId(externalId)));
 }
Beispiel #11
0
        internal async Task <ContentItemVariantModel <ConversationModel> > TryGetExistingConversationVariant(string conversationId)
        {
            ContentItemVariantModel <ConversationModel> conversationVariant = null;

            try
            {
                ContentItemVariantIdentifier variantIdentifier = new ContentItemVariantIdentifier(ContentItemIdentifier.ByExternalId(conversationId), LanguageIdentifier.DEFAULT_LANGUAGE);
                conversationVariant = await GetConversationVariant(variantIdentifier);

                logger.Debug("Downloaded existing conversation variant: " + conversationVariant.Elements.ConversationId);
            }
            catch (ContentManagementException e)
            {
                // If it's 404, conversation doesn't exist (yet)
                if (e.StatusCode != HttpStatusCode.NotFound)
                {
                    throw e;
                }
            }
            return(conversationVariant);
        }