aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs64
1 files changed, 61 insertions, 3 deletions
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;
+
/// <summary>
/// Gets or sets the additional highlight C# types.
@@ -25,6 +31,23 @@ namespace Tango.MachineStudio.UI.Console
/// </summary>
public ObservableCollection<KeyValuePair<String, Type>> 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(); }
+ }
+
+
/// <summary>
/// Gets or sets the run command.
/// </summary>
@@ -40,15 +63,18 @@ namespace Tango.MachineStudio.UI.Console
/// </summary>
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<KeyValuePair<string, Type>>();
IntellisenseTypes = new ObservableCollection<KeyValuePair<string, Type>>();
- IntellisenseTypes.Add(new KeyValuePair<string, Type>("consoleManager", typeof(ConsoleManager)));
+ IntellisenseTypes.Add(new KeyValuePair<string, Type>("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<string, Type>(type.Name, type));
+ }
+ }
+
+ foreach (var type in typeof(INotificationProvider).Assembly.GetTypes())
+ {
+ if (!type.FullName.Contains("<") && !type.FullName.Contains(">"))
+ {
+ HighlightTypes.Add(new KeyValuePair<string, Type>(type.Name, type));
+ }
+ }
+
HighlightTypes.Add(new KeyValuePair<string, Type>("Thread", typeof(Thread)));
HighlightTypes.Add(new KeyValuePair<string, Type>("DateTime", typeof(DateTime)));
HighlightTypes.Add(new KeyValuePair<string, Type>("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;
}
}
}