private void LoadDatabaseFromSnapshot()
        {
            // I lied, we won't load anything
            _currentVersion = 0;
            _tradingRepository.OrderBook().DeleteMany(
                Builders <OrderBookEntry> .Filter.Where(e => true)
                );
            _tradingRepository.HiddenOrders().DeleteMany(
                Builders <HiddenOrderEntry> .Filter.Where(e => true)
                );
            _tradingRepository.TransactionHistory().DeleteMany(
                Builders <TransactionHistoryEntry> .Filter.Where(e => true)
                );
            _tradingRepository.OrderHistory().DeleteMany(
                Builders <OrderHistoryEntry> .Filter.Where(e => true)
                );
            _accountRepository.Accounts().DeleteMany(
                new BsonDocumentFilterDefinition <AccountEntry>(new BsonDocument())
                );

            // This enables the version control semaphore
            _versionControl.Initialize(_currentVersion);
        }
示例#2
0
 static void GUITest_Init()
 {
     UVCProcessPopup.Init(VersionControl.Initialize(CommandLine.EmptyHandler), false, true, null, false);
 }
示例#3
0
 static void CoreTest_Init()
 {
     VersionControl.Initialize(OnProcessExit);
 }
 /// <summary>
 /// Raises the Init Button event.
 /// </summary>
 /// TODO: Implement button
 public static void OnButton_Init(UVCBrowser browser)
 {
     browser.DisableGUI();
     UVCProcessPopup.Init(VersionControl.Initialize(CommandLine.EmptyHandler), true, true, browser.OnProcessStop, true);
 }
示例#5
0
        /// <inheritdoc />
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                var beforeIntegration = true;
                // This enables the version control semaphore
                _versionControl.Initialize(_currentVersion);
                _logger.LogInformation(
                    $"Initialized {GetType().Name}, listening for wallet event entries to be processed");
                while (!_stopped)
                {
                    // We can batch events by using a second parameter, just make sure to consume the entire version
                    var missingEvents = await _eventHistoryService.LoadMissingEvents(_currentVersion);

                    if (missingEvents.Count > 0)
                    {
                        // Only integrate new events as long as no one is currently assuming a fixed current version
                        _versionControl.IncreaseVersion(() =>
                        {
                            foreach (var missingEvent in missingEvents)
                            {
                                if (missingEvent is WalletEventEntry walletEvent)
                                {
                                    AbstractProvider.ProviderLookup[walletEvent.CoinSymbol].ProcessEvent(walletEvent);
                                    _logger.LogDebug(
                                        $"Processed {walletEvent.CoinSymbol} event {walletEvent.GetType().Name}");
                                }

                                var eventVersionNumber = missingEvent.VersionNumber;
                                if (eventVersionNumber == _currentVersion)
                                {
                                    continue;
                                }

                                if (eventVersionNumber == _currentVersion + 1)
                                {
                                    _currentVersion++;
                                    continue;
                                }

                                throw new Exception(
                                    $"Integrity error: the event ID {missingEvent.Id} attempted to jump version from {_currentVersion} to {eventVersionNumber}. This cannot be recovered from and requires a manual fix by administrator");
                            }

                            if (beforeIntegration)
                            {
                                beforeIntegration = false;
                                _walletOperationService.HideWalletsAfterVersionNumber(_currentVersion);
                            }

                            _logger.LogInformation($"Current version is increased to {_currentVersion}");

                            return(_currentVersion);
                        });
                        _listeningInterval = 50;
                    }
                    else
                    {
                        if (beforeIntegration)
                        {
                            _versionControl.ExecuteUsingFixedVersion(_currentVersion =>
                            {
                                beforeIntegration = false;
                                _walletOperationService.HideWalletsAfterVersionNumber(_currentVersion);
                            });
                        }

                        if (_listeningInterval < _listeningIntervalMax)
                        {
                            _listeningInterval += 50;
                        }

                        await Task.Delay(TimeSpan.FromMilliseconds(_listeningInterval), stoppingToken);

                        _logger.LogDebug($"{GetType().Name} is still listening for event entries...");
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"{e.Message}\n{e.StackTrace}");
                Program.Shutdown();
                throw;
            }
        }