private async Task ReportRemoteIdGreaterThanLocal(DbWatcherSettings cfg) { var msg = $"Remote ID [{RemoteId}] is greater than Local ID [{LocalId}]."; Log("«DATA_ANOMALY» " + msg); await _hub.ReportDataAnomaly(cfg.UniqueDbName, msg); }
private Process StartSenderProcess(out DbWatcherSettings watcherSettings) { var cfg = JsonFile.Read <ChangeSenderSettings>("ChangeSender.cfg"); watcherSettings = cfg.WatchList[0]; return(Process.Start(@"..\..\..\LiteDbSync.ChangeSender.WPF\bin\Debug\ChangeSender.exe")); }
internal void SetTarget(DbWatcherSettings fileWatcherSettings) { _cfg = fileWatcherSettings; var nme = Path.GetFileName(_cfg.DbFilePath); var typ = _cfg.CollectionName; var ims = $"every {_cfg.IntervalMS:n0} ms"; UpdateTitle($"Watching “{nme}” ‹{typ}› [{ims}]"); }
private async Task SendChangesToServer(DbWatcherSettings cfg) { var recs = _local.GetRecords(cfg.DbFilePath, cfg.CollectionName, RemoteId + 1, LocalId); Log($"Sending {recs.Count:N0} record(s) to remote database ..."); await _hub.SendRecordsToRemote(cfg.UniqueDbName, recs); }
private async Task <long> GetLastServerId(DbWatcherSettings cfg) { var newId = await _hub.GetLastRemoteId(cfg.UniqueDbName); if (newId != RemoteId) { Log($"Latest remote Id: [{newId:N0}]"); } return(newId); }
public void SendChangesIfAny(DbWatcherSettings dbCfg) { if (_isBusy) { Log("‹ChangeSender› cannot process the request to [SendChangesIfAny] while a previous request is running."); return; } _isBusy = true; Task.Run(async() => { try { await SendChangesIfAnyAsync(dbCfg); } catch (Exception ex) { Log(ex.Info(true, true)); } _isBusy = false; }); }
private async Task SendChangesIfAnyAsync(DbWatcherSettings cfg) { LocalId = _local.GetLatestId(cfg.DbFilePath, cfg.CollectionName); RemoteId = await GetLastServerId(cfg); if (RemoteId < 0) { return; } if (RemoteId == LocalId) { return; } if (RemoteId > LocalId) { await ReportRemoteIdGreaterThanLocal(cfg); return; } await SendChangesToServer(cfg); await SendChangesIfAnyAsync(cfg); }