public static async Task <SynchronizerViewModel> Startup(BlockChainIdentity activeNetwork, string walletAppDataDir) { // 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(walletAppDataDir); var walletProcess = WalletProcess.Start(activeNetwork, walletAppDataDir); 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(new SynchronizerViewModel(walletProcess, walletClient)); }
private static TransportSecurity GetTransportSecurity(TransportSecurity transportSecurity) { if (envTransportSecurity.HasValue) { return(transportSecurity); } var envValue = Environment.GetEnvironmentVariable("TRANSPORT_SECURITY"); if (string.IsNullOrWhiteSpace(envValue)) { return(transportSecurity); } if (!Enum.TryParse(envValue, true, out TransportSecurity parsedEnvTransportSecurity)) { return(transportSecurity); } envTransportSecurity = parsedEnvTransportSecurity; Console.WriteLine($"Using env variable for transport security {envTransportSecurity}"); transportSecurity = envTransportSecurity.Value; return(transportSecurity); }
public static async Task <SynchronizerViewModel> Startup(BlockChainIdentity activeNetwork, string walletAppDataDir, bool searchPath, string extraArgs) { if (activeNetwork == null) { throw new ArgumentNullException(nameof(activeNetwork)); } if (walletAppDataDir == null) { throw new ArgumentNullException(nameof(walletAppDataDir)); } if (extraArgs == null) { throw new ArgumentNullException(nameof(extraArgs)); } // 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(walletAppDataDir); string walletProcessPath = null; if (!searchPath) { walletProcessPath = Portability.ExecutableInstallationPath( Environment.OSVersion.Platform, AssemblyResources.Organization, WalletProcess.ProcessName); } KillLeftoverWalletProcess(activeNetwork); var walletProcess = WalletProcess.Start(activeNetwork, walletAppDataDir, walletProcessPath, extraArgs); 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(new SynchronizerViewModel(walletProcess, walletClient)); }
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; }
public static SecureSocketOptions SecureSocketOptionsFromTransportSecurity(TransportSecurity security) { switch (security) { case TransportSecurity.Tls: return(SecureSocketOptions.StartTls); case TransportSecurity.Ssl: return(SecureSocketOptions.SslOnConnect); case TransportSecurity.None: return(SecureSocketOptions.None); default: throw new Exception($"invalid smtp transport security parameter {security}"); } }