Compare commits
2 commits
f9af985de4
...
13bb5ac0dd
| Author | SHA1 | Date | |
|---|---|---|---|
| 13bb5ac0dd | |||
| e2c356a723 |
2 changed files with 9 additions and 0 deletions
|
|
@ -95,9 +95,13 @@ class Program
|
||||||
{
|
{
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
if (lastTime - DateTime.Now <= TimeSpan.FromSeconds(30)) continue;
|
if (lastTime - DateTime.Now <= TimeSpan.FromSeconds(30)) continue;
|
||||||
|
var start = DateTime.Now;
|
||||||
|
Console.WriteLine("Checking for updates...");
|
||||||
foreach (var syncer in syncers)
|
foreach (var syncer in syncers)
|
||||||
syncer.FetchDatabase().Wait();
|
syncer.FetchDatabase().Wait();
|
||||||
lastTime = DateTime.Now;
|
lastTime = DateTime.Now;
|
||||||
|
var end = DateTime.Now - start;
|
||||||
|
Console.WriteLine($"Check completed. Total Time: {end}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
private string _restEndpoint;
|
private string _restEndpoint;
|
||||||
|
|
||||||
private bool _isDirty = false;
|
private bool _isDirty = false;
|
||||||
|
private bool _syncing = false;
|
||||||
|
|
||||||
public Syncer(DBSyncWatcher watcher, string dbPath, string dbName, string restEndpoint)
|
public Syncer(DBSyncWatcher watcher, string dbPath, string dbName, string restEndpoint)
|
||||||
{
|
{
|
||||||
|
|
@ -97,6 +98,8 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
{
|
{
|
||||||
if (dbName != _dbName)
|
if (dbName != _dbName)
|
||||||
return;
|
return;
|
||||||
|
if (_syncing)
|
||||||
|
return;
|
||||||
|
|
||||||
T? entry;
|
T? entry;
|
||||||
try
|
try
|
||||||
|
|
@ -129,6 +132,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
{
|
{
|
||||||
if (!_isDirty)
|
if (!_isDirty)
|
||||||
return;
|
return;
|
||||||
|
_syncing = true;
|
||||||
Console.WriteLine($"Syncing {_dbPath}...");
|
Console.WriteLine($"Syncing {_dbPath}...");
|
||||||
var json = new List<string>();
|
var json = new List<string>();
|
||||||
foreach (var entry in _entries)
|
foreach (var entry in _entries)
|
||||||
|
|
@ -136,5 +140,6 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
File.WriteAllLines(_dbPath, json);
|
File.WriteAllLines(_dbPath, json);
|
||||||
Console.WriteLine($"Updated {_dbPath}.");
|
Console.WriteLine($"Updated {_dbPath}.");
|
||||||
_isDirty = false;
|
_isDirty = false;
|
||||||
|
_syncing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue