private void PreviewButton_Click(object sender, RoutedEventArgs e) { try { var sp = new ScriptParser.ScriptParser(); sp.ParseScript(scriptPathTextBox.Text); var window = new PreviewWindow { Owner = this, Script = sp.ParsedScript }; window.ShowDialog(); } catch (ScriptParserException exception) { MessageBox.Show(exception.Message + string.Format( "\npath: {0} line: {1} column: {2}", exception.errorSource, exception.line, exception.column), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void WorkerThreadMain(string scriptPath) { try { var sp = new ScriptParser.ScriptParser(); sp.ParseScript(scriptPath); _script = sp.ParsedScript; sp.ParsedScript.Progress += WorkerThreadHandleProgress; sp.ParsedScript.Execute(); } catch (OperationCanceledException) { } catch (ScriptParserException exception) { WorkerThreadHandleError(exception.Message + string.Format( "\npath: {0} line: {1} column: {2}", exception.errorSource, exception.line, exception.column)); } catch (Exception exception) { WorkerThreadHandleError(exception.Message); } finally { _script = null; if (Application.Current != null) { Application.Current.Dispatcher.BeginInvoke( new Action(() => { executeButton.IsEnabled = true; }), null); } } }
public ICommand MakeCommand(CommandType commandType, List <string> arguments, string scriptPath) { switch (commandType) { case CommandType.Copy: if (arguments.Count == 2) { return(new CopyCommand(ParsePath(scriptPath, arguments[0]), ParsePath(scriptPath, arguments[1]))); } throw new ScriptParserException("copy expects 2 arguments", _source, _line); case CommandType.Move: if (arguments.Count == 2) { return(new MoveCommand(ParsePath(scriptPath, arguments[0]), ParsePath(scriptPath, arguments[1]))); } throw new ScriptParserException("move expects 2 arguments", _source, _line); case CommandType.Remove: if (arguments.Count == 1) { return(new RemoveCommand( ParsePath(scriptPath, arguments[0]))); } if (arguments.Count == 2) { return(new RemoveCommand( ParsePath(scriptPath, arguments[1]), ParseMode(arguments[0]))); } throw new ScriptParserException( "remove expects 1 or 2 arguments", _source, _line); case CommandType.CreateFile: if (arguments.Count == 1) { return(new CreateFileCommand( ParsePath(scriptPath, arguments[0]))); } if (arguments.Count == 2) { return(new CreateFileCommand( ParsePath(scriptPath, arguments[0]), ParseFileSize(arguments[1]))); } throw new ScriptParserException( "create_file command expects 1 or 2 arguments", _source, _line); case CommandType.CreateDirectory: if (arguments.Count == 1) { return(new CreateDirectoryCommand( ParsePath(scriptPath, arguments[0]))); } throw new ScriptParserException( "create_directory expects 1 argument", _source, _line); case CommandType.Execute: if (arguments.Count == 1) { _paths.Add(scriptPath); ScriptParser sp = new ScriptParser(_paths); string fullPath = ParsePath(scriptPath, arguments[0]); if (_paths.Contains(fullPath)) { throw new ScriptParserException(string.Format( "script {0} cannot be called by itself", fullPath), _source, _line); } sp.ParseScript(fullPath); _paths.Remove(scriptPath); return(sp.ParsedScript); } throw new ScriptParserException( "execute command expects 1 argument", _source, _line); case CommandType.Sleep: if (arguments.Count == 1) { return(new SleepCommand(ParseTimeInterval(arguments[0]))); } throw new ScriptParserException( "sleep expects 1 argument", _source, _line); default: throw new ScriptParserException("Undefined command type", _source, _line); } }
public ConversionAPI(ScriptParser parser, IDocumentWriter writer) { this.parser = parser; this.writer = writer; }