Updated Syncer
Added More noise to logging, so things can be seen happening.
This commit is contained in:
parent
6fb47905c0
commit
433797caae
1 changed files with 18 additions and 0 deletions
|
|
@ -67,17 +67,27 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
|
|
||||||
public async Task<bool> PingApi()
|
public async Task<bool> PingApi()
|
||||||
{
|
{
|
||||||
|
// TODO: Replace with Logger
|
||||||
|
Console.WriteLine($"Pinging API at {_client.BuildUri(new RestRequest("/ping"))}...");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = await _client.ExecuteHeadAsync(new RestRequest("/ping"));
|
var res = await _client.ExecuteHeadAsync(new RestRequest("/ping"));
|
||||||
if (res.StatusCode == HttpStatusCode.NotFound)
|
if (res.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
// TODO: Replace with Logger
|
||||||
|
Console.WriteLine($"Ping response 404 Not Found, Server Online!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
// TODO: Replace with Logger
|
||||||
|
Console.WriteLine($"Network Error: {ex.Message}, API not alive.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Replace with Logger
|
||||||
|
Console.WriteLine("Responded with something other then 404, API not what we expected.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,6 +114,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
if (_entries.Any(x => x.EqualId(item.Id())))
|
if (_entries.Any(x => x.EqualId(item.Id())))
|
||||||
_entries.RemoveAll(x => x.EqualId(item.Id()));
|
_entries.RemoveAll(x => x.EqualId(item.Id()));
|
||||||
_entries.Add(item);
|
_entries.Add(item);
|
||||||
|
// TODO: Replace with Logger
|
||||||
Console.WriteLine($"Posting {item.Id()}");
|
Console.WriteLine($"Posting {item.Id()}");
|
||||||
await _client.PostJsonAsync<T>(_restEndpoint, item);
|
await _client.PostJsonAsync<T>(_restEndpoint, item);
|
||||||
}
|
}
|
||||||
|
|
@ -122,11 +133,16 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
|
|
||||||
if (data.Equals(entry)) continue;
|
if (data.Equals(entry)) continue;
|
||||||
|
|
||||||
|
// TODO: Replace with Logger
|
||||||
Console.WriteLine($"Updated Entry for {_dbName} - {entry.Id()}");
|
Console.WriteLine($"Updated Entry for {_dbName} - {entry.Id()}");
|
||||||
_entries.RemoveAll(x => x.EqualId(entry.Id()));
|
_entries.RemoveAll(x => x.EqualId(entry.Id()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// TODO: Replace with Logger
|
||||||
Console.WriteLine($"New Entry for {_dbName} - {entry.Id()}");
|
Console.WriteLine($"New Entry for {_dbName} - {entry.Id()}");
|
||||||
|
}
|
||||||
|
|
||||||
_entries.Add(entry);
|
_entries.Add(entry);
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
}
|
}
|
||||||
|
|
@ -174,6 +190,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
if (!_isDirty)
|
if (!_isDirty)
|
||||||
return;
|
return;
|
||||||
_syncing = true;
|
_syncing = true;
|
||||||
|
// TODO: Replace with Logger
|
||||||
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)
|
||||||
|
|
@ -187,6 +204,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
||||||
fh.Close();
|
fh.Close();
|
||||||
}
|
}
|
||||||
_watcher.Locked = false;
|
_watcher.Locked = false;
|
||||||
|
// TODO: Replace with Logger
|
||||||
Console.WriteLine($"Updated {_dbPath}.");
|
Console.WriteLine($"Updated {_dbPath}.");
|
||||||
_isDirty = false;
|
_isDirty = false;
|
||||||
_syncing = false;
|
_syncing = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue