Esempio n. 1
0
        static int Main(string[] args)
        {
            var app = ShellHelper.CreateConsoleApp("cv4pve-pepper",
                                                   "Launching SPICE on Proxmox VE");

            var optVmId         = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME);
            var optRemoteViewer = app.Option("--viewer",
                                             "Executable SPICE client remote viewer",
                                             CommandOptionType.SingleValue)
                                  .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME);

            optRemoteViewer.Accepts().ExistingFile();

            app.OnExecute(() =>
            {
                var fileName = Path.GetTempFileName().Replace(".tmp", ".vv");
                var ret      = SpiceHelper.CreateFileSpaceClient(app.ClientTryLogin(), optVmId.Value(), fileName);

                if (ret)
                {
                    var process = new Process
                    {
                        StartInfo = new ProcessStartInfo()
                        {
                            UseShellExecute        = false,
                            CreateNoWindow         = true,
                            RedirectStandardOutput = false,
                            FileName  = StringHelper.Quote(optRemoteViewer.Value()),
                            Arguments = StringHelper.Quote(fileName)
                        }
                    };

                    if (app.DebugIsActive())
                    {
                        app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}");
                        app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}");
                    }

                    if (!app.DryRunIsActive())
                    {
                        process.Start();
                        ret = process.HasExited ? process.ExitCode == 0 : true;
                    }
                }

                return(ret ? 0 : 1);
            });

            return(app.ExecuteConsoleApp(args));
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE");

            var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME);

            var optRemoteViewer = app.Option("--viewer",
                                             "Executable SPICE client remote viewer",
                                             CommandOptionType.SingleValue)
                                  .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME);

            optRemoteViewer.Accepts().ExistingFile();

            app.OnExecute(() =>
            {
                var fileName = Path.GetTempFileName().Replace(".tmp", ".vv");
                var client   = app.ClientTryLogin();
                var ret      = SpiceHelper.CreateFileSpaceClient(client, optVmId.Value(), fileName);

                if (ret)
                {
                    var startInfo = new ProcessStartInfo
                    {
                        UseShellExecute        = false,
                        CreateNoWindow         = true,
                        RedirectStandardOutput = false,
                    };

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        startInfo.FileName  = "/bin/bash";
                        startInfo.Arguments = $"-c \"{optRemoteViewer.Value()} {fileName}\"";
                    }
                    else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        startInfo.FileName  = StringHelper.Quote(optRemoteViewer.Value());
                        startInfo.Arguments = StringHelper.Quote(fileName);
                    }

                    var process = new Process
                    {
                        StartInfo = startInfo
                    };

                    if (app.DebugIsActive())
                    {
                        app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}");
                        app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}");
                    }

                    if (!app.DryRunIsActive())
                    {
                        process.Start();
                        ret = !process.HasExited || process.ExitCode == 0;
                    }
                }
                else
                {
                    if (!client.LastResult.IsSuccessStatusCode)
                    {
                        app.Out.WriteLine($"Error: {client.LastResult.ReasonPhrase}");
                    }
                }

                return(ret ? 0 : 1);
            });

            return(app.ExecuteConsoleApp(args));
        }