public GraphedItems CheckForNewGraphedItems() { if (_lastScriptChangedEventFiredAt > _lastProcessedScriptChangedEvent) { // Only actually read the latest script file contents after a period of time since the // last change event fired. This prevents reading while it's still being written, and should // help with file lock contention. var lastFiredAtTicks = _lastScriptChangedEventFiredAt; var lastFiredAt = new DateTime(lastFiredAtTicks); if ((DateTime.Now - lastFiredAt).TotalMilliseconds > 200) { var contents = TryLoadFileContents(); if (contents != null) { Interlocked.Exchange(ref _lastProcessedScriptChangedEvent, lastFiredAtTicks); try { _onScreenLogger.Clear(); return(_scriptRunner.RunScript(contents)); } catch (ScriptException exception) { var content = "Failed to run script:\n\n"; if (exception.ShowStackTrace) { // ReSharper disable once PossibleNullReferenceException content += exception.InnerException.ToString(); } else { // ReSharper disable once PossibleNullReferenceException content += $"{exception.Message}: {exception.InnerException.Message}"; } _onScreenLogger.LogMessage(content); } catch (PointConversionException exception) { _onScreenLogger.LogMessage(exception.Message); } catch (Exception exception) { _onScreenLogger.LogMessage($"Failed to run script:\n\n{exception}"); } } } } return(null); }
public void StartScript(int scriptIndex) { ClearErrors(); _currentScript = _scriptStore.GetScript(scriptIndex); _logger.LogStart(_currentScript.Name); _currentRunner = _scriptRunnerFactory.CreateScriptRunner(_currentScript); _currentRunner.OutputDataReceived += WriteOutput; _currentRunner.ErrorReceived += WriteErrorOutput; _currentRunner.Done += Done; _currentRunner.RunScript(); }
public void LoadScript <TScript>() where TScript : IMMBotScript, new() { _scriptRunner.RunScript(TypedScript.Create <TScript>()); }