Skip to content

Commit cdd36ec

Browse files
committed
Adds saveCfg feature
1 parent fe0f0e4 commit cdd36ec

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

LanPartyTool/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
2121

22-
[assembly: AssemblyVersion("0.9.8.25")]
23-
[assembly: AssemblyFileVersion("0.9.8.25")]
22+
[assembly: AssemblyVersion("0.9.9.26")]
23+
[assembly: AssemblyFileVersion("0.9.9.26")]
2424

2525
[assembly: XmlConfigurator(ConfigFile = "log4net.config")]
2626
[assembly: Guid("94403695-D3D3-4A0C-A7A8-A8B9FAAF5E9B")]

LanPartyTool/agent/Agent.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ public void NewBarcodeHandler(string barcode, int counts)
283283
{
284284
Logger.Info($"New barcode scan: barcode {barcode} - counts {counts}");
285285

286-
_status.LastBarcode = barcode;
287-
288286
SoundUtility.Play(SoundUtility.Sound.Success);
289287

290288
ParseBarcodeCommandResponse(barcode, counts);
@@ -307,15 +305,36 @@ private void SendWelcomeToServer()
307305

308306
private void ParseBarcodeCommandResponse(string barcode, int counts)
309307
{
308+
List<string> cfgLines;
309+
310310
switch (counts)
311311
{
312312
case 1:
313-
var cfgLines = ServerUtility.GetCfg(_config.ServerUrl, barcode);
313+
Logger.Info("Get new CFG");
314+
315+
cfgLines = ServerUtility.GetCfg(_config.ServerUrl, barcode);
314316
if (cfgLines == null) return;
317+
315318
ApplyNewCfg(cfgLines);
319+
320+
_status.LastBarcode = barcode;
321+
316322
break;
317323

318324
case 2:
325+
Logger.Info("Save CFG");
326+
327+
if (barcode != _status.LastBarcode)
328+
{
329+
Logger.Warn("CFG not saved for different barcode");
330+
return;
331+
}
332+
333+
cfgLines = GameUtility.DumpCfg();
334+
if (cfgLines == null) return;
335+
336+
ServerUtility.SaveCfg(_config.ServerUrl, barcode, cfgLines);
337+
319338
break;
320339

321340
default:

LanPartyTool/agent/Watchdog.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public void Start()
3939
lastPingDateTime = DateTime.Now;
4040

4141
thread.Start();
42+
43+
Logger.Info("Watchdog started");
4244
}
4345
}
4446

@@ -54,6 +56,8 @@ public void Stop()
5456

5557
thread.Join();
5658
thread = null;
59+
60+
Logger.Info("Watchdog stopped");
5761
}
5862
}
5963

LanPartyTool/log4net.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<layout type="log4net.Layout.PatternLayout">
2121
<conversionPattern value="%date{yyyyMMdd HH:mm:ss.fff} %5level [%logger{1}] %message%newline" />
2222
</layout>
23-
<threshold value="DEBUG" />
23+
<threshold value="INFO" />
2424
</appender>
2525
<appender name="file" type="log4net.Appender.RollingFileAppender">
2626
<file value="lanpartytool.log" />

LanPartyTool/utility/ServerUtility.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class ServerUtility
1515
private const string PingEndPoint = "/ping";
1616
private const string WelcomeEndPoint = "/welcome";
1717
private const string GetCfgEndPoint = "/getCfg";
18+
private const string SaveCfgEndPoint = "/saveCfg";
1819

1920
private static readonly ILog Logger = LogManager.GetLogger(typeof(ServerUtility));
2021

@@ -39,10 +40,7 @@ public static string DefaultServerUrl()
3940
public static void Welcome(string serverUrl)
4041
{
4142
var result = HttpUtility.DoPost($"{serverUrl}{WelcomeEndPoint}");
42-
if (result == null)
43-
{
44-
Logger.Error($"\"{serverUrl}\" is not valid");
45-
}
43+
if (result == null) Logger.Error($"\"{serverUrl}\" is not valid");
4644
}
4745

4846
public static List<string> GetCfg(string serverUrl, string barcode)
@@ -65,6 +63,24 @@ public static List<string> GetCfg(string serverUrl, string barcode)
6563
return cfgLines;
6664
}
6765

66+
public static bool SaveCfg(string serverUrl, string barcode, List<string> cfgLines)
67+
{
68+
var result = HttpUtility.DoPost($"{serverUrl}{SaveCfgEndPoint}", new {barcode, cfgLines});
69+
if (result == null)
70+
{
71+
Logger.Debug($"\"{serverUrl}\" is not valid");
72+
return false;
73+
}
74+
75+
if (result.Success == false)
76+
{
77+
Logger.Warn(result.Error as string);
78+
return false;
79+
}
80+
81+
return true;
82+
}
83+
6884
private static IEnumerable<string> PossibleServerUrls()
6985
{
7086
var serverUrls = new List<string>();

0 commit comments

Comments
 (0)