示例#1
0
        protected JourneyInstance <TState> CreateJourneyInstance <TState>(
            string journeyName,
            Action <KeysBuilder> configureKeys,
            TState state,
            IReadOnlyDictionary <object, object> properties = null,
            string uniqueKey = null)
        {
            var keysBuilder = new KeysBuilder();

            configureKeys(keysBuilder);

            if (uniqueKey != null)
            {
                keysBuilder.With("ffiid", uniqueKey);
            }

            var keys = keysBuilder.Build();

            var instanceId = new JourneyInstanceId(journeyName, keys);

            var instanceStateProvider = Factory.Services.GetRequiredService <IUserInstanceStateProvider>();

            return((JourneyInstance <TState>)instanceStateProvider.CreateInstance(
                       journeyName,
                       instanceId,
                       typeof(TState),
                       state,
                       properties));
        }
示例#2
0
        public async Task DeleteAsync(string publicationId)
        {
            await Reactions.RemoveManyAsync(KeysBuilder.PublicationReactionsKey(publicationId));

            await Comments.DeleteManyAsync(publicationId);

            await publicationsApi.DeleteAsync(publicationId);
        }
示例#3
0
        public async Task <ReactionShort> RemoveAsync(string publicationId, string userId)
        {
            var result = await reactionsApi.DeleteByAuthorAsync(
                KeysBuilder.PublicationReactionsKey(publicationId),
                userId);

            return(ToReactionShort(result, null));
        }
示例#4
0
 private static PublicationComment ToDomain(Comment entity)
 {
     return(new PublicationComment(
                entity.Id,
                entity.Content,
                KeysBuilder.PublicationCommentKey(entity.Key),
                ToUser(entity.Author),
                entity.CreatedOn));
 }
示例#5
0
        public async Task <ReactionShort> AddOrUpdateAsync(string publicationId, ReactionType reactionType, string userId)
        {
            var result = await reactionsApi.UpsertAsync(
                KeysBuilder.PublicationReactionsKey(publicationId),
                reactionType.ToString(),
                userId);

            return(ToReactionShort(result, new UserReaction(reactionType)));
        }
        public async Task <(IEnumerable <PublicationComment>, long)> GetAsync(string publicationId, int skip, int take)
        {
            var response = await commentsApi
                           .SearchByKeyWithHttpInfoAsync(KeysBuilder.PublicationCommentKey(publicationId), skip, take);

            var comments   = response.Data.Select(c => ToDomain(c, publicationId)).ToList();
            var totalCount = GetTotalCountHeader(response);

            return(comments, totalCount);
        }
        /// <summary>
        /// Allows to specify multiple keys to be selected from the database. This enables you to request multiple design documents in a single request
        /// </summary>
        /// <see cref="https://docs.couchdb.org/en/stable/api/database/bulk-api.html?highlight=batch#post--db-_design_docs" />
        /// <returns></returns>
        public async Task <CouchResponse> DesignDocsAsync(string[] ids)
        {
            var request = new RestSharp.RestRequest("_design_docs", RestSharp.Method.POST);

            KeysBuilder expression = new KeysBuilder();

            ids.ToList().ForEach(a => expression.Add(a));

            request.AddParameter("application/json", expression.ToString(), RestSharp.ParameterType.RequestBody);
            return(await client.http.ExecuteAsync(request));
        }
示例#8
0
        private async Task <Dictionary <string, Dictionary <ReactionType, int> > > LoadReactionsAsync(IEnumerable <string> publicationIds)
        {
            var keys      = publicationIds.Select(KeysBuilder.PublicationReactionsKey).ToList();
            var query     = new ReactionsQuery(keys);
            var reactions = await reactionsApi.GetGroupedReactionsAsync(query);

            return(publicationIds
                   .ToDictionary(id => id, id =>
            {
                var r = reactions.ContainsKey(KeysBuilder.PublicationReactionsKey(id))
                        ? reactions[KeysBuilder.PublicationReactionsKey(id)]
                        : new Dictionary <string, int>();
                return r.Keys
                .Select(k => (Enum.Parse <ReactionType>(k), r[k]))
                .ToDictionary(o => o.Item1, o => o.Item2);
            }));
示例#9
0
        private async Task <Dictionary <string, CommentsShort> > LoadCommentsAsync(IEnumerable <string> publicationIds)
        {
            var keys  = publicationIds.Select(KeysBuilder.PublicationCommentKey).ToList();
            var query = new FeaturedQuery(keys);

            var featuredComments = await commentsApi.SearchFeaturedAsync(query);

            return(publicationIds
                   .ToDictionary(publicationId => publicationId, publicationId =>
            {
                var comment = featuredComments.GetValueOrDefault(KeysBuilder.PublicationCommentKey(publicationId));

                return new CommentsShort(
                    comment?.Comments.Select(c => ToDomain(c)) ?? Enumerable.Empty <PublicationComment>(),
                    comment?.TotalCount ?? 0);
            }));
        }
示例#10
0
        protected JourneyInstance <TState> GetJourneyInstance <TState>(
            string journeyName,
            Action <KeysBuilder> configureKeys,
            string uniqueKey = null)
        {
            var keysBuilder = new KeysBuilder();

            configureKeys(keysBuilder);

            if (uniqueKey != null)
            {
                keysBuilder.With("ffiid", uniqueKey);
            }

            var keys = keysBuilder.Build();

            var instanceId = new JourneyInstanceId(journeyName, keys);

            var instanceStateProvider = Factory.Services.GetRequiredService <IUserInstanceStateProvider>();

            return((JourneyInstance <TState>)instanceStateProvider.GetInstance(instanceId));
        }
 public async Task DeleteManyAsync(string publicationId)
 {
     await commentsApi.DeleteByKeyAsync(KeysBuilder.PublicationCommentKey(publicationId));
 }
        public async Task <PublicationComment> PublishAsync(string content, string publicationId, string userId)
        {
            var comment = await commentsApi.CreateAsync(new CreateCommentModel(KeysBuilder.PublicationCommentKey(publicationId), content, authorId : userId));

            return(ToDomain(comment, publicationId));
        }
        public async Task <PublicationComment> GetByIdAsync(string id)
        {
            var comment = await commentsApi.GetByIdAsync(id);

            return(ToDomain(comment, comment == null ? null : KeysBuilder.PublicationFromCommentKey(comment.Key)));
        }