Skip to content

Commit

Permalink
* rename abstract class BaseCrawlFacade, BasePostSaver & `BasePos…
Browse files Browse the repository at this point in the history
…tParser` to remove `Base-` prefix @ c#/crawler
  • Loading branch information
n0099 committed May 10, 2024
1 parent f8d6e6f commit 584499b
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions c#/crawler/src/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected override void ConfigureContainer(HostBuilderContext context, Container
{
builder.RegisterImplementsOfBaseTypes(typeof(EntryPoint).Assembly,
[
typeof(BaseCrawler<,>), typeof(BaseCrawlFacade<,,,>),
typeof(BasePostParser<,>), typeof(BaseSaver<>)
typeof(BaseCrawler<,>), typeof(CrawlFacade<,,,>),
typeof(PostParser<,>), typeof(BaseSaver<>)
]);
builder.RegisterType<CrawlerDbContext>();
builder.RegisterType<ClientRequester>();
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Crawler/ThreadLateCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class ThreadLateCrawler(
}
}
catch (Exception e)
{ // below is similar with BaseCrawlFacade.SilenceException()
{ // below is similar with CrawlFacade.SilenceException()
e.Data["fid"] = fid;
e.Data["tid"] = tid;
e = e.ExtractInnerExceptionsData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace tbm.Crawler.Tieba.Crawl.Facade;

#pragma warning disable S3881 // "IDisposable" should be implemented correctly
public abstract class BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>(
public abstract class CrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>(
#pragma warning restore S3881 // "IDisposable" should be implemented correctly
BaseCrawler<TResponse, TPostProtoBuf> crawler,
Fid fid,
CrawlerLocks.LockId lockId,
CrawlerLocks locks,
BasePostParser<TPost, TPostProtoBuf> postParser,
Func<ConcurrentDictionary<PostId, TPost>, BasePostSaver<TPost, TBaseRevision>> postSaverFactory,
PostParser<TPost, TPostProtoBuf> postParser,
Func<ConcurrentDictionary<PostId, TPost>, PostSaver<TPost, TBaseRevision>> postSaverFactory,
Func<ConcurrentDictionary<Uid, User>, UserParser> userParserFactory,
Func<ConcurrentDictionary<Uid, User>, UserSaver> userSaverFactory)
: IDisposable
Expand All @@ -25,7 +25,7 @@ public abstract class BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProt
public delegate void ExceptionHandler(Exception ex);

// ReSharper disable UnusedAutoPropertyAccessor.Global
public required ILogger<BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>>
public required ILogger<CrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>>
Logger { private get; init; }
public required CrawlerDbContext.New DbContextFactory { private get; init; }
public required ClientRequesterTcs RequesterTcs { private get; init; }
Expand Down Expand Up @@ -77,11 +77,11 @@ public virtual void Dispose()
}
}

public async Task<BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>>
public async Task<CrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>>
CrawlPageRange(Page startPage, Page endPage = Page.MaxValue, CancellationToken stoppingToken = default)
{ // cancel when startPage is already locked
if (_lockingPages.Count != 0) ThrowHelper.ThrowInvalidOperationException(
"CrawlPageRange() can only be called once, a instance of BaseCrawlFacade shouldn't be reuse for other crawls.");
"CrawlPageRange() can only be called once, a instance of CrawlFacade shouldn't be reuse for other crawls.");
var acquiredLocks = locks.AcquireRange(lockId, [startPage]);
if (acquiredLocks.Count == 0) Logger.LogInformation(
"Cannot crawl any page within the range [{}-{}] for lock type {}, id {} since they've already been locked",
Expand Down Expand Up @@ -115,12 +115,12 @@ public virtual void Dispose()
(IReadOnlyList<Page> pages, Func<Page, FailureCount> failureCountSelector, CancellationToken stoppingToken = default)
{
if (_lockingPages.Count != 0) ThrowHelper.ThrowInvalidOperationException(
"RetryPages() can only be called once, a instance of BaseCrawlFacade shouldn't be reuse for other crawls.");
"RetryPages() can only be called once, a instance of CrawlFacade shouldn't be reuse for other crawls.");
await CrawlPages(pages, failureCountSelector, stoppingToken);
return SaveCrawled(stoppingToken);
}

public BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>
public CrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>
AddExceptionHandler(ExceptionHandler handler)
{
_exceptionHandler += handler;
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Facade/ReplyCrawlFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReplyCrawlFacade(
UserSaver.New userSaverFactory,
CrawlerDbContext.New dbContextFactory,
SonicPusher sonicPusher)
: BaseCrawlFacade<ReplyPost, BaseReplyRevision, ReplyResponse, Reply>(
: CrawlFacade<ReplyPost, BaseReplyRevision, ReplyResponse, Reply>(
crawlerFactory(fid, tid), fid, new(fid, tid), locks[CrawlerLocks.Type.Reply],
postParser, postSaverFactory.Invoke,
userParserFactory.Invoke, userSaverFactory.Invoke)
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Facade/SubReplyCrawlFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class SubReplyCrawlFacade(
UserParser.New userParserFactory,
UserSaver.New userSaverFactory,
SonicPusher sonicPusher)
: BaseCrawlFacade<SubReplyPost, BaseSubReplyRevision, SubReplyResponse, SubReply>(
: CrawlFacade<SubReplyPost, BaseSubReplyRevision, SubReplyResponse, SubReply>(
crawlerFactory(tid, pid), fid, new(fid, tid, pid), locks[CrawlerLocks.Type.SubReply],
postParser, postSaverFactory.Invoke,
userParserFactory.Invoke, userSaverFactory.Invoke)
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Facade/ThreadCrawlFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ThreadCrawlFacade(
ThreadSaver.New postSaverFactory,
UserParser.New userParserFactory,
UserSaver.New userSaverFactory)
: BaseCrawlFacade<ThreadPost, BaseThreadRevision, ThreadResponse, Thread>(
: CrawlFacade<ThreadPost, BaseThreadRevision, ThreadResponse, Thread>(
crawlerFactory(forumName), fid, new(fid), locks[CrawlerLocks.Type.Thread],
postParser, postSaverFactory.Invoke,
userParserFactory.Invoke, userSaverFactory.Invoke)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace tbm.Crawler.Tieba.Crawl.Parser.Post;

public abstract class BasePostParser<TPost, TPostProtoBuf>
public abstract class PostParser<TPost, TPostProtoBuf>
where TPost : BasePost
where TPostProtoBuf : class, IMessage<TPostProtoBuf>
{
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Parser/Post/ReplyParser.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace tbm.Crawler.Tieba.Crawl.Parser;

public partial class ReplyParser(ILogger<ReplyParser> logger)
: BasePostParser<ReplyPost, Reply>
: PostParser<ReplyPost, Reply>
{
// length with 24 char is only appeared in legacy replies
[GeneratedRegex("^(?:[0-9a-f]{40}|[0-9a-f]{24})$", RegexOptions.Compiled, matchTimeoutMilliseconds: 100)]
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Parser/Post/SubReplyParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace tbm.Crawler.Tieba.Crawl.Parser.Post;

public class SubReplyParser : BasePostParser<SubReplyPost, SubReply>
public class SubReplyParser : PostParser<SubReplyPost, SubReply>
{
protected override PostId PostIdSelector(SubReplyPost post) => post.Spid;

Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Parser/Post/ThreadParser.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace tbm.Crawler.Tieba.Crawl.Parser.Post;

public class ThreadParser : BasePostParser<ThreadPost, Thread>
public class ThreadParser : PostParser<ThreadPost, Thread>
{
protected override PostId PostIdSelector(ThreadPost post) => post.Tid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace tbm.Crawler.Tieba.Crawl.Saver.Post;

public abstract class BasePostSaver<TPost, TBaseRevision>(
ILogger<BasePostSaver<TPost, TBaseRevision>> logger,
public abstract class PostSaver<TPost, TBaseRevision>(
ILogger<PostSaver<TPost, TBaseRevision>> logger,
ConcurrentDictionary<PostId, TPost> posts,
AuthorRevisionSaver.New authorRevisionSaverFactory,
PostType currentPostType)
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Saver/Post/ReplySaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class ReplySaver(
ILogger<ReplySaver> logger,
ConcurrentDictionary<PostId, ReplyPost> posts,
AuthorRevisionSaver.New authorRevisionSaverFactory)
: BasePostSaver<ReplyPost, BaseReplyRevision>(
: PostSaver<ReplyPost, BaseReplyRevision>(
logger, posts, authorRevisionSaverFactory, PostType.Reply)
{
public delegate ReplySaver New(ConcurrentDictionary<PostId, ReplyPost> posts);
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Saver/Post/SubReplySaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class SubReplySaver(
ILogger<SubReplySaver> logger,
ConcurrentDictionary<PostId, SubReplyPost> posts,
AuthorRevisionSaver.New authorRevisionSaverFactory)
: BasePostSaver<SubReplyPost, BaseSubReplyRevision>(
: PostSaver<SubReplyPost, BaseSubReplyRevision>(
logger, posts, authorRevisionSaverFactory, PostType.SubReply)
{
public delegate SubReplySaver New(ConcurrentDictionary<PostId, SubReplyPost> posts);
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Saver/Post/ThreadSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ThreadSaver(
ILogger<ThreadSaver> logger,
ConcurrentDictionary<Tid, ThreadPost> posts,
AuthorRevisionSaver.New authorRevisionSaverFactory)
: BasePostSaver<ThreadPost, BaseThreadRevision>(
: PostSaver<ThreadPost, BaseThreadRevision>(
logger, posts, authorRevisionSaverFactory, PostType.Thread)
{
public delegate ThreadSaver New(ConcurrentDictionary<Tid, ThreadPost> posts);
Expand Down

0 comments on commit 584499b

Please sign in to comment.