예제 #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var args = ProcessArguments.ParseArguments(e.Args);

            var activeNetwork = args.IntendedNetwork;

            WalletClient.Initialize();

            var appDataDir = Portability.LocalAppData(Environment.OSVersion.Platform,
                                                      AssemblyResources.Organization, AssemblyResources.ProductName);

            Directory.CreateDirectory(appDataDir);

            var startupTask = Task.Run(async() =>
            {
                // Begin the asynchronous reading of the certificate before starting the wallet
                // process.  This uses filesystem events to know when to begin reading the certificate,
                // and if there is too much delay between wallet writing the cert and this process
                // beginning to observe the change, the event may never fire and the cert won't be read.
                var rootCertificateTask = TransportSecurity.ReadModifiedCertificateAsync(appDataDir);

                var walletProcess = WalletProcess.Start(activeNetwork, appDataDir);

                WalletClient walletClient;
                try
                {
                    var listenAddress   = WalletProcess.RpcListenAddress("localhost", activeNetwork);
                    var rootCertificate = await rootCertificateTask;
                    walletClient        = await WalletClient.ConnectAsync(listenAddress, rootCertificate);
                }
                catch (Exception)
                {
                    if (walletProcess.HasExited)
                    {
                        throw new Exception("Wallet process closed unexpectedly");
                    }
                    walletProcess.KillIfExecuting();
                    throw;
                }

                return(Tuple.Create(walletProcess, walletClient));
            });

            startupTask.Wait();
            var startupResult = startupTask.Result;

            ActiveNetwork             = activeNetwork;
            WalletRpcProcess          = startupResult.Item1;
            WalletRpcClient           = startupResult.Item2;
            Application.Current.Exit += Application_Exit;
        }
예제 #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // WPF defaults to using the en-US culture for all formatted bindings.
            // Override this with the system's current culture.
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
                                                               new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            var args = ProcessArguments.ParseArguments(e.Args);

            var activeNetwork = args.IntendedNetwork;

            WalletClient.Initialize();

            Directory.CreateDirectory(AppDataDir);

            // try to obtain some default rpc settings to autofill the startup dialogs with.
            // try paymetheus defaults first, and if that fails, look for a dcrd config.
            try
            {
                var     iniParser    = new FileIniDataParser();
                IniData config       = null;
                string  defaultsFile = Path.Combine(AppDataDir, "defaults.ini");
                if (File.Exists(defaultsFile))
                {
                    config = iniParser.ReadFile(defaultsFile);
                }
                else
                {
                    var consensusRpcAppData = Portability.LocalAppData(Environment.OSVersion.Platform,
                                                                       "", ConsensusServerRpcOptions.ApplicationName);
                    var consensusRpcConfig      = ConsensusServerRpcOptions.ApplicationName + ".conf";
                    var consensusConfigFilePath = Path.Combine(consensusRpcAppData, consensusRpcConfig);
                    if (File.Exists(consensusConfigFilePath))
                    {
                        config = iniParser.ReadFile(consensusConfigFilePath);
                    }
                }

                if (config != null)
                {
                    // Settings can be found in either the Application Options or global sections.
                    var section = config["Application Options"];
                    if (section == null)
                    {
                        section = config.Global;
                    }

                    var rpcUser   = section["rpcuser"] ?? "";
                    var rpcPass   = section["rpcpass"] ?? "";
                    var rpcListen = section["rpclisten"] ?? "";
                    var rpcCert   = section["rpccert"] ?? "";

                    // rpclisten and rpccert can be filled with sensible defaults when empty.  user and password can not.
                    if (rpcListen == "")
                    {
                        rpcListen = "127.0.0.1";
                    }
                    if (rpcCert == "")
                    {
                        var localCertPath = ConsensusServerRpcOptions.LocalCertificateFilePath();
                        if (File.Exists(localCertPath))
                        {
                            rpcCert = localCertPath;
                        }
                    }

                    DefaultCSRPO = new ConsensusServerRpcOptions(rpcListen, rpcUser, rpcPass, rpcCert);
                }
            }
            catch { } // Ignore any errors, this will just result in leaving defaults empty.

            var syncTask = Task.Run(async() =>
            {
                return(await SynchronizerViewModel.Startup(activeNetwork, AppDataDir, args.SearchPathForWalletProcess,
                                                           args.ExtraWalletArgs));
            });
            var synchronizer = syncTask.Result;

            SingletonViewModelLocator.RegisterInstance("Synchronizer", synchronizer);
            ActiveNetwork = activeNetwork;
            Synchronizer  = synchronizer;
            Current.Exit += Application_Exit;
        }