Ejemplo n.º 1
0
        public Profile GetProfileForEdit(User user)
        {
            var profile = _profileRepository.GetProfile(user.UserID);

            profile.Signature = _textParsingService.ClientHtmlToForumCode(profile.Signature);
            return(profile);
        }
Ejemplo n.º 2
0
        public void DoIndex(ISearchService searchService, ISettingsManager settingsManager, IPostService postService,
                            IConfig config, ITopicService topicService, IErrorLog errorLog)
        {
            var topic = searchService.GetNextTopicForIndexing();

            if (topic != null)
            {
                var serviceClient = new SearchServiceClient(config.SearchUrl, new SearchCredentials(config.SearchKey));
                if (!serviceClient.Indexes.Exists(IndexName))
                {
                    CreateIndex(serviceClient);
                }

                var posts       = postService.GetPosts(topic, false).ToArray();
                var parsedPosts = posts.Select(x =>
                {
                    var parsedText = _textParsingService.ClientHtmlToForumCode(x.FullText);
                    parsedText     = _textParsingService.RemoveForumCode(parsedText);
                    return(parsedText);
                }).ToArray();
                var searchTopic = new SearchTopic
                {
                    TopicID       = topic.TopicID.ToString(),
                    ForumID       = topic.ForumID,
                    Title         = topic.Title,
                    LastPostTime  = topic.LastPostTime,
                    StartedByName = topic.StartedByName,
                    Replies       = topic.ReplyCount,
                    Views         = topic.ViewCount,
                    IsClosed      = topic.IsClosed,
                    IsPinned      = topic.IsPinned,
                    UrlName       = topic.UrlName,
                    LastPostName  = topic.LastPostName,
                    Posts         = parsedPosts
                };

                var actions =
                    new IndexAction <SearchTopic>[]
                {
                    IndexAction.Upload(searchTopic)
                };
                try
                {
                    var serviceIndexClient = serviceClient.Indexes.GetClient(IndexName);
                    var batch = IndexBatch.New(actions);
                    serviceIndexClient.Documents.Index(batch);
                    searchService.MarkTopicAsIndexed(topic);
                }
                catch (Exception exc)
                {
                    errorLog.Log(exc, ErrorSeverity.Error);
                    topicService.MarkTopicForIndexing(topic.TopicID);
                }
            }
        }
Ejemplo n.º 3
0
        public void DoIndex(int topicID, string tenantID)
        {
            var topic = _topicService.Get(topicID);

            if (topic != null)
            {
                var serviceClient = new SearchServiceClient(_config.SearchUrl, new SearchCredentials(_config.SearchKey));
                if (!serviceClient.Indexes.Exists(IndexName))
                {
                    CreateIndex(serviceClient);
                }

                var posts       = _postService.GetPosts(topic, false).ToArray();
                var parsedPosts = posts.Select(x =>
                {
                    var parsedText = _textParsingService.ClientHtmlToForumCode(x.FullText);
                    parsedText     = _textParsingService.RemoveForumCode(parsedText);
                    return(parsedText);
                }).ToArray();
                var searchTopic = new SearchTopic
                {
                    TopicID       = topic.TopicID.ToString(),
                    ForumID       = topic.ForumID,
                    Title         = topic.Title,
                    LastPostTime  = topic.LastPostTime,
                    StartedByName = topic.StartedByName,
                    Replies       = topic.ReplyCount,
                    Views         = topic.ViewCount,
                    IsClosed      = topic.IsClosed,
                    IsPinned      = topic.IsPinned,
                    UrlName       = topic.UrlName,
                    LastPostName  = topic.LastPostName,
                    Posts         = parsedPosts,
                    TenantID      = tenantID
                };

                var actions =
                    new[]
                {
                    IndexAction.Upload(searchTopic)
                };
                try
                {
                    var serviceIndexClient = serviceClient.Indexes.GetClient(IndexName);
                    var batch = IndexBatch.New(actions);
                    serviceIndexClient.Documents.Index(batch);
                }
                catch (Exception exc)
                {
                    _errorLog.Log(exc, ErrorSeverity.Error);
                    _topicService.QueueTopicForIndexing(topic.TopicID);
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <Profile> GetProfileForEdit(User user)
        {
            var profile = await _profileRepository.GetProfile(user.UserID);

            if (string.IsNullOrWhiteSpace(profile.Signature))
            {
                profile.Signature = string.Empty;
            }
            else
            {
                profile.Signature = _textParsingService.ClientHtmlToForumCode(profile.Signature);
            }
            return(profile);
        }
Ejemplo n.º 5
0
        public void DoIndex(int topicID, string tenantID)
        {
            var topic = _topicService.Get(topicID).Result;

            if (topic == null)
            {
                return;
            }

            _elasticSearchClientWrapper.VerifyIndexCreate();

            var posts = _postService.GetPosts(topic, false).Result;

            if (posts.Count == 0)
            {
                throw new Exception($"TopicID {topic.TopicID} has no posts to index.");
            }
            var firstPost = _textParsingService.ClientHtmlToForumCode(posts[0].FullText);

            firstPost = _textParsingService.RemoveForumCode(firstPost);
            posts.RemoveAt(0);
            var parsedPosts = posts.Select(x =>
            {
                var parsedText = _textParsingService.ClientHtmlToForumCode(x.FullText);
                parsedText     = _textParsingService.RemoveForumCode(parsedText);
                return(parsedText);
            }).ToArray();
            var searchTopic = new SearchTopic
            {
                Id            = $"{tenantID}-{topic.TopicID}",
                TopicID       = topic.TopicID,
                ForumID       = topic.ForumID,
                Title         = topic.Title,
                LastPostTime  = topic.LastPostTime,
                StartedByName = topic.StartedByName,
                Replies       = topic.ReplyCount,
                Views         = topic.ViewCount,
                IsClosed      = topic.IsClosed,
                IsPinned      = topic.IsPinned,
                UrlName       = topic.UrlName,
                LastPostName  = topic.LastPostName,
                FirstPost     = firstPost,
                Posts         = parsedPosts,
                TenantID      = tenantID
            };

            try
            {
                var indexResult = _elasticSearchClientWrapper.IndexTopic(searchTopic);
                if (indexResult.Result != Result.Created && indexResult.Result != Result.Updated)
                {
                    _errorLog.Log(indexResult.OriginalException, ErrorSeverity.Error, $"Debug information: {indexResult.DebugInformation}");
                    // TODO: Replace this with some Polly or get real about queues/deadletter
                    _topicService.QueueTopicForIndexing(topic.TopicID);
                }
            }
            catch (Exception exc)
            {
                _errorLog.Log(exc, ErrorSeverity.Error);
                // TODO: Replace this with some Polly or get real about queues/deadletter
                _topicService.QueueTopicForIndexing(topic.TopicID);
            }
        }
        public void DoIndex(int topicID, string tenantID, bool isForRemoval)
        {
            if (isForRemoval)
            {
                RemoveIndex(topicID, tenantID);
                return;
            }

            var topic = _topicService.Get(topicID).Result;

            if (topic == null)
            {
                return;
            }

            _elasticSearchClientWrapper.VerifyIndexCreate();

            var posts = _postService.GetPosts(topic, false).Result;

            if (posts.Count == 0)
            {
                throw new Exception($"TopicID {topic.TopicID} has no posts to index.");
            }
            var firstPost = _textParsingService.ClientHtmlToForumCode(posts[0].FullText);

            firstPost = _textParsingService.RemoveForumCode(firstPost);
            posts.RemoveAt(0);
            var parsedPosts = posts.Select(x =>
            {
                var parsedText = _textParsingService.ClientHtmlToForumCode(x.FullText);
                parsedText     = _textParsingService.RemoveForumCode(parsedText);
                return(parsedText);
            }).ToArray();
            var searchTopic = new SearchTopic
            {
                Id            = $"{tenantID}-{topic.TopicID}",
                TopicID       = topic.TopicID,
                ForumID       = topic.ForumID,
                Title         = topic.Title,
                LastPostTime  = topic.LastPostTime,
                StartedByName = topic.StartedByName,
                Replies       = topic.ReplyCount,
                Views         = topic.ViewCount,
                IsClosed      = topic.IsClosed,
                IsPinned      = topic.IsPinned,
                UrlName       = topic.UrlName,
                LastPostName  = topic.LastPostName,
                FirstPost     = firstPost,
                Posts         = parsedPosts,
                TenantID      = tenantID
            };

            try
            {
                var policy = Polly.Policy.HandleResult <IndexResponse>(x => !x.IsValid)
                             .WaitAndRetry(new[]
                {
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(30)
                }, (exception, timeSpan) => {
                    _errorLog.Log(exception.Result.OriginalException, ErrorSeverity.Error, $"Retry after {timeSpan.Seconds}: {exception.Result.DebugInformation}");
                });
                policy.Execute(() =>
                {
                    var indexResult = _elasticSearchClientWrapper.IndexTopic(searchTopic);
                    return(indexResult);
                });
            }
            catch (Exception exc)
            {
                _errorLog.Log(exc, ErrorSeverity.Error);
            }
        }