Пример #1
0
        /// <summary>
        /// Change the state of the interpreter.
        /// </summary>
        /// <param name="source">The source from where we changed the state (an interpreter usually).</param>
        /// <param name="e">The new state.</param>
        internal void ChangeState(object source, BaZicInterpreterStateChangeEventArgs e)
        {
            if (e.State == BaZicInterpreterState.StoppedWithError || e.State == BaZicInterpreterState.Stopped)
            {
                ProgramInterpreter?.CloseUserInterface();
            }

            lock (_stateChangedHistory)
            {
                var oldState = State;

                switch (e.State)
                {
                case BaZicInterpreterState.StoppedWithError:
                    if (State != BaZicInterpreterState.StoppedWithError)
                    {
                        Error = e.Error;
                        State = e.State;
                    }
                    break;

                case BaZicInterpreterState.Pause:
                case BaZicInterpreterState.Preparing:
                case BaZicInterpreterState.Ready:
                case BaZicInterpreterState.Running:
                case BaZicInterpreterState.Idle:
                case BaZicInterpreterState.Stopped:
                    State = e.State;
                    break;

                case BaZicInterpreterState.Log:
                    Logger.Instance.Debug($"BaZic Interpreter : {e.LogMessage}");
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(e.State));
                }

                if (e.State == BaZicInterpreterState.Log || e.State == BaZicInterpreterState.Ready || State != oldState)
                {
                    _stateChangedHistory.Add(e);
                    StateChanged?.Invoke(this, e);
                    _middleware.SendLog(this, e);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Sends a log to the <see cref="BaZicInterpreter"/>.
 /// </summary>
 /// <param name="sender">The core.</param>
 /// <param name="log">The log.</param>
 internal void SendLog(BaZicInterpreterCore sender, BaZicInterpreterStateChangeEventArgs log)
 {
     _baZicInterpreter.SendLog(log);
 }
Пример #3
0
 /// <summary>
 /// Raises the <see cref="StateChanged"/> event.
 /// </summary>
 /// <param name="log"></param>
 internal void SendLog(BaZicInterpreterStateChangeEventArgs log)
 {
     StateChanged?.Invoke(this, log);
 }