aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/CodeTemplate.cs23
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleManager.cs39
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleOnExecuteParameters.cs26
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml223
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs43
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs257
6 files changed, 611 insertions, 0 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
new file mode 100644
index 000000000..e2d525d95
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleManager.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+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
new file mode 100644
index 000000000..22338fea7
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml
@@ -0,0 +1,223 @@
+<mahapps:MetroWindow x:Class="Tango.MachineStudio.UI.Console.ConsoleWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+ xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI"
+ xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
+ xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
+ xmlns:views="clr-namespace:Tango.MachineStudio.UI.Views"
+ xmlns:fa="http://schemas.fontawesome.io/icons/"
+ xmlns:sharedControls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
+ xmlns:console="clr-namespace:Tango.MachineStudio.UI.Console"
+ xmlns:local="clr-namespace:Tango.MachineStudio.UI.Console"
+ mc:Ignorable="d"
+ Title="Developer Console" Height="800" Width="1280" BorderThickness="1" BorderBrush="#ADADAD" d:DataContext="{d:DesignInstance Type=console:ConsoleWindowVM, IsDesignTimeCreatable=False}" DataContext="{Binding ConsoleWindowVM, Source={StaticResource Locator}}" Foreground="Gainsboro">
+
+ <Window.Resources>
+ <ResourceDictionary>
+ <ResourceDictionary.MergedDictionaries>
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/FlatButton.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Styles.xaml" />
+ <ResourceDictionary>
+ <converters:StringEllipsisConverter x:Key="StringEllipsisConverter" />
+ </ResourceDictionary>
+ </ResourceDictionary.MergedDictionaries>
+ </ResourceDictionary>
+ </Window.Resources>
+
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition Height="742*"/>
+ </Grid.RowDefinitions>
+
+ <Menu IsMainMenu="True" BorderThickness="0">
+ <MenuItem Header="File">
+ <MenuItem Header="New" Command="{Binding NewCommand}">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="FileOutline" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <Separator/>
+ <MenuItem Header="Open" MinWidth="150" Command="{Binding OpenCommand}">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="FolderOutline" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <Separator/>
+ <MenuItem Header="Save" Command="{Binding SaveCommand}">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Save" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <MenuItem Header="Save as" Command="{Binding SaveAsCommand}">
+ <MenuItem.Icon>
+ <Grid>
+ <fa:ImageAwesome Icon="Save" Width="10" Foreground="Gainsboro" Margin="2" />
+ <fa:ImageAwesome Icon="Save" Width="10" Foreground="Gainsboro" Margin="2 -5 -5 2" />
+ </Grid>
+ </MenuItem.Icon>
+ </MenuItem>
+ </MenuItem>
+ <MenuItem Header="Edit">
+ <MenuItem Header="Cut" MinWidth="150" Command="Cut">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Cut" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <Separator/>
+ <MenuItem Header="Copy" Command="Copy">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Copy" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <MenuItem Header="Paste" Command="Paste">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Paste" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <Separator/>
+ <MenuItem Header="Undo" Command="Undo">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Undo" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <MenuItem Header="Redo" Command="Redo">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Repeat" Width="12" Foreground="Gainsboro" Margin="2" />
+ </MenuItem.Icon>
+ </MenuItem>
+ </MenuItem>
+ <MenuItem Header="Debug">
+ <MenuItem Header="Run (F5)" MinWidth="150" Command="{Binding RunCommand}" >
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Play" Width="12" Margin="2">
+ <fa:ImageAwesome.Style>
+ <Style TargetType="fa:ImageAwesome">
+ <Setter Property="Foreground" Value="#8DD28A"></Setter>
+ <Style.Triggers>
+ <Trigger Property="IsEnabled" Value="False">
+ <Setter Property="Foreground" Value="Gray"></Setter>
+ </Trigger>
+ </Style.Triggers>
+ </Style>
+ </fa:ImageAwesome.Style>
+ </fa:ImageAwesome>
+ </MenuItem.Icon>
+ </MenuItem>
+ <MenuItem Header="Stop" Command="{Binding StopCommand}" IsEnabled="False">
+ <MenuItem.Icon>
+ <fa:ImageAwesome Icon="Stop" Width="12" Margin="2">
+ <fa:ImageAwesome.Style>
+ <Style TargetType="fa:ImageAwesome">
+ <Setter Property="Foreground" Value="#F38B76"></Setter>
+ <Style.Triggers>
+ <Trigger Property="IsEnabled" Value="False">
+ <Setter Property="Foreground" Value="Gray"></Setter>
+ </Trigger>
+ </Style.Triggers>
+ </Style>
+ </fa:ImageAwesome.Style>
+ </fa:ImageAwesome>
+ </MenuItem.Icon>
+ </MenuItem>
+ </MenuItem>
+ </Menu>
+
+ <DockPanel Grid.Row="1">
+ <materialDesign:ColorZone Background="#2E2E2E" Padding="16" materialDesign:ShadowAssist.ShadowDepth="Depth2"
+ Mode="PrimaryMid" DockPanel.Dock="Top">
+ <DockPanel>
+ <Grid>
+ <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Height="60" HorizontalAlignment="Center">
+ <Image Source="/Images/machine-trans.png" RenderOptions.BitmapScalingMode="Fant"></Image>
+ <TextBlock Text="Machine Studio" VerticalAlignment="Center" Margin="20 0 0 0" FontSize="36"/>
+ </StackPanel>
+ </Grid>
+ </DockPanel>
+ </materialDesign:ColorZone>
+
+ <Grid>
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition Height="1*"/>
+ </Grid.RowDefinitions>
+
+ <Grid Grid.Row="1" x:Name="grid">
+ <Grid>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="467*"/>
+ <RowDefinition Height="5"/>
+ <RowDefinition Height="200*"/>
+ </Grid.RowDefinitions>
+
+ <controls:ScriptEditorControl BorderThickness="0 1 0 0" BorderBrush="#616161" 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" />
+
+
+ <Grid Grid.Row="2" Background="#1B1B1B">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="20"/>
+ <RowDefinition Height="57*"/>
+ </Grid.RowDefinitions>
+
+ <Border BorderThickness="0 0 0 1" BorderBrush="#595959">
+ <TextBlock Margin="2" HorizontalAlignment="Center">LOG</TextBlock>
+ </Border>
+
+ <TextBox x:Name="txtLog" TextChanged="TextBox_TextChanged" FontFamily="Lucida Console" Background="#202020" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro" Grid.Row="2"></TextBox>
+ </Grid>
+ </Grid>
+ </Grid>
+ </Grid>
+
+ <Border HorizontalAlignment="Right" Margin="0 -1 10 0" VerticalAlignment="Top" Width="300" Height="40" Padding="5" CornerRadius="0 0 30 30" BorderThickness="1 0 1 1" BorderBrush="DimGray">
+ <Border.Style>
+ <Style TargetType="Border">
+ <Setter Property="RenderTransform">
+ <Setter.Value>
+ <ScaleTransform ScaleX="1" ScaleY="0"></ScaleTransform>
+ </Setter.Value>
+ </Setter>
+ <Style.Triggers>
+ <DataTrigger Binding="{Binding NotificationProvider.HasTaskItems}" Value="True">
+ <DataTrigger.EnterActions>
+ <BeginStoryboard HandoffBehavior="Compose">
+ <Storyboard>
+ <DoubleAnimation Storyboard.TargetProperty="RenderTransform.ScaleY" FillBehavior="HoldEnd" To="1" Duration="00:00:0.2"></DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </DataTrigger.EnterActions>
+ <DataTrigger.ExitActions>
+ <BeginStoryboard HandoffBehavior="Compose">
+ <Storyboard>
+ <DoubleAnimation BeginTime="00:00:02" FillBehavior="HoldEnd" Storyboard.TargetProperty="RenderTransform.ScaleY" To="0" From="1" Duration="00:00:0.5"></DoubleAnimation>
+ </Storyboard>
+ </BeginStoryboard>
+ </DataTrigger.ExitActions>
+ </DataTrigger>
+ </Style.Triggers>
+ </Style>
+ </Border.Style>
+ <Border.Background>
+ <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
+ <GradientStop Color="#03A9F4"/>
+ <GradientStop Color="#0081BB" Offset="1"/>
+ </LinearGradientBrush>
+ </Border.Background>
+
+ <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="20 0 0 0">
+ <mahapps:ProgressRing Width="24" Height="24" Foreground="White"></mahapps:ProgressRing>
+ <TextBlock Text="{Binding NotificationProvider.CurrentTaskItem.Message,Converter={StaticResource StringEllipsisConverter},ConverterParameter=35}" Foreground="White" VerticalAlignment="Center" Margin="10 0 0 0" TextWrapping="Wrap"></TextBlock>
+ </StackPanel>
+ </Border>
+ </Grid>
+ </DockPanel>
+ </Grid>
+</mahapps:MetroWindow>
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
new file mode 100644
index 000000000..de2c728b0
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs
@@ -0,0 +1,43 @@
+using MahApps.Metro.Controls;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace Tango.MachineStudio.UI.Console
+{
+ /// <summary>
+ /// Interaction logic for ConsoleWindow.xaml
+ /// </summary>
+ public partial class ConsoleWindow : MetroWindow
+ {
+ private ConsoleWindowVM _vm;
+
+ public ConsoleWindow()
+ {
+ InitializeComponent();
+
+ this.Loaded += (_, __) =>
+ {
+ _vm = this.DataContext as ConsoleWindowVM;
+ _vm.SetLogTextBox(txtLog);
+ };
+ }
+
+ //Auto scroll to bottom of response log each time it is changed.
+ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ txtLog.SelectionStart = txtLog.Text.Length;
+ txtLog.ScrollToEnd();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs
new file mode 100644
index 000000000..a3a0a734e
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs
@@ -0,0 +1,257 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+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;
+ private TextBox _txtLog;
+ private String _currentFile;
+
+
+ /// <summary>
+ /// Gets or sets the additional highlight C# types.
+ /// </summary>
+ public ObservableCollection<KeyValuePair<String, Type>> HighlightTypes { get; set; }
+
+ internal void SetLogTextBox(TextBox txtLog)
+ {
+ _txtLog = txtLog;
+ }
+
+ /// <summary>
+ /// Gets or sets the intellisense types.
+ /// </summary>
+ public ObservableCollection<KeyValuePair<String, Type>> IntellisenseTypes { get; set; }
+
+ private String _code;
+ /// <summary>
+ /// Gets or sets the code.
+ /// </summary>
+ public String Code
+ {
+ get { return _code; }
+ set { _code = value; RaisePropertyChangedAuto(); }
+ }
+
+ private bool _isRunning;
+ /// <summary>
+ /// Gets or sets a value indicating whether a stub is currently running.
+ /// </summary>
+ public bool IsRunning
+ {
+ get { return _isRunning; }
+ set { _isRunning = value; RaisePropertyChanged(nameof(IsRunning)); InvalidateRelayCommands(); }
+ }
+
+ /// <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; }
+
+ /// <summary>
+ /// Gets or sets the new command.
+ /// </summary>
+ public RelayCommand NewCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the open command.
+ /// </summary>
+ public RelayCommand OpenCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the save command.
+ /// </summary>
+ public RelayCommand SaveCommand { get; set; }
+
+ /// <summary>
+ /// Gets or sets the save as command.
+ /// </summary>
+ public RelayCommand SaveAsCommand { 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");
+
+ NewCommand = new RelayCommand(CreateNew);
+ OpenCommand = new RelayCommand(OpenFile);
+ SaveCommand = new RelayCommand(SaveFile);
+ SaveAsCommand = new RelayCommand(SaveAsFile);
+ ClearCommand = new RelayCommand(ClearLog);
+ }
+
+ private void Stop()
+ {
+
+ }
+
+ private async void Run()
+ {
+ ScriptEngine engine = new ScriptEngine(new ConsoleOnExecuteParameters(new ConsoleManager(WriteLine)));
+ engine.Stop();
+ 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)
+ {
+ InvokeUI(() =>
+ {
+ _txtLog.AppendText(text);
+ });
+ }
+
+ /// <summary>
+ /// Clears the log.
+ /// </summary>
+ private void ClearLog()
+ {
+ _txtLog.Clear();
+ }
+
+ /// <summary>
+ /// Saves the selected script file.
+ /// </summary>
+ private void SaveFile()
+ {
+ if (_currentFile == null)
+ {
+ SaveAsFile();
+ }
+ else
+ {
+ File.WriteAllText(_currentFile, Code);
+ }
+ }
+
+ /// <summary>
+ /// Saves the selected script file.
+ /// </summary>
+ private void SaveAsFile()
+ {
+ SaveFileDialog dlg = new SaveFileDialog();
+ dlg.Filter = "C# Script Files|*.cs";
+ dlg.DefaultExt = ".cs";
+ if (dlg.ShowDialog().Value)
+ {
+ File.WriteAllText(dlg.FileName, Code);
+ _currentFile = dlg.FileName;
+ }
+ }
+
+ /// <summary>
+ /// Opens a script from HD.
+ /// </summary>
+ private void OpenFile()
+ {
+ OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Filter = "C# Script Files|*.cs";
+ if (dlg.ShowDialog().Value)
+ {
+ OpenFile(dlg.FileName);
+ }
+ }
+
+ /// <summary>
+ /// Opens the file.
+ /// </summary>
+ /// <param name="file">The file.</param>
+ private void OpenFile(String file)
+ {
+ Code = File.ReadAllText(file);
+ _currentFile = file;
+ }
+
+ private void CreateNew()
+ {
+ _txtLog.Clear();
+ _currentFile = null;
+ Code = String.Empty;
+ }
+ }
+}