Exemple #1
0
        public Task ExecuteAsync(QueryResult result)
        {
            if (!(result is EverythingResult everything))
            {
                throw new ArgumentException("Expected an EverythingResult", nameof(result));
            }

            EverythingSdk.IncrementRunCount(everything.FullPath);
            OpenDefault.PathOrUrl(everything.FullPath);
            return(Task.CompletedTask);
        }
Exemple #2
0
        public Task ExecuteAsync(QueryResult result)
        {
            switch (result)
            {
            case OpenPowerShellResult _:
                _processStarter.OpenApplication("powershell", "-NoExit");
                break;

            case PowerShellFileResult fileResult:
                if (fileResult.RunInExternalShell)
                {
                    OpenDefault.PathOrUrl($"powershell -NoExit -File {fileResult.FilePath} {fileResult.Arguments}");
                }
                else
                {
                    using (var shellSession = PowerShell.Create())
                    {
                        shellSession.AddScript("Set-ExecutionPolicy Bypass -Scope Process");
                        shellSession.AddScript(fileResult.FilePath);
                        shellSession.Invoke();
                    }
                }
                break;

            case PowerShellCommandResult powershellResult:
                if (powershellResult.RunInExternalShell)
                {
                    OpenDefault.PathOrUrl($"powershell -NoExit -Command {powershellResult.Command}");
                }
                else
                {
                    using (var shellSession = PowerShell.Create())
                    {
                        shellSession.AddScript(powershellResult.Command);
                        var executionOutput = shellSession.Invoke(powershellResult.Command);
                        if (shellSession.HadErrors)
                        {
                            _logger.Information("Command {powerShellCommand} had errors", powershellResult.Command);
                        }
                    }
                }
                break;
            }

            return(Task.CompletedTask);
        }