using Qrakhen.Qamp.Core.Execution; using Qrakhen.Qamp.Editor.Commands; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Windows.Input; namespace Qrakhen.Qamp.Editor.ViewModel; public class MainViewModel : ObservableObject { public EditorFrameViewModel EditorFrame { get; set; } private string _runnerOutput = ""; public string RunnerOutput { get => _runnerOutput; set => SetProperty(ref _runnerOutput, value); } public ICommand RunCommand { get; set; } public ICommand SaveCommand { get; set; } public ICommand LoadCommand { get; set; } public MainViewModel() { EditorFrame = new EditorFrameViewModel(); RunCommand = new RelayCommand(ExecuteRun, CanRun); SaveCommand = null; LoadCommand = null; } private void ExecuteRun() { try { string code = EditorFrame.Serialize(); Runner runner = new Runner(new Options((m) => { RunnerOutput += m; })); MemoryStream stream = new MemoryStream(); stream.Write(EditorFrame.Encoding.GetBytes(code)); runner.Run(stream); OnPropertyChanged(nameof(RunnerOutput)); } catch (Exception ex) { RunnerOutput += $"\nERR: {ex.Message}\n"; } } private bool CanRun() { return true; } }