public async Task <object> ExecuteScript(string script, string filename = null, string sandbox = "defaultSandbox", CancellationToken cancellationToken = new CancellationToken(), params object[] args) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new ExecuteScriptCommand(script) { filename = filename, sandbox = sandbox }; if (args.Length > 0) { comm1.Args = args; //.Select(v => v.ToString()).ToArray(); } await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { var err = comm1.Error["error"]?.ToString(); if (err == "javascript error") { throw new InvalidOperationException(comm1.Error["message"].ToString() ?? comm1.Error.ToString()); } /*if (err == "stale element reference") */ throw new WebBrowserException(comm1.Error); } return(ParseExecuteScriptReturnValue((comm1.Result as JObject)?["value"])); //comm1.Result; }
/// <summary> /// Implements the constructor for the Add-in object. Place your initialization code within this method. /// </summary> public CSqlAddin() { Assembly currentAssembly = Assembly.GetExecutingAssembly(); string imageResourceRoot = "csql.addin.Resources.Images.Commands."; VsCommand command; int position = 1; command = new SettingsCommand(); command.CommandBarName = "csql"; command.IconId = 50; command.Icon = new VsCommandIcon(currentAssembly, imageResourceRoot + "Settings.bmp"); command.Position = position++; RegisterCommand(command); command = new ExecuteScriptCommand(); command.CommandBarName = "csql"; command.IconId = 20; command.Icon = new VsCommandIcon(currentAssembly, imageResourceRoot + "ExecuteScript.bmp"); command.Position = position++; RegisterCommand(command); command = new CancelScriptCommand(); command.CommandBarName = "csql"; command.IconId = 21; command.Icon = new VsCommandIcon(currentAssembly, imageResourceRoot + "CancelScript.bmp"); command.Position = position++; RegisterCommand(command); command = new LocateFileCommand(); command.CommandBarName = "csql"; command.IconId = 40; command.Icon = new VsCommandIcon(currentAssembly, imageResourceRoot + "LocateFile.bmp"); command.Position = position++; RegisterCommand(command); command = new GroupFilesCommand(); command.CommandBarName = "csql"; command.IconId = 30; command.Icon = new VsCommandIcon(currentAssembly, imageResourceRoot + "GroupFiles.bmp"); command.Position = position++; RegisterCommand(command); command = new AboutDialogCommand(); command.CommandBarName = "csql"; command.IconId = 10; command.Icon = new VsCommandIcon(currentAssembly, imageResourceRoot + "AboutDialog.bmp"); command.Position = position++; RegisterCommand(command); }
public void ShouldComposeScripts([Frozen] Mock <IFileSystem> fileSystem, Mock <IScriptLibraryComposer> composer) { var cmd = new ExecuteScriptCommand( null, null, fileSystem.Object, new Mock <IScriptExecutor>().Object, new Mock <IScriptPackResolver>().Object, new TestLogProvider(), new Mock <IAssemblyResolver>().Object, composer.Object); cmd.Execute(); composer.Verify(c => c.Compose(It.IsAny <string>(), null)); }
public override void ExecuteHotkey(int index) { base.ExecuteHotkey(index); switch (index) { case 0: ExecuteScriptCommand.Execute(null); break; case 1: StopScriptCommand.Execute(null); break; case 2: Variables.Clear(); break; } }
private static int Go(string[] args) { if (args.Length < 1) { //no script provided. DefaultConsoles.Error.Red(c => c.WriteLine("No script provided.")); return(-1); } args = args.Select(ConsumeArg).Where(a => a != null).ToArray(); LogManager.Initialize(_logType); if (args.Length == 0) { _log.Error("No script file provided."); return(1); } var scriptPath = args[0]; scriptPath = Path.GetFullPath(scriptPath); if (!File.Exists(scriptPath)) { _log.Error($"Script not found: '{scriptPath}'"); return(2); } var scriptFile = new ScriptFile(scriptPath); var fileCommandOptions = new ExecuteScriptCommandOptions( scriptFile, args.Skip(1).ToArray(), _optimizationLevel, null, _disableCache, new ScriptGlobals(scriptFile.Path, MakeLocationDictionary(scriptFile.Path))); var fileCommand = new ExecuteScriptCommand(); return(fileCommand.Run <int>(fileCommandOptions).Result); }
public void MigratesTheFileSystem( [Frozen] Mock <IFileSystem> fileSystem, [Frozen] Mock <IFileSystemMigrator> fileSystemMigrator) { // arrange var sut = new ExecuteScriptCommand( null, null, fileSystem.Object, new Mock <IScriptExecutor>().Object, new Mock <IScriptPackResolver>().Object, new Mock <ILog>().Object, new Mock <IAssemblyResolver>().Object, fileSystemMigrator.Object); // act sut.Execute(); // assert fileSystemMigrator.Verify(m => m.Migrate(), Times.Once); }
/// <summary> /// Implements the constructor for the Add-in object. Place your initialization code within this method. /// </summary> public CSqlAddIn() { String imageResourceRoot = "csql.addin.Resources.Images.Commands."; VsCommand command; int position = 1; command = new SettingsCommand(); command.CommandBarName = "csql"; command.Icon = new VsCommandIcon(imageResourceRoot + "Settings.bmp"); command.Position = position++; RegisterCommand(command); command = new ExecuteScriptCommand(); command.CommandBarName = "csql"; command.Icon = new VsCommandIcon(imageResourceRoot + "ExecuteScript.bmp"); command.Position = position++; RegisterCommand(command); command = new LocateFileCommand(); command.CommandBarName = "csql"; command.Icon = new VsCommandIcon(imageResourceRoot + "LocateFile.bmp"); command.Position = position++; RegisterCommand(command); command = new GroupFilesCommand(); command.CommandBarName = "csql"; command.Icon = new VsCommandIcon(imageResourceRoot + "GroupFiles.bmp"); command.Position = position++; RegisterCommand(command); command = new AboutDialogCommand(); command.CommandBarName = "csql"; command.Icon = new VsCommandIcon(imageResourceRoot + "AboutDialog.bmp"); command.Position = position++; RegisterCommand(command); }
private static int Wain(string[] args) { var app = new CommandLineApplication(throwOnUnexpectedArg: false) { ExtendedHelpText = "Starting without a path to a CSX file or a command, starts the REPL (interactive) mode." }; var file = app.Argument("script", "Path to CSX script"); var interactive = app.Option("-i | --interactive", "Execute a script and drop into the interactive mode afterwards.", CommandOptionType.NoValue); var configuration = app.Option("-c | --configuration <configuration>", "Configuration to use for running the script [Release/Debug] Default is \"Debug\"", CommandOptionType.SingleValue); var packageSources = app.Option("-s | --sources <SOURCE>", "Specifies a NuGet package source to use when resolving NuGet packages.", CommandOptionType.MultipleValue); var debugMode = app.Option(DebugFlagShort + " | " + DebugFlagLong, "Enables debug output.", CommandOptionType.NoValue); var verbosity = app.Option("--verbosity", " Set the verbosity level of the command. Allowed values are t[trace], d[ebug], i[nfo], w[arning], e[rror], and c[ritical].", CommandOptionType.SingleValue); var nocache = app.Option("--no-cache", "Disable caching (Restore and Dll cache)", CommandOptionType.NoValue); var infoOption = app.Option("--info", "Displays environmental information", CommandOptionType.NoValue); var argsBeforeDoubleHyphen = args.TakeWhile(a => a != "--").ToArray(); var argsAfterDoubleHyphen = args.SkipWhile(a => a != "--").Skip(1).ToArray(); const string helpOptionTemplate = "-? | -h | --help"; app.HelpOption(helpOptionTemplate); app.VersionOption("-v | --version", () => new VersionProvider().GetCurrentVersion().Version); app.Command("eval", c => { c.Description = "Execute CSX code."; var code = c.Argument("code", "Code to execute."); var cwd = c.Option("-cwd |--workingdirectory <currentworkingdirectory>", "Working directory for the code compiler. Defaults to current directory.", CommandOptionType.SingleValue); c.HelpOption(helpOptionTemplate); c.OnExecute(async() => { var source = code.Value; if (string.IsNullOrWhiteSpace(source)) { if (Console.IsInputRedirected) { source = await Console.In.ReadToEndAsync(); } else { c.ShowHelp(); return(0); } } var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); var options = new ExecuteCodeCommandOptions(source, cwd.Value(), app.RemainingArguments.Concat(argsAfterDoubleHyphen).ToArray(), configuration.ValueEquals("release", StringComparison.OrdinalIgnoreCase) ? OptimizationLevel.Release : OptimizationLevel.Debug, nocache.HasValue(), packageSources.Values?.ToArray()); return(await new ExecuteCodeCommand(ScriptConsole.Default, logFactory).Execute <int>(options)); }); }); app.Command("init", c => { c.Description = "Creates a sample script along with the launch.json file needed to launch and debug the script."; var fileName = c.Argument("filename", "(Optional) The name of the sample script file to be created during initialization. Defaults to 'main.csx'"); var cwd = c.Option("-cwd |--workingdirectory <currentworkingdirectory>", "Working directory for initialization. Defaults to current directory.", CommandOptionType.SingleValue); c.HelpOption(helpOptionTemplate); c.OnExecute(() => { var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); new InitCommand(logFactory).Execute(new InitCommandOptions(fileName.Value, cwd.Value())); return(0); }); }); app.Command("new", c => { c.Description = "Creates a new script file"; var fileNameArgument = c.Argument("filename", "The script file name"); var cwd = c.Option("-cwd |--workingdirectory <currentworkingdirectory>", "Working directory the new script file to be created. Defaults to current directory.", CommandOptionType.SingleValue); c.HelpOption(helpOptionTemplate); c.OnExecute(() => { var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); var scaffolder = new Scaffolder(logFactory); if (fileNameArgument.Value == null) { c.ShowHelp(); return(0); } scaffolder.CreateNewScriptFile(fileNameArgument.Value, cwd.Value() ?? Directory.GetCurrentDirectory()); return(0); }); }); // windows only if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // on windows we have command to register .csx files to be executed by dotnet-script app.Command("register", c => { c.Description = "Register .csx file handler to enable running scripts directly"; c.HelpOption(helpOptionTemplate); c.OnExecute(() => { var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); var scaffolder = new Scaffolder(logFactory); scaffolder.RegisterFileHandler(); }); }); } app.Command("publish", c => { c.Description = "Creates a self contained executable or DLL from a script"; var fileNameArgument = c.Argument("filename", "The script file name"); var publishDirectoryOption = c.Option("-o |--output", "Directory where the published executable should be placed. Defaults to a 'publish' folder in the current directory.", CommandOptionType.SingleValue); var dllName = c.Option("-n |--name", "The name for the generated DLL (executable not supported at this time). Defaults to the name of the script.", CommandOptionType.SingleValue); var dllOption = c.Option("--dll", "Publish to a .dll instead of an executable.", CommandOptionType.NoValue); var commandConfig = c.Option("-c | --configuration <configuration>", "Configuration to use for publishing the script [Release/Debug]. Default is \"Debug\"", CommandOptionType.SingleValue); var runtime = c.Option("-r |--runtime", "The runtime used when publishing the self contained executable. Defaults to your current runtime.", CommandOptionType.SingleValue); c.HelpOption(helpOptionTemplate); c.OnExecute(() => { if (fileNameArgument.Value == null) { c.ShowHelp(); return(0); } var options = new PublishCommandOptions ( new ScriptFile(fileNameArgument.Value), publishDirectoryOption.Value(), dllName.Value(), dllOption.HasValue() ? PublishType.Library : PublishType.Executable, commandConfig.ValueEquals("release", StringComparison.OrdinalIgnoreCase) ? OptimizationLevel.Release : OptimizationLevel.Debug, packageSources.Values?.ToArray(), runtime.Value() ?? ScriptEnvironment.Default.RuntimeIdentifier, nocache.HasValue() ); var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); new PublishCommand(ScriptConsole.Default, logFactory).Execute(options); return(0); }); }); app.Command("exec", c => { c.Description = "Run a script from a DLL."; var dllPath = c.Argument("dll", "Path to DLL based script"); var commandDebugMode = c.Option(DebugFlagShort + " | " + DebugFlagLong, "Enables debug output.", CommandOptionType.NoValue); c.HelpOption(helpOptionTemplate); c.OnExecute(async() => { if (string.IsNullOrWhiteSpace(dllPath.Value)) { c.ShowHelp(); return(0); } var options = new ExecuteLibraryCommandOptions ( dllPath.Value, app.RemainingArguments.Concat(argsAfterDoubleHyphen).ToArray(), nocache.HasValue() ); var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); return(await new ExecuteLibraryCommand(ScriptConsole.Default, logFactory).Execute <int>(options)); }); }); app.OnExecute(async() => { int exitCode = 0; var scriptFile = new ScriptFile(file.Value); var optimizationLevel = configuration.ValueEquals("release", StringComparison.OrdinalIgnoreCase) ? OptimizationLevel.Release : OptimizationLevel.Debug; var scriptArguments = app.RemainingArguments.Concat(argsAfterDoubleHyphen).ToArray(); var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); if (infoOption.HasValue()) { var environmentReporter = new EnvironmentReporter(logFactory); await environmentReporter.ReportInfo(); return(0); } if (scriptFile.HasValue) { if (interactive.HasValue()) { return(await RunInteractiveWithSeed(file.Value, logFactory, scriptArguments, packageSources.Values?.ToArray())); } var fileCommandOptions = new ExecuteScriptCommandOptions ( new ScriptFile(file.Value), scriptArguments, optimizationLevel, packageSources.Values?.ToArray(), interactive.HasValue(), nocache.HasValue() ); var fileCommand = new ExecuteScriptCommand(ScriptConsole.Default, logFactory); return(await fileCommand.Run <int, CommandLineScriptGlobals>(fileCommandOptions)); } else { await RunInteractive(!nocache.HasValue(), logFactory, packageSources.Values?.ToArray()); } return(exitCode); }); return(app.Execute(argsBeforeDoubleHyphen)); }
/// <summary> /// Send a command to a dedicated client /// </summary> /// <param name="scriptCommand">Basic Information of the command</param> /// <returns></returns> public async Task SendCommandToClient(ExecuteScriptCommand scriptCommand) { await Clients.OthersInGroup(scriptCommand.AppId).SendAsync("ExecuteCommand", scriptCommand.CommandTitle, scriptCommand.CommandParam); }
public ICommand CreateCommand(ScriptCsArgs args) { if (args.ScriptName != null) { var executeCommand = new ExecuteScriptCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.Executor, _scriptServiceRoot.ScriptPackResolver); if (args.Restore) { var restoreCommand = new RestoreCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver); return new CompositeCommand(restoreCommand, executeCommand); } return executeCommand; } if (args.Install != null) { var installCommand = new InstallCommand( args.Install, args.AllowPreReleaseFlag, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver, _scriptServiceRoot.PackageInstaller); var restoreCommand = new RestoreCommand( args.Install, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver); return new CompositeCommand(installCommand, restoreCommand); } if (args.Clean) { var cleanCommand = new CleanCommand( args.ScriptName, _scriptServiceRoot.FileSystem, _scriptServiceRoot.PackageAssemblyResolver); return cleanCommand; } if (args.Save) { return new SaveCommand(_scriptServiceRoot.PackageAssemblyResolver); } if (args.Version) { return new VersionCommand(); } return new InvalidCommand(); }
public string ProcessCommand(string content) { var requestData = JsonConvert.DeserializeObject <Command>(content); var command = requestData.Name; var parameters = requestData.Parameters; string elementId = null; if (parameters == null) { throw new NullReferenceException("Parameters can not be NULL"); } JToken elementIdObject; if (parameters.TryGetValue("ID", out elementIdObject)) { elementId = elementIdObject.ToString(); } CommandBase commandToExecute; if (command.Equals("ping")) { // Service command return("<pong>"); } // TODO: Refactor similar to CommandExecutors in Driver if (command.Equals(DriverCommand.GetAlertText)) { commandToExecute = new AlertTextCommand(); } else if (command.Equals(DriverCommand.AcceptAlert)) { commandToExecute = new AlertCommand { Action = AlertCommand.With.Accept }; } else if (command.Equals(DriverCommand.DismissAlert)) { commandToExecute = new AlertCommand { Action = AlertCommand.With.Dismiss }; } else if (command.Equals(DriverCommand.FindElement) || command.Equals(DriverCommand.FindChildElement)) { commandToExecute = new ElementCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.FindElements) || command.Equals(DriverCommand.FindChildElements)) { commandToExecute = new ElementsCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.ClickElement)) { commandToExecute = new ClickCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.SendKeysToElement)) { var values = ((JArray)parameters["value"]).ToObject <List <string> >(); var value = string.Empty; if (values.Any()) { value = values.Aggregate((aggregated, next) => aggregated + next); } commandToExecute = new ValueCommand { ElementId = elementId, KeyString = value }; } else if (command.Equals(DriverCommand.GetElementText)) { commandToExecute = new TextCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.IsElementDisplayed)) { commandToExecute = new DisplayedCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementLocation)) { commandToExecute = new LocationCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementLocationOnceScrolledIntoView)) { commandToExecute = new LocationInViewCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementSize)) { commandToExecute = new GetElementSizeCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementRect)) { commandToExecute = new GetElementRectCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetPageSource)) { commandToExecute = new PageSourceCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetOrientation)) { commandToExecute = new OrientationCommand(); } else if (command.Equals(DriverCommand.GetElementAttribute)) { commandToExecute = new GetElementAttributeCommand { ElementId = elementId }; } else if (command.Equals(ExtendedDriverCommand.InvokeAppBarItemCommand)) { commandToExecute = new InvokeAppBarItemCommand(); } else if (command.Equals(DriverCommand.ExecuteScript)) { commandToExecute = new ExecuteScriptCommand(); } else { throw new NotImplementedException("Not implemented: " + command); } // TODO: Replace passing Automator to command with passing some kind of configuration commandToExecute.Automator = this; commandToExecute.Parameters = parameters; var response = commandToExecute.Do(); return(response); }