public void Handle(GeneralQueryResult message)
        {
            if (message.Dtos.Any())
            {
                if (Data.SkipGenerals % 1000 == 0)
                {
                    _entityIndexer.OptimizeGeneralIndex();
                    _entityIndexer.OptimizeAssignableIndex();
                    _entityIndexer.OptimizeTestCaseIndex();
                }

                Data.GeneralsRetrievedCount += message.Dtos.Length;

                foreach (var general in message.Dtos)
                {
                    _entityIndexer.AddGeneralIndex(general);
                }

                var assignables = message.Dtos.Where(g => _entityTypesProvider.IsAssignable(g.EntityTypeID)).Select(generalDto => generalDto.GeneralID.GetValueOrDefault()).ToArray();
                if (assignables.Any())
                {
                    Send(new AssignableQuery {
                        Hql = string.Format(AssignablesHql, string.Join(",", assignables)), IgnoreMessageSizeOverrunFailure = true, Params = _param
                    });
                }

                var testCases = message.Dtos.Where(g => _entityTypesProvider.IsTestCase(g.EntityTypeID)).Select(generalDto => generalDto.GeneralID.GetValueOrDefault()).ToArray();
                if (testCases.Any())
                {
                    Send(new TestCaseQuery {
                        Hql = string.Format(TestCaseHql, string.Join(",", testCases)), IgnoreMessageSizeOverrunFailure = true, Params = _param
                    });
                }

                if (Data.GeneralsRetrievedCount == message.QueryResultCount)
                {
                    Data.GeneralsRetrievedCount = 0;
                    Data.SkipGenerals          += PageSize;

                    Send(new GeneralQuery {
                        Hql = string.Format(GeneralsHql, Data.SkipGenerals, PageSize), IgnoreMessageSizeOverrunFailure = true, Params = _param
                    });
                }
            }
            else
            {
                _entityIndexer.OptimizeGeneralIndex();
                _entityIndexer.OptimizeAssignableIndex();
                _entityIndexer.OptimizeTestCaseIndex();
                Data.CommentsRetrievedCount = 0;
                Data.GeneralsRetrievedCount = 0;
                Data.SkipGenerals           = 0;
                Send(new CommentQuery {
                    Hql = string.Format(CommentsHql, Data.SkipComments, PageSize), IgnoreMessageSizeOverrunFailure = true, Params = _param
                });
            }
        }
 private void AddGeneralIndex(GeneralDTO generalDto)
 {
     RebuildOrAction(() => _entityIndexer.AddGeneralIndex(generalDto, DocumentIndexOptimizeSetup.DeferredOptimize));
 }
 private void AddGeneralIndex(GeneralDTO generalDto)
 {
     _entityIndexer.AddGeneralIndex(generalDto);
     _entityIndexer.OptimizeGeneralIndex();
 }