private void RunScriptButton_Click(object sender, EventArgs e) { // Cancel and playback, just in case HK_CancelPlayback(); m_scriptOutput.Clear(); StartPlayingScript(); }
public ScriptViewModel(Interfaces.IConnection client) { Script = new TextDocument(); log = new LogStream(); log.PropertyChanged += Log_PropertyChanged; this.engine = new ScriptEngine.V8Engine((Client)client); RunCommand = new DelegateCommand <string>((body) => { Task.Run(() => { IsRunning = true; this.tokenSource = new CancellationTokenSource(); var cancel = tokenSource.Token; Task.Run(() => { do { engine.Run(body, log, cancel); } while (_isRepeat && !cancel.IsCancellationRequested); IsRunning = false; }, cancel); }); }); StopCommand = new DelegateCommand(() => { engine.Stop(); this.tokenSource.Cancel(); IsRunning = false; }); RepeatCommand = new DelegateCommand(() => { IsRepeat = !_isRepeat; }); LoadCommand = new DelegateCommand(() => { using (var ofd = new OpenFileDialog()) { ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); ofd.Filter = "Javascript files (*.js)|*.js|All files (*.*)|*.*"; ofd.FilterIndex = 1; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { Script = new TextDocument(File.ReadAllText(ofd.FileName, System.Text.Encoding.UTF8)); } } }); ClearOutputCommand = new DelegateCommand(() => { ScriptOutput.Clear(); }); }