-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFishingFormDBLogger.cs
153 lines (136 loc) · 4.77 KB
/
FishingFormDBLogger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Drawing;
using Fishing.Properties;
namespace Fishing
{
internal class FishingFormDBLogger : Logger, IFishDBStatusDisplay
{
private const int SpamThreshold = 10;
// TODO extract strings
private bool InTransaction = false;
private int uploadFish;
private int uploadingFish = 0;
private int downloadingRod = 0;
private string currentRod = string.Empty;
private int downloadFish;
private int downloadingFish = 0;
public FishingFormDBLogger(Action<string, Color> logFunc) : base(logFunc)
{
}
public bool StartDBTransaction(string message)
{
if (InTransaction)
{
return false;
}
InTransaction = true;
Info(message);
return true;
}
public void EndDBTransaction(string message)
{
Info(message);
InTransaction = false;
}
public void SetUploadFishNumber(int fish)
{
if (fish > 0)
{
Info("Uploading {0} fish.", fish);
}
uploadFish = fish;
if (uploadFish >= SpamThreshold)
{
Info("Too many fish uploading to list individually.");
}
uploadingFish = 0;
}
public void SetUploadRodAndFish(string rod, string fish)
{
if (uploadFish < SpamThreshold)
{ // Prevent spam hanging the GUI
uploadingFish++;
Info("{0}: \"{1}\" caught with {2}.", uploadingFish, fish, rod);
}
}
public void SetUploadRenameRodAndFish(string rod, string newName, string oldName)
{
if (uploadFish < SpamThreshold)
{ // Prevent spam hanging the GUI
uploadingFish++;
Info("{0}: \"{1}\" renamed to \"{2}\". ({3})", uploadingFish, oldName, newName, rod);
}
}
public void SetDownloadRodNumber(int rods)
{
if (rods > 0)
{
Info("Downloading {0} rods' data.", rods);
}
downloadingFish = 0;
}
public void SetDownloadRod(string rod)
{
downloadingRod++;
currentRod = rod;
Info("Getting information for {0} (#{1}).", rod, downloadingRod);
}
public void SetDownloadRodFish(int fish)
{
downloadingFish = 0;
downloadFish = fish;
if (fish > 0)
{
Info("Downloading {0} fish and fish data caught with {1}.", fish, currentRod);
}
if (downloadFish >= SpamThreshold)
{ // Prevent spam hanging the GUI
Info("Too many fish downloading to list individually.");
}
}
public void SetDownloadRenameRodFish(int fish)
{
downloadingFish = 0;
downloadFish = fish;
if (fish > 0)
{
Info("Downloading {0} renames (caught with {1}).", fish, currentRod);
}
if (downloadFish >= SpamThreshold)
{ // Prevent spam hanging the GUI
Info("Too many renames downloading to list individually.");
}
}
public void SetDownloadFish(string fish)
{
if (downloadFish < SpamThreshold)
{ // Prevent spam hanging the GUI
downloadingFish++;
Info("{0}: got \"{1}\".", downloadingFish, fish);
}
}
public void SetDownloadRenameFish(string newName, string oldName)
{
if (downloadFish < SpamThreshold)
{ // Prevent spam hanging the GUI
downloadingFish++;
Info("{0}: got \"{1}\" and renamed to \"{2}\".", downloadingFish, oldName, newName);
}
}
public void SetFishBaitOrZone(string fish, string baitOrZone)
{
if ((downloadFish == 0 && uploadFish < SpamThreshold) || (downloadFish != 0 && downloadFish < SpamThreshold))
{ // Prevent spam hanging the GUI
Info("Adding \"{0}\" to \"{1}\".", baitOrZone, fish);
}
}
public override void Error(string message, params object[] args)
{
Log(Resources.MessageError + string.Format(message, args), Color.Red);
}
public override void Warning(string message, params object[] args)
{
Log(Resources.MessageWarning + string.Format(message, args), Color.Yellow);
}
}
}