示例#1
0
        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);
        }
示例#2
0
        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"));
        }
示例#3
0
        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}]");
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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;
            });
        }
示例#7
0
        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);
        }