Exemplo n.º 1
0
        // When invoked with and unknown command it should not launch the GUI.
        public async Task InvokedWithUnknownCommandAsync()
        {
            var ms     = new MemoryStream();
            var output = new StreamWriter(ms, Encoding.ASCII, 1024, true);

            CommandInterpreter.Configure(CreateMixCommand(), CreateFindPasswordCommand(), output, output);
            // unknown command
            var runGui = await CommandInterpreter.ExecuteCommandsAsync(new[] { "unknowncommand" });

            output.Flush();
            var consoleOutput = Encoding.ASCII.GetString(ms.ToArray());

            Assert.Contains("Unknown command:", consoleOutput);
            Assert.False(runGui);

            ms     = new MemoryStream();
            output = new StreamWriter(ms, Encoding.ASCII, 1024, true);
            // Unknown option
            CommandInterpreter.Configure(CreateMixCommand(), CreateFindPasswordCommand(), output, output);
            runGui = await CommandInterpreter.ExecuteCommandsAsync(new[] { "--unknownoption" });

            output.Flush();
            consoleOutput = Encoding.ASCII.GetString(ms.ToArray());
            Assert.Contains("Unknown command:", consoleOutput);
            Assert.False(runGui);
        }
Exemplo n.º 2
0
        private static bool ProcessCliCommands(string[] args)
        {
            var daemon        = new Daemon(Global, TerminateService);
            var interpreter   = new CommandInterpreter(Console.Out, Console.Error);
            var executionTask = interpreter.ExecuteCommandsAsync(
                args,
                new MixerCommand(daemon));

            return(executionTask.GetAwaiter().GetResult());
        }
Exemplo n.º 3
0
        private static bool ShouldRunGui(string[] args)
        {
            var daemon        = new Daemon(Global);
            var interpreter   = new CommandInterpreter(Console.Out, Console.Error);
            var executionTask = interpreter.ExecuteCommandsAsync(
                args,
                new MixerCommand(daemon),
                new PasswordFinderCommand(Global.WalletManager),
                new CrashReportCommand(Global.CrashReporter));

            return(executionTask.GetAwaiter().GetResult());
        }
Exemplo n.º 4
0
        /// Warning! In Avalonia applications Main must not be async. Otherwise application may not run on OSX.
        /// see https://github.com/AvaloniaUI/Avalonia/wiki/Unresolved-platform-support-issues
        private static void Main(string[] args)
        {
            bool runGui = false;

            try
            {
                Global = new Global();

                Locator.CurrentMutable.RegisterConstant(Global);

                Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui");
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

                runGui = CommandInterpreter.ExecuteCommandsAsync(Global, args).GetAwaiter().GetResult();

                if (!runGui)
                {
                    return;
                }

                if (Global.InitializeUiConfigAsync().GetAwaiter().GetResult())
                {
                    Logger.LogInfo($"{nameof(Global.UiConfig)} is successfully initialized.");
                }
                else
                {
                    Logger.LogError($"Failed to initialize {nameof(Global.UiConfig)}.");
                    return;
                }

                Logger.LogSoftwareStarted("Wasabi GUI");

                BuildAvaloniaApp().StartShellApp("Wasabi Wallet", AppMainAsync, args);
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex);
                throw;
            }
            finally
            {
                MainWindowViewModel.Instance?.Dispose();
                Global.DisposeAsync().GetAwaiter().GetResult();
                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      -= TaskScheduler_UnobservedTaskException;

                if (runGui)
                {
                    Logger.LogSoftwareStopped("Wasabi GUI");
                }
            }
        }
Exemplo n.º 5
0
        private static bool ProcessCliCommands(string[] args)
        {
            var daemon        = new Daemon(Global !, TerminateService);
            var interpreter   = new CommandInterpreter(Console.Out, Console.Error);
            var executionTask = interpreter.ExecuteCommandsAsync(
                args,
                new MixerCommand(daemon),
                new PasswordFinderCommand(Global !.WalletManager),
                new CrashReportCommand(CrashReporter));

            return(executionTask.GetAwaiter().GetResult());
        }
Exemplo n.º 6
0
        // When invoked with "--datadir" only it should set the DataDir and launch the GUI
        public async Task InvokedWithDataDirAsync()
        {
            var ms     = new MemoryStream();
            var output = new StreamWriter(ms, Encoding.ASCII, 1024, true);

            CommandInterpreter.Configure(CreateMixCommand(), CreateFindPasswordCommand(), output, output);
            var runGui = await CommandInterpreter.ExecuteCommandsAsync(new[] { "--datadir", "expected/passed/datadir" });

            output.Flush();
            Assert.Equal("expected/passed/datadir", WalletWasabi.Gui.Global.DataDir);
            Assert.True(runGui);
        }
Exemplo n.º 7
0
        // When invoked with "--version" it should NOT in GUI mode
        public async Task InvokedWithVersionAsync()
        {
            var ms     = new MemoryStream();
            var output = new StreamWriter(ms, Encoding.ASCII, 1024, true);

            CommandInterpreter.Configure(CreateMixCommand(), CreateFindPasswordCommand(), output, output);
            var runGui = await CommandInterpreter.ExecuteCommandsAsync(new[] { "--version" });

            output.Flush();
            var consoleOutput = Encoding.ASCII.GetString(ms.ToArray());

            Assert.Contains("Wasabi Client Version:", consoleOutput);
            Assert.False(runGui);
        }
Exemplo n.º 8
0
        // When invoked with "findpassword" it should NOT launch the GUI
        public async Task InvokedWithPasswordFinderAsync()
        {
            var ms                  = new MemoryStream();
            var output              = new StreamWriter(ms, Encoding.ASCII, 1024, true);
            var invoked             = false;
            var findPasswordCommand = CreateFindPasswordCommand();

            findPasswordCommand.Run = (s) => invoked = true;
            CommandInterpreter.Configure(CreateMixCommand(), findPasswordCommand, output, output);
            var runGui = await CommandInterpreter.ExecuteCommandsAsync(new[] { "findpassword" });

            Assert.True(invoked);
            Assert.False(runGui);
        }
Exemplo n.º 9
0
#pragma warning disable IDE1006 // Naming Styles

        private static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            bool runGui = false;

            try
            {
                Global = new Global();

                Locator.CurrentMutable.RegisterConstant(Global);

                Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui");
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

                runGui = await CommandInterpreter.ExecuteCommandsAsync(Global, args);

                if (!runGui)
                {
                    return;
                }
                Logger.LogSoftwareStarted("Wasabi GUI");

                BuildAvaloniaApp().StartShellApp("Wasabi Wallet", AppMainAsync, args);
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex);
                throw;
            }
            finally
            {
                StatusBar?.Dispose();
                await Global.DisposeAsync().ConfigureAwait(false);

                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      -= TaskScheduler_UnobservedTaskException;

                if (runGui)
                {
                    Logger.LogSoftwareStopped("Wasabi GUI");
                }
            }
        }
Exemplo n.º 10
0
        // When invoked with "--datadir" only it should set the DataDir and launch the GUI
        public async Task InvokedWithMixAsync()
        {
            var ms         = new MemoryStream();
            var output     = new StreamWriter(ms, Encoding.ASCII, 1024, true);
            var invoked    = false;
            var mixCommand = CreateMixCommand();

            mixCommand.Run = (s) => invoked = true;
            CommandInterpreter.Configure(mixCommand, CreateFindPasswordCommand(), output, output);
            var runGui = await CommandInterpreter.ExecuteCommandsAsync(new[] { "mix" });

            Assert.True(invoked);
            Assert.False(runGui);

            // Ensure backward compatibility with --mix
            mixCommand     = CreateMixCommand();
            mixCommand.Run = (s) => invoked = true;
            CommandInterpreter.Configure(mixCommand, CreateFindPasswordCommand(), output, output);
            invoked = false;
            runGui  = await CommandInterpreter.ExecuteCommandsAsync(new[] { "--mix" });

            Assert.True(invoked);
            Assert.False(runGui);
        }
Exemplo n.º 11
0
 static async Task Main(string[] args)
 {
     await CommandInterpreter.ExecuteCommandsAsync(args);
 }
Exemplo n.º 12
0
#pragma warning disable IDE1006 // Naming Styles

        private static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            StatusBarViewModel statusBar = null;
            bool runGui = false;

            try
            {
                Global = new Global();
                Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui");
                AvaloniaGlobalComponent.AvaloniaInstance    = Global;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

                runGui = await CommandInterpreter.ExecuteCommandsAsync(Global, args);

                if (!runGui)
                {
                    return;
                }
                Logger.LogStarting("Wasabi GUI");

                BuildAvaloniaApp()
                .BeforeStarting(async builder =>
                {
                    MainWindowViewModel.Instance        = new MainWindowViewModel();
                    MainWindowViewModel.Instance.Global = Global;
                    statusBar = new StatusBarViewModel(Global);
                    MainWindowViewModel.Instance.StatusBar = statusBar;

                    await Global.InitializeNoWalletAsync();

                    statusBar.Initialize(Global.Nodes.ConnectedNodes, Global.Synchronizer, Global.UpdateChecker);

                    if (Global.Network != Network.Main)
                    {
                        MainWindowViewModel.Instance.Title += $" - {Global.Network}";
                    }
                    Dispatcher.UIThread.Post(() =>
                    {
                        GC.Collect();
                    });
                }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", null, () => MainWindowViewModel.Instance);
            }
            catch (Exception ex)
            {
                Logger.LogCritical <Program>(ex);
                throw;
            }
            finally
            {
                statusBar?.Dispose();
                await Global.DisposeAsync();

                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      -= TaskScheduler_UnobservedTaskException;

                if (runGui)
                {
                    Logger.LogInfo($"Wasabi GUI stopped gracefully.", Logger.InstanceGuid.ToString());
                }
            }
        }
Exemplo n.º 13
0
        // When invoked without any argument it should launch in GUI mode
        public async Task InvokedWithoutArgumentsAsync()
        {
            var runGui = await CommandInterpreter.ExecuteCommandsAsync(new string[0]);

            Assert.True(runGui);
        }