Пример #1
0
        public MainWindowViewModel(IKernel kernel, WalletMonitor walletMonitor = null)
        {
            this.kernel        = kernel;
            coreDaemon         = kernel.Get <CoreDaemon>();
            coreStorage        = coreDaemon.CoreStorage;
            localClient        = kernel.Get <LocalClient>();
            this.walletMonitor = walletMonitor;

            startTime              = DateTimeOffset.Now;
            runningTimeTimer       = new DispatcherTimer();
            runningTimeTimer.Tick += (sender, e) =>
            {
                var runningTime = (DateTimeOffset.Now - startTime);
                RunningTime = $"{Math.Floor(runningTime.TotalHours):#,#00}:{runningTime:mm':'ss}";
            };
            runningTimeTimer.Interval = TimeSpan.FromMilliseconds(100);
            runningTimeTimer.Start();

            WinningBlockchainHeight = -1;
            CurrentBlockchainHeight = -1;
            DownloadedBlockCount    = -1;
            WalletHeight            = -1;

            updateWorker = new WorkerMethod("",
                                            _ =>
            {
                WinningBlockchainHeight = coreDaemon.TargetChainHeight;
                CurrentBlockchainHeight = coreDaemon.CurrentChain.Height;
                DownloadedBlockCount    = coreStorage.BlockWithTxesCount;

                BlockRate       = coreDaemon.GetBlockRate();
                TransactionRate = coreDaemon.GetTxRate();
                InputRate       = coreDaemon.GetInputRate();

                BlockDownloadRate           = localClient.GetBlockDownloadRate();
                DuplicateBlockDownloadCount = localClient.GetDuplicateBlockDownloadCount();
                BlockMissCount = localClient.GetBlockMissCount();

                if (walletMonitor != null)
                {
                    WalletHeight       = this.walletMonitor.WalletHeight;
                    WalletEntriesCount = this.walletMonitor.EntriesCount;
                    BitBalance         = this.walletMonitor.BitBalance;
                    BtcBalance         = this.walletMonitor.BtcBalance;
                }

                return(Task.CompletedTask);
            },
                                            initialNotify: true, minIdleTime: TimeSpan.FromSeconds(1), maxIdleTime: TimeSpan.FromSeconds(1));
            updateWorker.Start();
        }