Esempio n. 1
0
        private void ExecuteSyncCommand()
        {
            Task.Run(() =>
            {
                if (!SyncHelper.HasConnection())
                {
                    Messenger.Default.Send <BusyMessage>(new BusyMessage {
                        IsBusy = true, Message = "No network.  Unable to sync."
                    });
                    System.Threading.Thread.Sleep(3000);
                    Messenger.Default.Send <BusyMessage>(new BusyMessage {
                        IsBusy = false, Message = ""
                    });
                    return;
                }

                Messenger.Default.Send <BusyMessage>(new BusyMessage {
                    IsBusy = true, Message = "Syncing..."
                });

                if (PBISyncHelper.IsRunning)
                {
                    PBISyncHelper.WaitForCompletion();
                }
                PBISyncHelper.RunSync();
                PBISyncHelper.WaitForCompletion();
                Messenger.Default.Send <BusyMessage>(new BusyMessage {
                    IsBusy = false, Message = ""
                });
            });
        }
Esempio n. 2
0
        public async Task DoSync()
        {
            var newSyncTime = DateTime.UtcNow;

            try
            {
                if (!SyncHelper.HasConnection())
                {
                    return;
                }

                using (var uow = new UnitOfWork())
                {
                    var documentDbSetting = uow.SettingsRepository.FindSingle(x => x.Key == BridgeSettingKeys.DOCUMENT_DB_KEY);
                    var endpointSetting   = uow.SettingsRepository.FindSingle(x => x.Key == BridgeSettingKeys.DOCUMENTDB_ENDPOINT);
                    DocumentDBContext.Initialize(endpointSetting.Value, documentDbSetting.Value);
                    if (DocumentDBContext.Initialized)
                    {
                        try
                        {
                            var lastSyncTime = DateTime.Parse(uow.SettingsRepository.GetSettingWithDefault(BridgeSettingKeys.LAST_SYNC_TIME, "01/01/2019"));
                            lastSyncTime = lastSyncTime.AddMinutes(-1);

                            await ExecuteSteps(uow, lastSyncTime);

                            uow.SettingsRepository.UpsertSetting(BridgeSettingKeys.LAST_SYNC_TIME, newSyncTime.ToString());
                            uow.SaveChanges();
                        }
                        catch (Exception exc)
                        {
                            Logging.Logger.Log(exc);
                        }
                    }
                }
            }
            catch (Exception outerExc)
            {
                Logging.Logger.Log(outerExc);
            }
        }