From 4eee351d5c4c7465bd1449f21a481bfab96b6bf7 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 1 May 2018 15:37:36 +0300 Subject: Started working on developer console. --- .../Tango.MachineStudio.UI/Console/CodeTemplate.cs | 23 ++++++++ .../Console/ConsoleManager.cs | 25 +++++++++ .../Console/ConsoleOnExecuteParameters.cs | 26 +++++++++ .../Console/ConsoleWindow.xaml | 4 +- .../Console/ConsoleWindow.xaml.cs | 7 +++ .../Console/ConsoleWindowVM.cs | 64 +++++++++++++++++++++- 6 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/CodeTemplate.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleOnExecuteParameters.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/CodeTemplate.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/CodeTemplate.cs new file mode 100644 index 000000000..4b307051f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/CodeTemplate.cs @@ -0,0 +1,23 @@ +using System; +using System.Text; +using System.Linq; +using System.Drawing; +using System.Diagnostics; +using System.Windows.Forms; +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; +using Tango.MachineStudio.Common.Notifications; +using Tango.MachineStudio.UI.Console; + +public void OnExecute(ConsoleManager manager) +{ + manager.InvokeUI(() => + { + + var notification = manager.TangoIOC.GetInstance(); + notification.ShowInfo("Hello world!"); + + }); +} + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleManager.cs index 0a737c526..e2d525d95 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleManager.cs @@ -4,11 +4,36 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core.DI; +using Tango.MachineStudio.Common.Modules; namespace Tango.MachineStudio.UI.Console { public class ConsoleManager { public TangoIOC TangoIOC { get; set; } + private Action _writeLine; + + public ConsoleManager(Action writeLine) + { + _writeLine = writeLine; + TangoIOC = TangoIOC.Default; + } + + public void WriteLine(String text) + { + _writeLine(text); + } + + public void InvokeUI(Action action) + { + Core.Helpers.ThreadsHelper.InvokeUI(action); + } + + public void StartModule(String name) + { + IStudioModuleLoader loader = TangoIOC.Default.GetInstance(); + var module = loader.AllModules.SingleOrDefault(x => x.Name == name); + TangoIOC.Default.GetInstance().StartModule(module); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleOnExecuteParameters.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleOnExecuteParameters.cs new file mode 100644 index 000000000..b06637ccd --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleOnExecuteParameters.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Scripting; + +namespace Tango.MachineStudio.UI.Console +{ + public class ConsoleOnExecuteParameters : OnExecuteParameters + { + /// + /// Provides access to the script stub manager. + /// + public ConsoleManager manager; + + /// + /// Initializes a new instance of the class. + /// + /// The manager. + public ConsoleOnExecuteParameters(ConsoleManager manager) + { + this.manager = manager; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml index 90c07b1af..3a30eda57 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml @@ -57,12 +57,12 @@ - + - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs index 459c3d119..e22582a46 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs @@ -20,9 +20,16 @@ namespace Tango.MachineStudio.UI.Console /// public partial class ConsoleWindow : MetroWindow { + private ConsoleWindowVM _vm; + public ConsoleWindow() { InitializeComponent(); + + this.Loaded += (_, __) => + { + _vm = this.DataContext as ConsoleWindowVM; + }; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs index c88976948..9c1192f06 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs @@ -7,13 +7,19 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Threading; using Tango.Core.Commands; +using Tango.Core.Helpers; using Tango.MachineStudio.Common.Modules; +using Tango.MachineStudio.Common.Notifications; +using Tango.Scripting; using Tango.SharedUI; namespace Tango.MachineStudio.UI.Console { public class ConsoleWindowVM : ViewModel { + private IStudioModuleLoader _moduleLoader; + private INotificationProvider _notificatrion; + /// /// Gets or sets the additional highlight C# types. @@ -25,6 +31,23 @@ namespace Tango.MachineStudio.UI.Console /// public ObservableCollection> IntellisenseTypes { get; set; } + private String _code; + + public String Code + { + get { return _code; } + set { _code = value; RaisePropertyChangedAuto(); } + } + + private String _log; + + public String Log + { + get { return _log; } + set { _log = value; RaisePropertyChangedAuto(); } + } + + /// /// Gets or sets the run command. /// @@ -40,15 +63,18 @@ namespace Tango.MachineStudio.UI.Console /// public RelayCommand ClearCommand { get; set; } - public ConsoleWindowVM(IStudioModuleLoader moduleLoader) + public ConsoleWindowVM(IStudioModuleLoader moduleLoader, INotificationProvider notification) { + _moduleLoader = moduleLoader; + _notificatrion = notification; + RunCommand = new RelayCommand(Run); StopCommand = new RelayCommand(Stop); HighlightTypes = new ObservableCollection>(); IntellisenseTypes = new ObservableCollection>(); - IntellisenseTypes.Add(new KeyValuePair("consoleManager", typeof(ConsoleManager))); + IntellisenseTypes.Add(new KeyValuePair("manager", typeof(ConsoleManager))); foreach (var moduleType in moduleLoader.UserModules.SelectMany(x => x.MainViewType.Assembly.GetTypes())) { @@ -58,6 +84,22 @@ namespace Tango.MachineStudio.UI.Console } } + foreach (var type in this.GetType().Assembly.GetTypes()) + { + if (!type.FullName.Contains("<") && !type.FullName.Contains(">")) + { + HighlightTypes.Add(new KeyValuePair(type.Name, type)); + } + } + + foreach (var type in typeof(INotificationProvider).Assembly.GetTypes()) + { + if (!type.FullName.Contains("<") && !type.FullName.Contains(">")) + { + HighlightTypes.Add(new KeyValuePair(type.Name, type)); + } + } + HighlightTypes.Add(new KeyValuePair("Thread", typeof(Thread))); HighlightTypes.Add(new KeyValuePair("DateTime", typeof(DateTime))); HighlightTypes.Add(new KeyValuePair("TimeSpan", typeof(TimeSpan))); @@ -73,6 +115,8 @@ namespace Tango.MachineStudio.UI.Console { IntellisenseTypes.Add(item); } + + Code = EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.MachineStudio.UI.Console.CodeTemplate.cs"); } private void Stop() @@ -80,9 +124,23 @@ namespace Tango.MachineStudio.UI.Console } - private void Run() + private async void Run() { + ScriptEngine engine = new ScriptEngine(new ConsoleOnExecuteParameters(new ConsoleManager(WriteLine))); + engine.ReferencedAssemblies.Add(this.GetType()); + engine.ReferencedAssemblies.Add(typeof(INotificationProvider)); + + foreach (var module in _moduleLoader.AllModules) + { + engine.ReferencedAssemblies.Add(module.GetType()); + } + await engine.Run(Code); + } + + private void WriteLine(String text) + { + Log += text + Environment.NewLine; } } } -- cgit v1.3.1