Skip to content

Commit bcecae5

Browse files
authored
Missing refresh village tickbox (#171)
1 parent 2ba5cad commit bcecae5

File tree

15 files changed

+92
-41
lines changed

15 files changed

+92
-41
lines changed

MainCore/Tasks/Attack/StartFarmList.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using MainCore.Services;
2-
using MainCore.Tasks.Update;
32
using Microsoft.EntityFrameworkCore;
43
using OpenQA.Selenium;
54
using System;
65
using System.Linq;
6+
using MainCore.Tasks.Update;
77

88
#if TRAVIAN_OFFICIAL || TRAVIAN_OFFICIAL_HEROUI
99

@@ -21,7 +21,7 @@
2121

2222
namespace MainCore.Tasks.Attack
2323
{
24-
public class StartFarmList : UpdateFarmList
24+
public class StartFarmList : AccountBotTask
2525
{
2626
public StartFarmList(int accountId, int farmId) : base(accountId, "Start farmlist")
2727
{
@@ -58,7 +58,10 @@ public override void SetService(IDbContextFactory<AppDbContext> contextFactory,
5858

5959
public override void Execute()
6060
{
61-
base.Execute();
61+
if (!IsUpdateFail())
62+
{
63+
return;
64+
}
6265

6366
if (!IsFarmExist())
6467
{
@@ -84,6 +87,14 @@ public override void Execute()
8487
}
8588
}
8689

90+
private bool IsUpdateFail()
91+
{
92+
var updateTask = new UpdateFarmList(AccountId);
93+
updateTask.CopyFrom(this);
94+
updateTask.Execute();
95+
return updateTask.IsFail;
96+
}
97+
8798
private bool IsFarmExist()
8899
{
89100
using var context = _contextFactory.CreateDbContext();

MainCore/Tasks/BotTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class BotTask
1212
public DateTime ExecuteAt { get; set; }
1313
public int RetryCounter { get; set; }
1414
protected bool StopFlag { get; set; }
15-
public bool IsFail { get; set; }
15+
public bool IsFail { get; protected set; }
1616
public CancellationTokenSource Cts { get; set; }
1717

1818
protected IDbContextFactory<AppDbContext> _contextFactory;

MainCore/Tasks/Misc/LoginTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void AddTask()
165165
var update = updateList.FirstOrDefault(x => x.VillageId == village.Id);
166166
if (update is null)
167167
{
168-
_taskManager.Add(AccountId, new UpdateDorf1(village.Id, AccountId));
168+
_taskManager.Add(AccountId, new RefreshVillage(village.Id, AccountId));
169169
}
170170
}
171171
}

MainCore/Tasks/Misc/RefreshVillage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public override void Execute()
2424
}
2525
taskUpdate.CopyFrom(this);
2626
taskUpdate.Execute();
27+
if (taskUpdate.IsFail) return;
2728

2829
NextExecute();
2930
}

MainCore/Tasks/Update/UpdateAdventures.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public UpdateAdventures(int accountId) : base(accountId, "Update hero's adventur
1313

1414
public override void Execute()
1515
{
16+
IsFail = true;
1617
using var context = _contextFactory.CreateDbContext();
1718

1819
NavigateHelper.ToAdventure(_chromeBrowser);
@@ -42,6 +43,7 @@ public override void Execute()
4243
NextExecute();
4344
}
4445
}
46+
IsFail = false;
4547
}
4648

4749
private void NextExecute()

MainCore/Tasks/Update/UpdateBothDorf.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,43 @@
33

44
namespace MainCore.Tasks.Update
55
{
6-
public class UpdateBothDorf : UpdateVillage
6+
public class UpdateBothDorf : VillageBotTask
77
{
88
public UpdateBothDorf(int villageId, int accountId) : base(villageId, accountId, "Update All page")
99
{
1010
}
1111

1212
public override void Execute()
1313
{
14+
IsFail = true;
1415
var url = _chromeBrowser.GetCurrentUrl();
1516
if (url.Contains("dorf2"))
1617
{
1718
{
1819
using var context = _contextFactory.CreateDbContext();
1920
NavigateHelper.ToDorf2(_chromeBrowser, context, AccountId);
2021
}
21-
base.Execute();
22+
if (IsUpdateFail()) return;
2223

2324
{
2425
using var context = _contextFactory.CreateDbContext();
2526
NavigateHelper.ToDorf1(_chromeBrowser, context, AccountId);
2627
}
27-
base.Execute();
28+
if (IsUpdateFail()) return;
2829
}
2930
else if (url.Contains("dorf1"))
3031
{
3132
{
3233
using var context = _contextFactory.CreateDbContext();
3334
NavigateHelper.ToDorf1(_chromeBrowser, context, AccountId);
3435
}
35-
base.Execute();
36+
if (IsUpdateFail()) return;
3637

3738
{
3839
using var context = _contextFactory.CreateDbContext();
3940
NavigateHelper.ToDorf2(_chromeBrowser, context, AccountId);
4041
}
41-
base.Execute();
42+
if (IsUpdateFail()) return;
4243
}
4344
else
4445
{
@@ -49,29 +50,38 @@ public override void Execute()
4950
using var context = _contextFactory.CreateDbContext();
5051
NavigateHelper.ToDorf1(_chromeBrowser, context, AccountId);
5152
}
52-
base.Execute();
53+
if (IsUpdateFail()) return;
5354

5455
{
5556
using var context = _contextFactory.CreateDbContext();
5657
NavigateHelper.ToDorf2(_chromeBrowser, context, AccountId);
5758
}
58-
base.Execute();
59+
if (IsUpdateFail()) return;
5960
}
6061
else
6162
{
6263
{
6364
using var context = _contextFactory.CreateDbContext();
6465
NavigateHelper.ToDorf2(_chromeBrowser, context, AccountId);
6566
}
66-
base.Execute();
67+
if (IsUpdateFail()) return;
6768

6869
{
6970
using var context = _contextFactory.CreateDbContext();
7071
NavigateHelper.ToDorf1(_chromeBrowser, context, AccountId);
7172
}
72-
base.Execute();
73+
if (IsUpdateFail()) return;
7374
}
7475
}
76+
IsFail = false;
77+
}
78+
79+
private bool IsUpdateFail()
80+
{
81+
var taskUpdate = new UpdateVillage(VillageId, AccountId);
82+
taskUpdate.CopyFrom(this);
83+
taskUpdate.Execute();
84+
return taskUpdate.IsFail;
7585
}
7686
}
7787
}

MainCore/Tasks/Update/UpdateDorf1.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@
22

33
namespace MainCore.Tasks.Update
44
{
5-
public class UpdateDorf1 : UpdateVillage
5+
public class UpdateDorf1 : VillageBotTask
66
{
77
public UpdateDorf1(int villageId, int accountId) : base(villageId, accountId, "Update Resources page")
88
{
99
}
1010

1111
public override void Execute()
1212
{
13+
IsFail = true;
1314
ToDorf1();
14-
base.Execute();
15+
if (IsUpdateFail()) return;
16+
IsFail = false;
1517
}
1618

1719
private void ToDorf1()
1820
{
1921
using var context = _contextFactory.CreateDbContext();
2022
NavigateHelper.ToDorf1(_chromeBrowser, context, AccountId);
2123
}
24+
25+
private bool IsUpdateFail()
26+
{
27+
var taskUpdate = new UpdateVillage(VillageId, AccountId);
28+
taskUpdate.CopyFrom(this);
29+
taskUpdate.Execute();
30+
return taskUpdate.IsFail;
31+
}
2232
}
2333
}

MainCore/Tasks/Update/UpdateDorf2.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@
22

33
namespace MainCore.Tasks.Update
44
{
5-
public class UpdateDorf2 : UpdateVillage
5+
public class UpdateDorf2 : VillageBotTask
66
{
77
public UpdateDorf2(int villageId, int accountId) : base(villageId, accountId, "Update Buildings page")
88
{
99
}
1010

1111
public override void Execute()
1212
{
13-
{
14-
using var context = _contextFactory.CreateDbContext();
15-
NavigateHelper.ToDorf2(_chromeBrowser, context, AccountId);
16-
}
17-
base.Execute();
13+
IsFail = true;
14+
ToDorf2();
15+
if (IsUpdateFail()) return;
16+
IsFail = false;
17+
}
18+
19+
private void ToDorf2()
20+
{
21+
using var context = _contextFactory.CreateDbContext();
22+
NavigateHelper.ToDorf2(_chromeBrowser, context, AccountId);
23+
}
24+
25+
private bool IsUpdateFail()
26+
{
27+
var taskUpdate = new UpdateVillage(VillageId, AccountId);
28+
taskUpdate.CopyFrom(this);
29+
taskUpdate.Execute();
30+
return taskUpdate.IsFail;
1831
}
1932
}
2033
}

MainCore/Tasks/Update/UpdateFarmList.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,27 @@ public UpdateFarmList(int accountId) : base(accountId, "Update farmlist")
1010
{
1111
}
1212

13-
public UpdateFarmList(int accountId, string name) : base(accountId, name)
14-
{
15-
}
16-
1713
public override void Execute()
1814
{
15+
IsFail = true;
1916
var village = GetVillageHasRallyPoint();
20-
if (Cts.IsCancellationRequested) return;
17+
if (IsStop()) return;
2118
if (village == -1)
2219
{
2320
_logManager.Warning(AccountId, "There is no rallypoint in your villages");
2421
return;
2522
}
2623
{
2724
var result = GotoFarmListPage(village);
28-
if (Cts.IsCancellationRequested) return;
25+
if (IsStop()) return;
2926
if (!result) return;
3027
}
3128
{
3229
using var context = _contextFactory.CreateDbContext();
3330
UpdateHelper.UpdateFarmList(context, _chromeBrowser, AccountId);
3431
_eventManager.OnFarmListUpdated(AccountId);
3532
}
33+
IsFail = false;
3634
}
3735

3836
private int GetVillageHasRallyPoint()
@@ -72,6 +70,7 @@ private bool GotoFarmListPage(int village)
7270
var taskUpdate = new UpdateDorf2(village, AccountId);
7371
taskUpdate.CopyFrom(this);
7472
taskUpdate.Execute();
73+
if (taskUpdate.IsFail) return false;
7574

7675
if (Cts.IsCancellationRequested) return false;
7776

MainCore/Tasks/Update/UpdateHeroItems.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ public UpdateHeroItems(int accountId) : base(accountId, "Update hero's items")
1010

1111
public override void Execute()
1212
{
13+
IsFail = true;
1314
NavigateHelper.ToHeroInventory(_chromeBrowser);
1415
using var context = _contextFactory.CreateDbContext();
1516
UpdateHelper.UpdateHeroInventory(context, _chromeBrowser, AccountId);
17+
IsFail = false;
1618
}
1719
}
1820
}

0 commit comments

Comments
 (0)