示例#1
0
        async Task <bool> StartServerAsync()
        {
            try
            {
                WalletApiProcess = _cardanoServer.ConnectToDaedalus(_sprdSettings.WalletSettings);
            }
            catch (Exception e)
            {
                var msgBox       = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("SPRD: Daedalus not running", string.Format("{0}{1}Do you want start Daedalus automatically now? Daedalus to be running and synchronized.{2}SPRD will exit, restart again when Daedalus is ready!", e.Message, Environment.NewLine, Environment.NewLine), ButtonEnum.YesNo, Icon.Stop);
                var msgBoxResult = await msgBox.ShowDialog(_desktopMainWindow);

                if (msgBoxResult == ButtonResult.Yes)
                {
                    _cardanoServer.StartDaedalus();
                }

                _desktopMainWindow.Close();
                Environment.Exit(0);
                return(false);
                //WalletApiProcess = _cardanoServer.ConnectToDaedalus(_sprdSettings.WalletSettings);
            }

            try
            {
                var lastCommitedPoolInformations = await _sprdServer.GetPoolInformationsAsync();

                LastComittedAdaPools = new ObservableCollection <SprdPoolInfo>(lastCommitedPoolInformations);

                var allWallets = await _walletClient.GetAllWalletsAsync();

                AllWallets = new ObservableCollection <Wallet>(allWallets);

                if (!AllWallets.Any())
                {
                    throw new Exception(string.Format("No wallets found in Daedalus. You cannot use SPRD since a Wallet must be selected in order to verify your identity!{0} The logs may help or try to  restart Daedalus and SPRD!", Environment.NewLine));
                }

                ResolvePoolIds(BlockChainCache.StakePools);
                SprdSelection.Wallet = AllWallets.First();

                var allPools = await _walletClient.GetAllPoolsAsync();

                AllStakePools = new ObservableCollection <StakePool>(allPools);
                OnPropertyChanged("ShowCaching");

                ResolvePoolIds(AllStakePools);
                await WriteCache(allPools);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("The operation has timed out."))
                {
                    Logging.Logger.LogWarning("Timeout happened, try to restart servers...");
                    Dispose();
                    var started = await StartServerAsync();

                    if (started)
                    {
                        return(started);
                    }
                }
                var errorMessag = string.Format("While starting the Cardano wallet API following error occurred: {0}", e.Message);
                await ShowException(errorMessag);

                return(false);
            }

            return(true);
        }