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()
|
||||
{
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Pinging API at {_client.BuildUri(new RestRequest("/ping"))}...");
|
||||
try
|
||||
{
|
||||
var res = await _client.ExecuteHeadAsync(new RestRequest("/ping"));
|
||||
if (res.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Ping response 404 Not Found, Server Online!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Network Error: {ex.Message}, API not alive.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine("Responded with something other then 404, API not what we expected.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +114,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
|||
if (_entries.Any(x => x.EqualId(item.Id())))
|
||||
_entries.RemoveAll(x => x.EqualId(item.Id()));
|
||||
_entries.Add(item);
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Posting {item.Id()}");
|
||||
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;
|
||||
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Updated Entry for {_dbName} - {entry.Id()}");
|
||||
_entries.RemoveAll(x => x.EqualId(entry.Id()));
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"New Entry for {_dbName} - {entry.Id()}");
|
||||
}
|
||||
|
||||
_entries.Add(entry);
|
||||
_isDirty = true;
|
||||
}
|
||||
|
|
@ -174,6 +190,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
|||
if (!_isDirty)
|
||||
return;
|
||||
_syncing = true;
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Syncing {_dbPath}...");
|
||||
var json = new List<string>();
|
||||
foreach (var entry in _entries)
|
||||
|
|
@ -187,6 +204,7 @@ public class Syncer<T> : ISyncer where T : class, IDataModel, new()
|
|||
fh.Close();
|
||||
}
|
||||
_watcher.Locked = false;
|
||||
// TODO: Replace with Logger
|
||||
Console.WriteLine($"Updated {_dbPath}.");
|
||||
_isDirty = false;
|
||||
_syncing = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue