/// <summary>
 /// Add filter by entity id and options.
 /// </summary>
 /// <param name="messageQuery">Instance <see cref="EntitySchemaQuery" /></param>
 /// <param name="entityId">Entity message id.</param>
 /// <param name="readOptions">Reading options <see cref="EsnReadMessageOptions" />.</param>
 protected virtual void AddEntityMessageFilter(EntitySchemaQuery messageQuery, Guid entityId,
                                               EsnReadMessageOptions readOptions)
 {
     messageQuery.Filters.Add(messageQuery.CreateIsNullFilter("Parent"));
     messageQuery.Filters.Add(
         messageQuery.CreateFilterWithParameters(FilterComparisonType.Equal, "EntityId", entityId));
     if (readOptions.OffsetDate != default(DateTime))
     {
         var filterComparisonType = readOptions.OrderDirection == OrderDirection.Descending
                                 ? FilterComparisonType.Less
                                 : FilterComparisonType.Greater;
         messageQuery.Filters.Add(
             messageQuery.CreateFilterWithParameters(
                 filterComparisonType,
                 GetSortedColumnName(readOptions.SortedBy),
                 readOptions.OffsetDate
                 ));
     }
     if (readOptions.Filters != null)
     {
         IEntitySchemaQueryFilterItem esqFilters
             = readOptions.Filters.BuildEsqFilter(messageQuery.RootSchema.UId, UserConnection);
         messageQuery.Filters.Add(esqFilters);
     }
 }
示例#2
0
        /// <inheritdoc />
        public IEnumerable <EsnReadMessageDTO> ReadFeedMessage(EsnReadMessageOptions readOptions)
        {
            var messages        = new List <EsnReadMessageDTO>();
            var readOptionLocal = new EsnReadMessageOptions {
                SortedBy         = readOptions.SortedBy,
                ReadMessageCount = readOptions.ReadMessageCount,
                OffsetDate       = readOptions.OffsetDate
            };
            var sortedColumnName = readOptionLocal.SortedBy.ToString();

            do
            {
                var messagesFromDb = _messageReader.ReadFeedMessage(readOptionLocal);
                foreach (var message in messagesFromDb)
                {
                    readOptionLocal.OffsetDate = message.GetTypedColumnValue <DateTime>(sortedColumnName);
                    var entityId        = message.GetTypedColumnValue <Guid>("EntityId");
                    var entitySchemaUId = message.GetTypedColumnValue <Guid>("EntitySchemaUId");

                    if (_esnSecurityEngine.CanReadEntityMessage(entitySchemaUId, entityId))
                    {
                        messages.Add(CreateEsnMessageDTO(message));
                        if (messages.Count == readOptions.ReadMessageCount)
                        {
                            break;
                        }
                    }
                }
                if (messagesFromDb.Count() != readOptions.ReadMessageCount)
                {
                    break;
                }
            } while (messages.Count < readOptions.ReadMessageCount);
            return(messages);
        }
        /// <inheritdoc />
        public IEnumerable <Entity> ReadFeedMessage(EsnReadMessageOptions readOption)
        {
            var messageQuery = GetMessageQuery(readOption);

            AddFeedFilter(messageQuery, readOption);
            return(messageQuery.GetEntityCollection(UserConnection));
        }
        /// <inheritdoc />
        public IEnumerable <Entity> ReadEntityMessage(Guid entityId, EsnReadMessageOptions readOption)
        {
            var messageQuery = GetMessageQuery(readOption);

            AddEntityMessageFilter(messageQuery, entityId, readOption);
            return(messageQuery.GetEntityCollection(UserConnection));
        }
        /// <summary>
        /// Get query for retrieving messages.
        /// </summary>
        /// <param name="readOptions">Reading options <see cref="EsnReadMessageOptions" />.</param>
        /// <returns>Instance <see cref="EntitySchemaQuery" />.</returns>
        protected virtual EntitySchemaQuery GetMessageQuery(EsnReadMessageOptions readOptions)
        {
            var messageQuery = GetMessageQuery(readOptions.SortedBy, readOptions.OrderDirection);

            messageQuery.RowCount = readOptions.ReadMessageCount;
            return(messageQuery);
        }
示例#6
0
 /// <inheritdoc />
 public IEnumerable <EsnReadMessageDTO> ReadEntityMessage(Guid schemaUId, Guid entityId,
                                                          EsnReadMessageOptions options)
 {
     if (_esnSecurityEngine.CanReadEntityMessage(schemaUId, entityId))
     {
         return(_messageReader.ReadEntityMessage(entityId, options).Select(CreateEsnMessageDTO));
     }
     throw new SecurityException(string.Format(
                                     new LocalizableString("Terrasoft.Core",
                                                           "DBSecurityEngine.Exception.CurrentUserHasNotRightsForObject"), "SocialMessage"));
 }
示例#7
0
        public EsnMessagesServiceResponse ReadFeed(EsnReadMessageOptions readOptions)
        {
            var result = new EsnMessagesServiceResponse();

            try {
                result.EsnMessages = EsnCenter.ReadFeedMessage(readOptions);
            } catch (Exception e) {
                result = new EsnMessagesServiceResponse(e);
            }
            return(result);
        }
示例#8
0
        public EsnMessagesServiceResponse ReadEntityMessage(Guid schemaUId, Guid entityId,
                                                            EsnReadMessageOptions readOptions)
        {
            var result = new EsnMessagesServiceResponse();

            try {
                result.EsnMessages = EsnCenter.ReadEntityMessage(schemaUId, entityId, readOptions);
            } catch (Exception e) {
                result = new EsnMessagesServiceResponse(e);
            }
            return(result);
        }
        /// <summary>
        /// Add filter by user subscription feed.
        /// </summary>
        /// <param name="messageQuery">Instance <see cref="EntitySchemaQuery" /></param>
        /// <param name="readOptions">Reading options <see cref="EsnReadMessageOptions" />.</param>
        protected virtual void AddFeedFilter(EntitySchemaQuery messageQuery, EsnReadMessageOptions readOptions)
        {
            messageQuery.Filters.Add(messageQuery.CreateIsNullFilter("Parent"));
            if (readOptions.OffsetDate != default(DateTime))
            {
                messageQuery.Filters.Add(
                    messageQuery.CreateFilterWithParameters(
                        FilterComparisonType.Less,
                        GetSortedColumnName(readOptions.SortedBy),
                        readOptions.OffsetDate
                        ));
            }
            var feedFilter         = new EntitySchemaQueryFilterCollection(messageQuery);
            var subscriptionFilter = new EntitySchemaQueryFilterCollection(messageQuery);

            subscriptionFilter.LogicalOperation = LogicalOperationStrict.Or;
            var userId = UserConnection.CurrentUser.Id;

            subscriptionFilter.Add(
                messageQuery.CreateFilterWithParameters(
                    FilterComparisonType.Equal,
                    "[SocialSubscription:EntityId:EntityId].[SysUserInRole:SysRole:SysAdminUnit].SysUser",
                    userId
                    ));
            subscriptionFilter.Add(
                messageQuery.CreateFilterWithParameters(
                    FilterComparisonType.Equal,
                    "[SocialSubscription:EntityId:EntityId].SysAdminUnit",
                    userId
                    ));
            feedFilter.Add(subscriptionFilter);
            var unsubscriptionFilter = new EntitySchemaQueryFilterCollection(messageQuery);

            unsubscriptionFilter.IsNot = true;
            unsubscriptionFilter.Add(
                messageQuery.CreateFilterWithParameters(
                    FilterComparisonType.Equal,
                    "[SocialUnsubscription:EntityId:EntityId].SysAdminUnit",
                    userId
                    ));
            feedFilter.Add(unsubscriptionFilter);
            messageQuery.Filters.Add(feedFilter);
        }