1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
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.
/// </summary>
public ObservableCollection<KeyValuePair<String, Type>> HighlightTypes { get; set; }
/// <summary>
/// Gets or sets the intellisense types.
/// </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>
public RelayCommand RunCommand { get; set; }
/// <summary>
/// Gets or sets the stop command.
/// </summary>
public RelayCommand StopCommand { get; set; }
/// <summary>
/// Gets or sets the clear command.
/// </summary>
public RelayCommand ClearCommand { get; set; }
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>("manager", typeof(ConsoleManager)));
foreach (var moduleType in moduleLoader.UserModules.SelectMany(x => x.MainViewType.Assembly.GetTypes()))
{
if (!moduleType.FullName.Contains("<") && !moduleType.FullName.Contains(">"))
{
HighlightTypes.Add(new KeyValuePair<string, Type>(moduleType.FullName, moduleType));
}
}
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)));
HighlightTypes.Add(new KeyValuePair<string, Type>("Dispatcher", typeof(Dispatcher)));
HighlightTypes.Add(new KeyValuePair<string, Type>("Task", typeof(Task)));
HighlightTypes.Add(new KeyValuePair<string, Type>("List", typeof(IList<Object>)));
HighlightTypes.Add(new KeyValuePair<string, Type>("int", typeof(Int32)));
HighlightTypes.Add(new KeyValuePair<string, Type>("double", typeof(Double)));
HighlightTypes.Add(new KeyValuePair<string, Type>("String", typeof(String)));
HighlightTypes.Add(new KeyValuePair<string, Type>("string", typeof(String)));
foreach (var item in HighlightTypes)
{
IntellisenseTypes.Add(item);
}
Code = EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.MachineStudio.UI.Console.CodeTemplate.cs");
}
private void Stop()
{
}
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;
}
}
}
|