diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-05-01 15:37:36 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-05-01 15:37:36 +0300 |
| commit | 4eee351d5c4c7465bd1449f21a481bfab96b6bf7 (patch) | |
| tree | 2e024259b863815615c357951567f9a7c24e347e /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console | |
| parent | 47fad304ebc8f056f1c5ffcde037c66029fc80c9 (diff) | |
| download | Tango-4eee351d5c4c7465bd1449f21a481bfab96b6bf7.tar.gz Tango-4eee351d5c4c7465bd1449f21a481bfab96b6bf7.zip | |
Started working on developer console.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console')
6 files changed, 144 insertions, 5 deletions
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<INotificationProvider>(); + 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<String> _writeLine; + + public ConsoleManager(Action<String> 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<IStudioModuleLoader>(); + var module = loader.AllModules.SingleOrDefault(x => x.Name == name); + TangoIOC.Default.GetInstance<ViewModels.MainViewVM>().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 + { + /// <summary> + /// Provides access to the script stub manager. + /// </summary> + public ConsoleManager manager; + + /// <summary> + /// Initializes a new instance of the <see cref="StubOnExecuteParameters"/> class. + /// </summary> + /// <param name="manager">The manager.</param> + 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 @@ <RowDefinition Height="200*"/> </Grid.RowDefinitions> - <controls:ScriptEditorControl HighlightTypes="{Binding HighlightTypes}" IntellisenseTypes="{Binding IntellisenseTypes}"></controls:ScriptEditorControl> + <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" RunCommand="{Binding RunCommand}" StopCommand="{Binding StopCommand}" HighlightTypes="{Binding HighlightTypes}" IntellisenseTypes="{Binding IntellisenseTypes}"></controls:ScriptEditorControl> <GridSplitter Grid.Row="1" Background="#101010" Foreground="#202020" BorderBrush="#202020" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" /> - <TextBox x:Name="txtLog" FontFamily="Lucida Console" Background="Black" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro" Grid.Row="2"></TextBox> + <TextBox x:Name="txtLog" Text="{Binding Log}" FontFamily="Lucida Console" Background="Black" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro" Grid.Row="2"></TextBox> </Grid> </Grid> </Grid> 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 /// </summary> 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; + /// <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; } } } |
