diff options
34 files changed, 113 insertions, 2489 deletions
diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf Binary files differindex 3d183bcd4..aa316f3a2 100644 --- a/Software/DB/Tango.mdf +++ b/Software/DB/Tango.mdf diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf Binary files differindex e31a2abc0..fb24dd6b9 100644 --- a/Software/DB/Tango_log.ldf +++ b/Software/DB/Tango_log.ldf diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs index b1ffd9071..fb05a0b94 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Stubs/ViewModels/MainViewVM.cs @@ -30,34 +30,11 @@ namespace Tango.MachineStudio.Stubs.ViewModels public class MainViewVM : StudioViewModel<StubsModule> { private INotificationProvider _notification; - private StubsModuleSettings _settings; #region Properties public IStudioApplicationManager ApplicationManager { get; set; } - private bool _useConnectedMachine; - /// <summary> - /// Gets or sets a value indicating whether [use connected machine]. - /// </summary> - public bool UseConnectedMachine - { - get { return _useConnectedMachine; } - set - { - _useConnectedMachine = value; - - if (_useConnectedMachine && !ApplicationManager.IsMachineConnected) - { - _notification.ShowError("No connected machine found."); - _useConnectedMachine = false; - } - - RaisePropertyChangedAuto(); - InvalidateRelayCommands(); - } - } - private StubsViewVM _stubsViewVM; /// <summary> /// Gets or sets the stubs view vm. @@ -79,8 +56,6 @@ namespace Tango.MachineStudio.Stubs.ViewModels { StubsViewVM = new StubsViewVM(ConnectionMode.External); - _settings = SettingsManager.Default.GetOrCreate<StubsModuleSettings>(); - ApplicationManager = applicationManager; _notification = notification; diff --git a/Software/Visual_Studio/Tango.Settings/SettingsManager.cs b/Software/Visual_Studio/Tango.Settings/SettingsManager.cs index 34ac2ddfe..cd8b97c92 100644 --- a/Software/Visual_Studio/Tango.Settings/SettingsManager.cs +++ b/Software/Visual_Studio/Tango.Settings/SettingsManager.cs @@ -63,6 +63,11 @@ namespace Tango.Settings { TypeNameHandling = TypeNameHandling.All, Formatting = Formatting.Indented, + Error = (sender, args) => + { + args.ErrorContext.Handled = true; + Logging.LogManager.Default.Log(args.ErrorContext.Error.Message); + } }; _jsonSettings.Converters.Add(new StringEnumConverter(false)); diff --git a/Software/Visual_Studio/Tango.Stubs/ViewModels/StubsViewVM.cs b/Software/Visual_Studio/Tango.Stubs/ViewModels/StubsViewVM.cs index 64f5a2913..34052cb7a 100644 --- a/Software/Visual_Studio/Tango.Stubs/ViewModels/StubsViewVM.cs +++ b/Software/Visual_Studio/Tango.Stubs/ViewModels/StubsViewVM.cs @@ -249,11 +249,6 @@ namespace Tango.Stubs.ViewModels public RelayCommand<String> InsertSnippetCommand { get; set; } /// <summary> - /// Gets or sets the exit command. - /// </summary> - public RelayCommand ExitCommand { get; set; } - - /// <summary> /// Gets or sets the create item command. /// </summary> public RelayCommand<CreateItemVM> CreateItemCommand { get; set; } @@ -348,7 +343,6 @@ namespace Tango.Stubs.ViewModels SaveCommand = new RelayCommand(SaveFile); SaveAsCommand = new RelayCommand(SaveAsFile); StubSnippetSelectedCommand = new RelayCommand(OnStubSnippetSelected); - ExitCommand = new RelayCommand(() => Application.Current.Shutdown()); ClearCommand = new RelayCommand(ClearLog); Ports = new List<string>(); @@ -418,9 +412,6 @@ namespace Tango.Stubs.ViewModels } Examples = Examples.OrderBy(x => x.Name).ToList(); - - LogManager.RegisterLogger(new Logging.FileLogger() { Enabled = true }); - LogManager.Log("Application Started!"); } public StubsViewVM(ConnectionMode connectionMode) : this() @@ -615,7 +606,7 @@ namespace Tango.Stubs.ViewModels /// <summary> /// Toggles the USB adapter connection. /// </summary> - private void ToggleConnection() + private async void ToggleConnection() { try { @@ -623,18 +614,18 @@ namespace Tango.Stubs.ViewModels { _machineOperator = new MachineOperator(); _machineOperator.Adapter = new UsbTransportAdapter(SelectedPort, BaudRate); - _machineOperator.Connect().Wait(); + await _machineOperator.Connect(); IsConnected = true; } else { - _machineOperator.Disconnect().Wait(); IsConnected = false; + await _machineOperator.Disconnect(); } } catch (Exception ex) { - AppendTextLog(ex.Message); + AppendTextLog(ex.Message + Environment.NewLine); } } @@ -659,7 +650,7 @@ namespace Tango.Stubs.ViewModels if (MachineOperator == null || MachineOperator.State != TransportComponentState.Connected) { - AppendTextLog("Machine operator is not initialized or connected. Could not execute script."); + AppendTextLog("Machine operator is not initialized or connected. Could not execute script." + Environment.NewLine); return; } diff --git a/Software/Visual_Studio/Tango.Stubs/Views/StubsView.xaml b/Software/Visual_Studio/Tango.Stubs/Views/StubsView.xaml index c27109232..456a6718f 100644 --- a/Software/Visual_Studio/Tango.Stubs/Views/StubsView.xaml +++ b/Software/Visual_Studio/Tango.Stubs/Views/StubsView.xaml @@ -14,8 +14,8 @@ xmlns:transport="clr-namespace:Tango.Transport.Adapters;assembly=Tango.Transport" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1280" Background="#202020" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:StubsViewVM, IsDesignTimeCreatable=False}"> - - + + <UserControl.InputBindings> <KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}"/> @@ -176,12 +176,6 @@ </Grid> </MenuItem.Icon> </MenuItem> - <Separator/> - <MenuItem Header="Exit" Command="{Binding ExitCommand}"> - <MenuItem.Icon> - <fa:ImageAwesome Icon="SignOut" Width="12" Foreground="Gainsboro" Margin="2" /> - </MenuItem.Icon> - </MenuItem> </MenuItem> <MenuItem Header="Edit"> <MenuItem Header="Cut" MinWidth="150" Command="Cut"> @@ -318,83 +312,87 @@ </Grid> <Grid Grid.Column="1" Grid.RowSpan="3"> - <Grid VerticalAlignment="Bottom" Height="25" Background="#007ACC"> - - </Grid> - <DockPanel> - <GroupBox Header="COMMUNICATION PORT" VerticalAlignment="Top" DockPanel.Dock="Top" Margin="0 2 0 0" Visibility="{Binding DisplayConnectionPane,Converter={StaticResource BooleanToVisibilityConverter}}"> - <StackPanel> - <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Ports}" Height="35" SelectedItem="{Binding SelectedPort}"></ComboBox> - <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Source={StaticResource baudRates}}" Height="35" SelectedItem="{Binding BaudRate}" SelectedIndex="0"> - <ComboBox.ItemTemplate> - <DataTemplate> - <TextBlock Text="{Binding Path=.,Converter={StaticResource EnumToDescriptionConverter}}" /> - </DataTemplate> - </ComboBox.ItemTemplate> - </ComboBox> - </StackPanel> - </GroupBox> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="1*" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Grid Grid.Row="1" VerticalAlignment="Bottom" Height="25" Background="#007ACC"></Grid> + <DockPanel> + <GroupBox Header="COMMUNICATION PORT" VerticalAlignment="Top" DockPanel.Dock="Top" Margin="0 2 0 0" Visibility="{Binding DisplayConnectionPane,Converter={StaticResource BooleanToVisibilityConverter}}"> + <StackPanel> + <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Ports}" Height="35" SelectedItem="{Binding SelectedPort}"></ComboBox> + <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Source={StaticResource baudRates}}" Height="35" SelectedItem="{Binding BaudRate}" SelectedIndex="0"> + <ComboBox.ItemTemplate> + <DataTemplate> + <TextBlock Text="{Binding Path=.,Converter={StaticResource EnumToDescriptionConverter}}" /> + </DataTemplate> + </ComboBox.ItemTemplate> + </ComboBox> + </StackPanel> + </GroupBox> - <GroupBox Header="CONNECTION" DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="0 10 0 25" Visibility="{Binding DisplayConnectionPane,Converter={StaticResource BooleanToVisibilityConverter}}"> - <StackPanel> - <Button Height="50" MinWidth="100" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding ToggleConnectionCommand}"> - <Button.Style> - <Style TargetType="Button" BasedOn="{StaticResource AccentedSquareButtonStyle}"> - <Style.Triggers> - <DataTrigger Binding="{Binding IsConnected}" Value="False"> - <Setter Property="Content"> - <Setter.Value> - <StackPanel Orientation="Horizontal"> - <fa:ImageAwesome Icon="Link" Width="16"></fa:ImageAwesome> - <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">CONNECT</TextBlock> - </StackPanel> - </Setter.Value> - </Setter> - </DataTrigger> - <DataTrigger Binding="{Binding IsConnected}" Value="True"> - <Setter Property="Content"> - <Setter.Value> - <StackPanel Orientation="Horizontal"> - <fa:ImageAwesome Icon="Unlink" Width="16"></fa:ImageAwesome> - <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">DISCONNECT</TextBlock> - </StackPanel> - </Setter.Value> - </Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </Button.Style> - </Button> - </StackPanel> - </GroupBox> + <GroupBox Header="CONNECTION" DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="0 5 0 5" Visibility="{Binding DisplayConnectionPane,Converter={StaticResource BooleanToVisibilityConverter}}"> + <StackPanel> + <Button Height="50" MinWidth="100" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding ToggleConnectionCommand}"> + <Button.Style> + <Style TargetType="Button" BasedOn="{StaticResource AccentedSquareButtonStyle}"> + <Style.Triggers> + <DataTrigger Binding="{Binding IsConnected}" Value="False"> + <Setter Property="Content"> + <Setter.Value> + <StackPanel Orientation="Horizontal"> + <fa:ImageAwesome Icon="Link" Width="16"></fa:ImageAwesome> + <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">CONNECT</TextBlock> + </StackPanel> + </Setter.Value> + </Setter> + </DataTrigger> + <DataTrigger Binding="{Binding IsConnected}" Value="True"> + <Setter Property="Content"> + <Setter.Value> + <StackPanel Orientation="Horizontal"> + <fa:ImageAwesome Icon="Unlink" Width="16"></fa:ImageAwesome> + <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">DISCONNECT</TextBlock> + </StackPanel> + </Setter.Value> + </Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </Button.Style> + </Button> + </StackPanel> + </GroupBox> - <GroupBox Header="STUB SNIPPETS" Margin="0 10 0 30"> - <Grid> - <ListBox BorderThickness="0" ItemsSource="{Binding StubSnippets}" HorizontalContentAlignment="Stretch" SelectedItem="{Binding SelectedStubSnippet}"> - <ListBox.ItemContainerStyle> - <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}"> - <Setter Property="Padding" Value="0"></Setter> - <Setter Property="Margin" Value="0 2 0 2"></Setter> - <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> - </Style> - </ListBox.ItemContainerStyle> - <ListBox.ItemTemplate> - <DataTemplate> - <Border BorderThickness="1" BorderBrush="#007ACC" Padding="8" Background="Transparent"> - <Border.InputBindings> - <MouseBinding Gesture="LeftDoubleClick" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.StubSnippetSelectedCommand}"/> - </Border.InputBindings> - <Grid> - <fa:ImageAwesome Icon="ArrowLeft" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5 0 0 0" Foreground="#007ACC" Width="16" Height="16"></fa:ImageAwesome> - <TextBlock VerticalAlignment="Center" FontSize="11" HorizontalAlignment="Center" Text="{Binding Name}"></TextBlock> - </Grid> - </Border> - </DataTemplate> - </ListBox.ItemTemplate> - </ListBox> - </Grid> - </GroupBox> - </DockPanel> + <GroupBox Header="STUB SNIPPETS" Margin="0 10 0 0"> + <Grid> + <ListBox BorderThickness="0" ItemsSource="{Binding StubSnippets}" HorizontalContentAlignment="Stretch" SelectedItem="{Binding SelectedStubSnippet}"> + <ListBox.ItemContainerStyle> + <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}"> + <Setter Property="Padding" Value="0"></Setter> + <Setter Property="Margin" Value="0 2 0 2"></Setter> + <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> + </Style> + </ListBox.ItemContainerStyle> + <ListBox.ItemTemplate> + <DataTemplate> + <Border BorderThickness="1" BorderBrush="#007ACC" Padding="8" Background="Transparent"> + <Border.InputBindings> + <MouseBinding Gesture="LeftDoubleClick" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.StubSnippetSelectedCommand}"/> + </Border.InputBindings> + <Grid> + <fa:ImageAwesome Icon="ArrowLeft" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5 0 0 0" Foreground="#007ACC" Width="16" Height="16"></fa:ImageAwesome> + <TextBlock VerticalAlignment="Center" FontSize="11" HorizontalAlignment="Center" Text="{Binding Name}"></TextBlock> + </Grid> + </Border> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + </Grid> + </GroupBox> + </DockPanel> + </Grid> </Grid> <GridSplitter Margin="5 0 5 0" Grid.Row="1" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center"> diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.xaml b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.xaml index 68bec1795..93766373c 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.xaml +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/App.xaml @@ -19,11 +19,6 @@ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Styles.xaml" /> - - <!--View Models--> - <ResourceDictionary> - <vm:MainViewVM x:Key="MainViewVM" /> - </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/BasicRequest.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/BasicRequest.cs deleted file mode 100644 index b1a1902ef..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/BasicRequest.cs +++ /dev/null @@ -1,35 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - - // Request ---- - // Double : A - // Double : B - - // Response ---- - // Double : Sum - var response = stubManager.Run<CalculateResponse>("CalculateRequest", 10, 5); - - if (response.Sum == 15) - { - - stubManager.WriteLine("Sum is " + response.Sum); - - } - else - { - stubManager.WriteLine("Sum is incorrect!"); - } - -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/BasicRequestPolling.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/BasicRequestPolling.cs deleted file mode 100644 index feba9cbe3..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/BasicRequestPolling.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - int sum = 0; - int a = 0; - - while (sum < 100) - { - a = a + 1; - var response = stubManager.Run<CalculateResponse>("CalculateRequest", 0, a); - sum = response.Sum; - stubManager.WriteLine(sum); - } - - stubManager.WriteLine("Polling completed!"); - -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ContinuousResponse.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ContinuousResponse.cs deleted file mode 100644 index 86587abcc..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ContinuousResponse.cs +++ /dev/null @@ -1,25 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - - - // Request ---- - // Int32 : Amount - // Int32 : Delay - - // Response ---- - // Double : Progress - stubManager.RunContinuous<ProgressResponse>("ProgressRequest", null, 100, 1); //Put null in the callback and let our application log the response automatically.. - -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ContinuousResponseAdvanced.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ContinuousResponseAdvanced.cs deleted file mode 100644 index 3e744ba4b..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ContinuousResponseAdvanced.cs +++ /dev/null @@ -1,35 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - - // Request ---- - // Int32 : Amount - // Int32 : Delay - - // Response ---- - // Double : Progress - - - ProgressRequest request = new ProgressRequest(); - request.Amount = 100; - request.Delay = 1; - - stubManager.RunContinuous<ProgressResponse>(request, (response) => - { - - stubManager.WriteLine(response.Progress); - - }); - -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/InvokeResponseWindow.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/InvokeResponseWindow.cs deleted file mode 100644 index 3b702bd91..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/InvokeResponseWindow.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - String response = null; - - //Invoke the response window with default parameters. - response = stubManager.ShowResponseWindow(); - stubManager.WriteLine(response); - - //Invoke the response window with custom message. - response = stubManager.ShowResponseWindow("Please enter response:"); - stubManager.WriteLine(response); - - //Invoke the response window with custom message and default response. - response = stubManager.ShowResponseWindow("Please enter response:", "Default response"); - stubManager.WriteLine(response); -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ManualRequestInitialization.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ManualRequestInitialization.cs deleted file mode 100644 index 75e204a1d..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/ManualRequestInitialization.cs +++ /dev/null @@ -1,26 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - - - CalculateRequest calculateRequest = new CalculateRequest(); - calculateRequest.A = 10; - calculateRequest.B = 15; - - var response = stubManager.Run<CalculateResponse>(calculateRequest); - - stubManager.WriteLine("The response sum is: " + response.Sum); - - -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/RequestTimeout.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/RequestTimeout.cs deleted file mode 100644 index ca6fea674..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/RequestTimeout.cs +++ /dev/null @@ -1,19 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - - stubManager.RequestTimeout = 5000; //Set request timeout to 5 seconds. - - var response = stubManager.Run<CalculateResponse>("CalculateRequest", 10, 5); -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/Sleep.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/Sleep.cs deleted file mode 100644 index 9179e46ec..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/Sleep.cs +++ /dev/null @@ -1,30 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - int sum = 0; - int a = 0; - - while (sum < 100) - { - a = a + 1; - var response = stubManager.Run<CalculateResponse>("CalculateRequest", 0, a); - sum = response.Sum; - stubManager.WriteLine(sum); - - Thread.Sleep(10); //Sleep for 10 milli. - } - - stubManager.WriteLine("Polling completed!"); - -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/WriteToFile.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/WriteToFile.cs deleted file mode 100644 index 1d580fd5d..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Examples/WriteToFile.cs +++ /dev/null @@ -1,29 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -private const string FILE_PATH = "D:\\logFile.txt"; - -public void OnExecute(StubManager stubManager) -{ - //This will overwrite existing file. - stubManager.WriteToFile(FILE_PATH, "Writing to file..."); - - for (int i = 0; i < 10; i++) - { - //This will append the contents to the end of the file. - stubManager.AppendToFile(FILE_PATH, i.ToString() + " Some text..."); - } - - stubManager.AppendToFile(FILE_PATH, "Done"); - - stubManager.WriteLine("Done writing to the file."); -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/MainWindow.xaml index 4674e860e..61c79481e 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/MainWindow.xaml +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/MainWindow.xaml @@ -7,7 +7,7 @@ xmlns:views="clr-namespace:Tango.Stubs.UI.Views" xmlns:local="clr-namespace:Tango.Stubs.UI" mc:Ignorable="d" - Title="Tango Stubs Execution Utility" Height="720" Width="1280" TitlebarHeight="40" WindowState="Maximized" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" WindowStartupLocation="CenterScreen" Background="#202020" Foreground="Gainsboro" DataContext="{Binding RelativeSource={RelativeSource Self}}"> + Title="Tango Stubs Execution Utility" Height="720" Width="1280" TitlebarHeight="40" WindowState="Maximized" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" WindowStartupLocation="CenterScreen" Background="#202020" Foreground="Gainsboro"> <mahapps:MetroWindow.TitleTemplate> <DataTemplate> <TextBlock Foreground="Gray" Text="{Binding}" VerticalAlignment="Center"></TextBlock> @@ -20,6 +20,6 @@ </mahapps:MetroWindow.IconTemplate> <Grid> - <views:MainView DataContext="{StaticResource MainViewVM}"></views:MainView> + <views:MainView></views:MainView> </Grid> </mahapps:MetroWindow> diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.Designer.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.Designer.cs index 0f1dfb64d..0c9738076 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.Designer.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.Designer.cs @@ -59,29 +59,5 @@ namespace Tango.Stubs.UI.Properties { resourceCulture = value; } } - - /// <summary> - /// Looks up a localized string similar to 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; - /// - ///public void OnExecute(MediaManager mediaManager, Preset preset, CanvasScriptItem item) - ///{ - /// CanvasVideoItem canvasVideoItem = new CanvasVideoItem(); - /// canvasVideoItem.VideoFile = "C:\\video1.mp4"; - /// mediaManager.Invoke(() => mediaManager.Play(canvasVideoItem)); - /// Thread.Sl [rest of string was truncated]";. - /// </summary> - internal static string CodeTabTemplate { - get { - return ResourceManager.GetString("CodeTabTemplate", resourceCulture); - } - } } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.resx b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.resx index 7693cadac..1af7de150 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.resx +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Properties/Resources.resx @@ -117,8 +117,4 @@ <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> - <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> - <data name="CodeTabTemplate" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\CodeTabTemplate.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value> - </data> </root>
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs deleted file mode 100644 index bce014952..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs +++ /dev/null @@ -1,28 +0,0 @@ -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.PMR.Stubs; -using Tango.Stubs.UI; - -public void OnExecute(StubManager stubManager) -{ - for (int i = 0; i < 10; i++) - { - var response = stubManager.Run<CalculateResponse>("calculate", 1, i); - - if (response.Sum == 10) - { - stubManager.WriteLine("OK!"); - } - else - { - stubManager.WriteLine(response.Sum); - } - } -}
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs deleted file mode 100644 index 328318e93..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs +++ /dev/null @@ -1,481 +0,0 @@ -using Google.Protobuf; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using Tango.PMR; -using Tango.PMR.Common; -using Tango.Stubs.UI.Windows; -using Tango.Transport.Adapters; - -namespace Tango.Stubs.UI -{ - /// <summary> - /// Represents a manager capable of executing stub scripts asynchronously. - /// </summary> - public class StubManager - { - private UsbTransportAdapter _adapter; //Holds the USB transport adapter. - private Action<String> _writeLine; - private Action<String> _write; - private Action _clear; - - /// <summary> - /// Occurs when the stub has failed to execute. - /// </summary> - public event EventHandler<Exception> Failed; - - /// <summary> - /// Occurs when the stub has completed successfully. - /// </summary> - public event EventHandler<String> Completed; - - /// <summary> - /// Occurs when the stub has been initialized and executed. - /// </summary> - public event EventHandler<String> Executed; - - /// <summary> - /// Gets a value indicating whether this <see cref="StubManager"/> is aborted. - /// </summary> - internal bool Aborted { get; private set; } - - /// <summary> - /// Gets or sets a value indicating whether [automatic log]. - /// </summary> - public bool AutoLog { get; set; } - - /// <summary> - /// Gets or sets the request timeout. - /// </summary> - public int RequestTimeout { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="StubManager"/> class. - /// </summary> - /// <param name="adapter">The adapter.</param> - public StubManager(UsbTransportAdapter adapter, Action<String> writeLine, Action<String> write, Action clear) - { - _writeLine = writeLine; - _write = write; - _clear = clear; - - _adapter = adapter; - RequestTimeout = 2; - } - - /// <summary> - /// Aborts the current script. - /// </summary> - internal void Abort() - { - Aborted = true; - } - - /// <summary> - /// Runs the specified stub name. - /// </summary> - /// <param name="stubName">Name of the stub.</param> - /// <param name="args">The arguments.</param> - public IMessage Run(String stubName, params Object[] args) - { - if (Aborted) return null; - - var stubType = MessageFactory.GetAvailableRequestStubs().SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower()); - if (stubType == null) - { - OnFailed(new ArgumentException("Invalid stub '" + stubName + "'.")); - return null; - } - - var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance); - - if (stubProps.Length > args.Length) - { - OnFailed(new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + ".")); - return null; - } - - Executed?.Invoke(this, stubType.Name); - - try - { - Object request = Activator.CreateInstance(stubType); - - int argIndex = 0; - foreach (var prop in stubProps) - { - Object arg = args[argIndex++]; - - if (prop.PropertyType == typeof(UInt32)) - { - prop.SetValue(request, UInt32.Parse(arg.ToString())); - } - else if (prop.PropertyType == typeof(bool)) - { - prop.SetValue(request, bool.Parse(arg.ToString())); - } - else if (prop.PropertyType.IsPrimitive) - { - object converted = Convert.ChangeType(arg, prop.PropertyType); - prop.SetValue(request, converted); - } - else - { - prop.SetValue(request, arg); - } - } - - return Run(request as IMessage); - } - catch (Exception ex) - { - OnFailed(ex); - } - - return null; - } - - /// <summary> - /// Runs the specified stub name. - /// </summary> - /// <param name="stubName">Name of the stub.</param> - /// <param name="args">The arguments.</param> - public IMessage Run(IMessage stub) - { - if (Aborted) return null; - - Executed?.Invoke(this, stub.GetType().Name); - - EventHandler<byte[]> handler = null; - - try - { - MessageContainer container = new MessageContainer(); - container.Token = Guid.NewGuid().ToString(); - container.Type = MessageFactory.ParseMessageType(stub.GetType().Name); - - container.Data = (stub as IMessage).ToByteString(); - - byte[] requestData = container.ToByteArray(); - - bool done = false; - - IMessage message = null; - - Task.Factory.StartNew(() => - { - _adapter.Write(requestData); - - DateTime startTime = DateTime.Now; - - MessageContainer responseContainer = null; - - handler = new EventHandler<byte[]>((sender, data) => - { - responseContainer = MessageFactory.ParseContainer(data); - }); - - _adapter.DataAvailable += handler; - - while (responseContainer == null) - { - Thread.Sleep(2); - - if (DateTime.Now > startTime.AddSeconds(RequestTimeout)) - { - done = true; - OnFailed(new TimeoutException(String.Format("Response has failed to arrive after {0} seconds.", TimeSpan.FromMilliseconds(RequestTimeout).TotalSeconds))); - return; - } - - if (Aborted) - { - done = true; - return; - } - } - - message = MessageFactory.ExtractMessageFromContainer(responseContainer); - OnCompleted(JsonConvert.SerializeObject(message, Formatting.Indented)); - done = true; - }); - - while (!done) - { - Thread.Sleep(2); - } - - if (handler != null) - { - _adapter.DataAvailable -= handler; - } - - return message; - } - catch (Exception ex) - { - if (handler != null) - { - _adapter.DataAvailable -= handler; - } - - OnFailed(ex); - } - - return null; - } - - public T Run<T>(String stubName, params Object[] args) where T : class, IMessage - { - return Run(stubName, args) as T; - } - - public T Run<T>(IMessage stub) where T : class, IMessage - { - return Run(stub) as T; - } - - /// <summary> - /// Runs the specified stub name. - /// </summary> - /// <param name="stubName">Name of the stub.</param> - /// <param name="args">The arguments.</param> - public void RunContinuous<T>(IMessage stub, Action<T> callback) where T : class, IMessage - { - if (Aborted) return; - - Type stubType = stub.GetType(); - - Executed?.Invoke(this, stubType.Name); - - EventHandler<byte[]> handler = null; - - try - { - MessageContainer container = new MessageContainer(); - container.Token = Guid.NewGuid().ToString(); - container.Continuous = true; - container.Type = MessageFactory.ParseMessageType(stubType.Name); - - container.Data = (stub as IMessage).ToByteString(); - - byte[] requestData = container.ToByteArray(); - - bool done = false; - - IMessage message = null; - - Task.Factory.StartNew(() => - { - _adapter.Write(requestData); - - DateTime startTime = DateTime.Now; - - MessageContainer responseContainer = null; - - handler = new EventHandler<byte[]>((sender, data) => - { - responseContainer = MessageFactory.ParseContainer(data); - message = MessageFactory.ExtractMessageFromContainer(responseContainer); - - callback?.Invoke(message as T); - - if (AutoLog) - { - WriteLine(JsonConvert.SerializeObject(message, Formatting.Indented)); - } - - if (responseContainer.Completed || Aborted) - { - _adapter.DataAvailable -= handler; - done = true; - return; - } - }); - - _adapter.DataAvailable += handler; - }); - - while (!done) - { - Thread.Sleep(2); - } - - OnCompleted("Continuous request completed."); - - if (handler != null) - { - _adapter.DataAvailable -= handler; - } - - return; - } - catch (Exception ex) - { - if (handler != null) - { - _adapter.DataAvailable -= handler; - } - - OnFailed(ex); - } - - return; - } - - /// - /// <summary> - /// Runs the specified stub name. - /// </summary> - /// <param name="stubName">Name of the stub.</param> - /// <param name="args">The arguments.</param> - public void RunContinuous<T>(String stubName, Action<T> callback, params Object[] args) where T : class, IMessage - { - if (Aborted) return; - - var stubType = MessageFactory.GetAvailableRequestStubs().SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower()); - if (stubType == null) - { - OnFailed(new ArgumentException("Invalid stub '" + stubName + "'.")); - return; - } - - var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance); - - if (stubProps.Length > args.Length) - { - OnFailed(new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + ".")); - return; - } - - try - { - Object request = Activator.CreateInstance(stubType); - - int argIndex = 0; - foreach (var prop in stubProps) - { - Object arg = args[argIndex++]; - - if (prop.PropertyType == typeof(UInt32)) - { - prop.SetValue(request, UInt32.Parse(arg.ToString())); - } - else if (prop.PropertyType == typeof(bool)) - { - prop.SetValue(request, bool.Parse(arg.ToString())); - } - else if (prop.PropertyType.IsPrimitive) - { - object converted = Convert.ChangeType(arg, prop.PropertyType); - prop.SetValue(request, converted); - } - else - { - prop.SetValue(request, arg); - } - } - - RunContinuous<T>(request as IMessage, callback); - } - catch (Exception ex) - { - OnFailed(ex); - } - } - - public void WriteLine(Object obj) - { - _writeLine(obj != null ? obj.ToString() : "null"); - } - - public void Write(Object obj) - { - _write(obj != null ? obj.ToString() : "null"); - } - - public void WriteLineHex(Object number, int digits) - { - _writeLine("#" + Convert.ToInt32(number).ToString("X" + digits.ToString())); - } - - public void WriteHex(Object number, int digits) - { - _write("#" + Convert.ToInt32(number).ToString("X" + digits.ToString())); - } - - public void Clear() - { - _clear(); - } - - public String ShowResponseWindow(String message, String defaultResponse) - { - String response = null; - bool closed = false; - - Application.Current.Dispatcher.Invoke(() => - { - TextInputWindow dlg = new TextInputWindow(message, defaultResponse); - dlg.WindowStartupLocation = WindowStartupLocation.CenterOwner; - dlg.Owner = Application.Current.MainWindow; - dlg.ShowDialog(); - response = dlg.Response; - closed = true; - }); - - while (!closed) - { - Thread.Sleep(10); - } - - return response; - } - - public String ShowResponseWindow(String message) - { - return ShowResponseWindow(message, null); - } - - public String ShowResponseWindow() - { - return ShowResponseWindow(null); - } - - public void WriteToFile(String filePath, String content) - { - File.WriteAllText(filePath, content + Environment.NewLine); - } - - public void AppendToFile(String filePath, String content) - { - File.AppendAllText(filePath, content + Environment.NewLine); - } - - /// <summary> - /// Raises the <see cref="Failed"/> event. - /// </summary> - /// <param name="ex">The exception.</param> - protected virtual void OnFailed(Exception ex) - { - Failed?.Invoke(this, ex); - } - - /// <summary> - /// Raises the <see cref="Completed"/> event. - /// </summary> - /// <param name="response">The response.</param> - protected virtual void OnCompleted(String response) - { - Completed?.Invoke(this, response); - } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubOnExecuteParameters.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubOnExecuteParameters.cs deleted file mode 100644 index 14b69a0b7..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubOnExecuteParameters.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Scripting; - -namespace Tango.Stubs.UI -{ - /// <summary> - /// Represents the global object which will be sent to the scripting engine. - /// </summary> - /// <seealso cref="Tango.Scripting.OnExecuteParameters" /> - public class StubOnExecuteParameters : OnExecuteParameters - { - /// <summary> - /// Provides access to the script stub manager. - /// </summary> - public StubManager stubManager; - - /// <summary> - /// Initializes a new instance of the <see cref="StubOnExecuteParameters"/> class. - /// </summary> - /// <param name="manager">The manager.</param> - public StubOnExecuteParameters(StubManager manager) - { - stubManager = manager; - } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubsUISettings.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubsUISettings.cs deleted file mode 100644 index 62d77a012..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubsUISettings.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Settings; -using Tango.Transport.Adapters; - -namespace Tango.Stubs.UI -{ - public class StubsUISettings : SettingsBase - { - /// <summary> - /// Gets or sets the selected port. - /// </summary> - public String SelectedPort { get; set; } - - /// <summary> - /// Gets or sets the baud rate. - /// </summary> - public UsbSerialBaudRates BaudRate { get; set; } - - /// <summary> - /// Gets or sets the last tabs. - /// </summary> - public List<String> LastTabs { get; set; } - - /// <summary> - /// Gets or sets a value indicating whether [automatic log response]. - /// </summary> - public bool AutoLogResponse { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="StubsUI"/> class. - /// </summary> - public StubsUISettings() - { - BaudRate = UsbSerialBaudRates.BR_9600; - LastTabs = new List<string>(); - } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj index 5867800db..de5ba2c69 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Tango.Stubs.UI.csproj @@ -78,27 +78,7 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </ApplicationDefinition> - <EmbeddedResource Include="Examples\InvokeResponseWindow.cs" /> - <EmbeddedResource Include="Examples\WriteToFile.cs" /> - <Compile Include="Windows\TextInputWindow.xaml.cs"> - <DependentUpon>TextInputWindow.xaml</DependentUpon> - </Compile> - <None Include="Resources\CodeTabTemplate.cs" /> - <EmbeddedResource Include="Examples\BasicRequestPolling.cs" /> - <EmbeddedResource Include="Examples\ManualRequestInitialization.cs" /> - <EmbeddedResource Include="Examples\Sleep.cs" /> - <EmbeddedResource Include="Examples\ContinuousResponse.cs" /> - <EmbeddedResource Include="Examples\ContinuousResponseAdvanced.cs" /> - <EmbeddedResource Include="Examples\RequestTimeout.cs" /> - <Compile Include="StubManager.cs" /> - <Compile Include="StubOnExecuteParameters.cs" /> - <Compile Include="StubsUISettings.cs" /> - <Compile Include="ViewModels\CodeTabVM.cs" /> - <Compile Include="ViewModels\CreateGroupVM.cs" /> - <Compile Include="ViewModels\CreateItemVM.cs" /> - <Compile Include="ViewModels\ExampleVM.cs" /> <Compile Include="ViewModels\MainViewVM.cs" /> - <Compile Include="ViewModels\StubSnippetVM.cs" /> <Compile Include="Views\MainView.xaml.cs"> <DependentUpon>MainView.xaml</DependentUpon> </Compile> @@ -118,10 +98,6 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> - <Page Include="Windows\TextInputWindow.xaml"> - <SubType>Designer</SubType> - <Generator>MSBuild:Compile</Generator> - </Page> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs"> @@ -195,9 +171,6 @@ <ItemGroup> <None Include="FodyWeavers.xml" /> </ItemGroup> - <ItemGroup> - <EmbeddedResource Include="Examples\BasicRequest.cs" /> - </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PostBuildEvent>if $(ConfigurationName) == Debug $(TargetDir)linkgen.exe -s "$(TargetPath)" -d "$(TargetDir)Utilities\Stubs Execution GUI.lnk"</PostBuildEvent> diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CodeTabVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CodeTabVM.cs deleted file mode 100644 index a56ad7aca..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CodeTabVM.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core.Commands; -using Tango.Scripting; -using Tango.SharedUI; - -namespace Tango.Stubs.UI.ViewModels -{ - /// <summary> - /// Represents a single script editor tab view model; - /// </summary> - /// <seealso cref="Tango.SharedUI.ViewModel" /> - public class CodeTabVM : ViewModel - { - private String _title; - /// <summary> - /// Gets or sets the script title/file name. - /// </summary> - public String Title - { - get - { - return File != null ? Path.GetFileName(File) : _title; - } - set - { - _title = value; - RaisePropertyChanged(nameof(Title)); - } - } - - private String _file; - /// <summary> - /// Gets or sets the full script file path. - /// </summary> - public String File - { - get { return _file; } - set - { - _file = value; - RaisePropertyChanged(nameof(File)); - RaisePropertyChanged(nameof(Title)); - } - } - - private String _code; - /// <summary> - /// Gets or sets the script code. - /// </summary> - public String Code - { - get { return _code; } - set { _code = value; RaisePropertyChanged(nameof(Code)); } - } - - private bool _isRunning; - /// <summary> - /// Gets or sets a value indicating whether this instance is running. - /// </summary> - public bool IsRunning - { - get { return _isRunning; } - set { _isRunning = value; RaisePropertyChangedAuto(); } - } - - private RelayCommand _insertCodeSnippetCommand; - /// <summary> - /// Gets or sets the insert snippet command. (Inserts stub snippet to editor) - /// </summary> - public RelayCommand InsertSnippetCommand - { - get { return _insertCodeSnippetCommand; } - set { _insertCodeSnippetCommand = value; RaisePropertyChanged(nameof(InsertSnippetCommand)); } - } - - private ObservableCollection<CompilerError> _errors; - /// <summary> - /// Gets or sets the errors. - /// </summary> - public ObservableCollection<CompilerError> Errors - { - get { return _errors; } - set { _errors = value; RaisePropertyChangedAuto(); } - } - - /// <summary> - /// Initializes a new instance of the <see cref="CodeTabVM"/> class. - /// </summary> - public CodeTabVM() - { - Title = "untitled"; - Code = Properties.Resources.CodeTabTemplate; - Errors = new ObservableCollection<CompilerError>(); - } - - /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. - /// </summary> - /// <returns> - /// A <see cref="System.String" /> that represents this instance. - /// </returns> - public override string ToString() - { - return Title; - } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CreateGroupVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CreateGroupVM.cs deleted file mode 100644 index c2ed051db..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CreateGroupVM.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; - -namespace Tango.Stubs.UI.ViewModels -{ - public class CreateGroupVM : ExtendedObject - { - public String Name { get; set; } - - public List<CreateItemVM> Items { get; set; } - - public CreateGroupVM() - { - Items = new List<CreateItemVM>(); - } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CreateItemVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CreateItemVM.cs deleted file mode 100644 index be96edee8..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/CreateItemVM.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.Core; - -namespace Tango.Stubs.UI.ViewModels -{ - public class CreateItemVM : ExtendedObject - { - public Type Type { get; set; } - - public String Name { get; set; } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/ExampleVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/ExampleVM.cs deleted file mode 100644 index b98c9cd12..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/ExampleVM.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.Stubs.UI.ViewModels -{ - public class ExampleVM - { - public String Name { get; set; } - - public String Code { get; set; } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs index e5e053b36..4027af171 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs @@ -20,6 +20,7 @@ using Tango.Scripting; using Tango.Settings; using Tango.SharedUI; using Tango.Stubs.UI.Views; +using Tango.Stubs.ViewModels; using Tango.Transport.Adapters; namespace Tango.Stubs.UI.ViewModels @@ -30,770 +31,30 @@ namespace Tango.Stubs.UI.ViewModels /// <seealso cref="Tango.SharedUI.ViewModel" /> public class MainViewVM : ViewModel { - private UsbTransportAdapter _adapter; //Holds the USB transport adapter. - private StubManager _stubManager; - private TextBox _logTextBox; - private StubsUISettings _settings; - - #region Properties - - public List<CreateGroupVM> CreateGroups { get; set; } - - public List<ExampleVM> Examples { get; set; } - - /// <summary> - /// Gets or sets the code tabs. - /// </summary> - public ObservableCollection<CodeTabVM> CodeTabs { get; set; } - - /// <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; } - - /// <summary> - /// Gets or sets the collection of stub snippets. - /// </summary> - public ObservableCollection<StubSnippetVM> StubSnippets { get; set; } - - private StubSnippetVM _selectedStubSnippet; - /// <summary> - /// Gets or sets the selected stub snippet. - /// </summary> - public StubSnippetVM SelectedStubSnippet - { - get { return _selectedStubSnippet; } - set { _selectedStubSnippet = value; RaisePropertyChanged(nameof(SelectedStubSnippet)); } - } - - private CodeTabVM _selectedCodeTab; - /// <summary> - /// Gets or sets the selected code tab. - /// </summary> - public CodeTabVM SelectedCodeTab - { - get { return _selectedCodeTab; } - set { _selectedCodeTab = value; RaisePropertyChanged(nameof(SelectedCodeTab)); InvalidateRelayCommands(); } - } - - private bool _isConnected; - /// <summary> - /// Gets or sets a value indicating whether the USB adapter is connected. - /// </summary> - public bool IsConnected - { - get { return _isConnected; } - set { _isConnected = value; RaisePropertyChanged(nameof(IsConnected)); InvalidateRelayCommands(); } - } - - private List<String> _ports; - /// <summary> - /// Gets or sets the available USB ports. - /// </summary> - public List<String> Ports - { - get { return _ports; } - set { _ports = value; RaisePropertyChanged(nameof(Ports)); } - } - - private String _selectedPort; - /// <summary> - /// Gets or sets the selected USB port. - /// </summary> - public String SelectedPort - { - get { return _selectedPort; } - set { _selectedPort = value; RaisePropertyChanged(nameof(SelectedPort)); InvalidateRelayCommands(); } - } - - private String _status; - /// <summary> - /// Gets or sets the current status bar text. - /// </summary> - public String Status - { - get { return _status; } - set { _status = value; RaisePropertyChanged(nameof(Status)); } - } - - 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(); } - } - - private bool _appendLogAuto; - - public bool AppendLogAuto - { - get { return _appendLogAuto; } - set { _appendLogAuto = value; RaisePropertyChangedAuto(); } - } - - private UsbSerialBaudRates _baudRate; + private StubsViewVM _stubsViewVM; /// <summary> - /// Gets or sets the baud rate. + /// Gets or sets the stubs view vm. /// </summary> - public UsbSerialBaudRates BaudRate + public StubsViewVM StubsViewVM { - get { return _baudRate; } - set { _baudRate = value; RaisePropertyChangedAuto(); } + get { return _stubsViewVM; } + set { _stubsViewVM = value; RaisePropertyChangedAuto(); } } - #endregion - - #region Commands - - /// <summary> - /// Gets or sets the new command. - /// </summary> - public RelayCommand NewCommand { get; set; } - - /// <summary> - /// Gets or sets the close tab command. - /// </summary> - public RelayCommand<CodeTabVM> CloseTabCommand { get; set; } - - /// <summary> - /// Gets or sets the build command. - /// </summary> - public RelayCommand BuildCommand { get; set; } - - /// <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 toggle connection command. - /// </summary> - public RelayCommand ToggleConnectionCommand { 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; } - - /// <summary> - /// Gets or sets the clear command. - /// </summary> - public RelayCommand ClearCommand { get; set; } - - /// <summary> - /// Gets or sets the stub snippet selected command. - /// </summary> - public RelayCommand StubSnippetSelectedCommand { get; set; } - - /// <summary> - /// Gets or sets the insert snippet command. - /// </summary> - public RelayCommand<String> InsertSnippetCommand { get; set; } - - /// <summary> - /// Gets or sets the exit command. - /// </summary> - public RelayCommand ExitCommand { get; set; } - - /// <summary> - /// Gets or sets the create item command. - /// </summary> - public RelayCommand<CreateItemVM> CreateItemCommand { get; set; } - - /// <summary> - /// Gets or sets the create example command. - /// </summary> - public RelayCommand<ExampleVM> CreateExampleCommand { get; set; } - #endregion - - #region Constructors - /// <summary> /// Initializes a new instance of the <see cref="MainViewVM"/> class. /// </summary> public MainViewVM() { - _settings = SettingsManager.Default.GetOrCreate<StubsUISettings>(); - - Examples = new List<ExampleVM>(); - CodeTabs = new ObservableCollection<CodeTabVM>(); - NewCommand = new RelayCommand(CreateNewTab); - CloseTabCommand = new RelayCommand<CodeTabVM>(OnTabClosing); - RunCommand = new RelayCommand(RunTab, (x) => IsConnected && !IsRunning && SelectedCodeTab != null); - BuildCommand = new RelayCommand(async () => await BuildTab(), (x) => !IsRunning && SelectedCodeTab != null); - StopCommand = new RelayCommand(StopTab, (x) => IsConnected && IsRunning && SelectedCodeTab != null); - InsertSnippetCommand = new RelayCommand<string>((x) => { }); - CreateExampleCommand = new RelayCommand<ExampleVM>(CreateExample); - - HighlightTypes = new ObservableCollection<KeyValuePair<string, Type>>(); - IntellisenseTypes = new ObservableCollection<KeyValuePair<string, Type>>(); - - IntellisenseTypes.Add(new KeyValuePair<string, Type>("stubManager", typeof(StubManager))); - - foreach (var stubType in typeof(PMR.Common.MessageContainer).Assembly.GetTypes().Where(x => typeof(IMessage).IsAssignableFrom(x))) - { - HighlightTypes.Add(new KeyValuePair<string, Type>(stubType.Name, stubType)); - } - - 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); - } - - StubSnippets = new ObservableCollection<StubSnippetVM>(); - - foreach (var stubType in MessageFactory.GetAvailableRequestStubs()) - { - StubSnippetVM snippet = new StubSnippetVM(); - snippet.Name = stubType.Name.Replace("Stub", "").Replace("Request", "").ToWords(); - - snippet.Code = String.Empty; - - snippet.Code += "// " + "Request ----" + Environment.NewLine; - - foreach (var prop in stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) - { - snippet.Code += "// " + prop.PropertyType.Name + " : " + prop.Name + Environment.NewLine; - } - - Type responseType = MessageFactory.GetAvailableRequestResponseStubs().SingleOrDefault(x => x.Name == stubType.Name.Replace("Request", "Response")); - - if (responseType != null) - { - snippet.Code += Environment.NewLine + "// " + "Response ----" + Environment.NewLine; - - foreach (var prop in responseType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) - { - snippet.Code += "// " + prop.PropertyType.Name + " : " + prop.Name + Environment.NewLine; - } - } - - snippet.Code += String.Format("var response = stubManager.Run<{2}>(\"{0}\" ,{1});", stubType.Name, String.Join(", ", stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(x => x.PropertyType.Name == "string" ? "\"string\"" : x.PropertyType.Name)), stubType.Name.Replace("Request", "Response")); - StubSnippets.Add(snippet); - } - - ToggleConnectionCommand = new RelayCommand(ToggleConnection, (x) => !IsRunning); - OpenCommand = new RelayCommand(OpenFile); - SaveCommand = new RelayCommand(SaveFile); - SaveAsCommand = new RelayCommand(SaveAsFile); - StubSnippetSelectedCommand = new RelayCommand(OnStubSnippetSelected); - ExitCommand = new RelayCommand(() => Application.Current.Shutdown()); - ClearCommand = new RelayCommand(ClearLog); - - Ports = new List<string>(); - - for (int i = 1; i < 100; i++) - { - Ports.Add("COM" + i); - } - - SelectedPort = _settings.SelectedPort != null ? _settings.SelectedPort : Ports.First(); - BaudRate = _settings.BaudRate; - AppendLogAuto = _settings.AutoLogResponse; - - Status = "Ready"; - - if (_settings.LastTabs.Count > 0) - { - foreach (var file in _settings.LastTabs) - { - if (File.Exists(file)) - { - OpenFile(file); - } - } - } - else - { - CreateNewTab(); - } - - CreateGroups = new List<CreateGroupVM>(); - - foreach (var typesGroup in typeof(PMR.Common.MessageContainer).Assembly.GetTypes().Where(x => x.IsClass && !x.IsGenericType && !x.Name.Contains("Reflection") && typeof(IMessage).IsAssignableFrom(x)).GroupBy(x => x.Namespace)) - { - CreateGroupVM group = new CreateGroupVM(); - group.Name = typesGroup.First().Namespace.Split('.').Last(); - - foreach (var type in typesGroup) - { - group.Items.Add(new CreateItemVM() - { - Name = type.Name, - Type = type, - }); - } - - CreateGroups.Add(group); - } - - CreateItemCommand = new RelayCommand<CreateItemVM>(CreateItem); - - foreach (var name in typeof(MainViewVM).Assembly.GetManifestResourceNames()) - { - if (name.Contains(".Examples.")) - { - using (Stream stream = typeof(MainViewVM).Assembly.GetManifestResourceStream(name)) - { - StreamReader reader = new StreamReader(stream); - - ExampleVM example = new ExampleVM(); - String[] str = name.Split('.'); - example.Name = str[str.Length - 2].ToWords(); - example.Code = reader.ReadToEnd(); - Examples.Add(example); - } - } - } - - Examples = Examples.OrderBy(x => x.Name).ToList(); - - Application.Current.Exit += Current_Exit; - LogManager.RegisterLogger(new Logging.FileLogger() { Enabled = true }); - LogManager.Log("Application Started!"); - } - - #endregion - - #region Virtual Methods - - /// <summary> - /// Called when a stub snippet is double clicked. - /// </summary> - protected virtual void OnStubSnippetSelected() - { - if (SelectedStubSnippet != null) - { - if (InsertSnippetCommand != null) - { - InsertSnippetCommand.Execute(SelectedStubSnippet.Code); - } - } - } - - /// <summary> - /// Called when user closes a script tab. - /// </summary> - /// <param name="codeTab">The code tab.</param> - protected virtual void OnTabClosing(CodeTabVM codeTab) - { - CodeTabs.Remove(codeTab); - } - - #endregion - - #region Private Methods - - private void CreateExample(ExampleVM example) - { - CreateNewTab(); - SelectedCodeTab.Code = example.Code; - SelectedCodeTab.Title = example.Name; - } - - private void CreateItem(CreateItemVM item) - { - if (item != null) - { - if (InsertSnippetCommand != null) - { - String code = String.Empty; - - FormatProperties(item.Type, ref code); - - InsertSnippetCommand.Execute(code); - } - } - } - - private void FormatProperties(Type type, ref String code) - { - code += Environment.NewLine + String.Format("{0} {1} = new {0}();", type.Name, type.Name.ToCamelCase()) + Environment.NewLine; - - foreach (var prop in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) - { - if (prop.PropertyType == typeof(String)) - { - code += String.Format("{0}.{1} = {2};", type.Name.ToCamelCase(), prop.Name, "null") + Environment.NewLine; - } - else if (prop.PropertyType.IsEnum) - { - code += String.Format("{0}.{1} = {2};", type.Name.ToCamelCase(), prop.Name, Activator.CreateInstance(prop.PropertyType).GetType().FullName + "." + Activator.CreateInstance(prop.PropertyType).ToString()) + Environment.NewLine; - } - else if (!prop.PropertyType.IsClass) - { - code += String.Format("{0}.{1} = {2};", type.Name.ToCamelCase(), prop.Name, Activator.CreateInstance(prop.PropertyType).ToString().ToLower()) + Environment.NewLine; - } - else if (prop.PropertyType.IsGenericType) - { - Type genericType = prop.PropertyType.GenericTypeArguments[0]; - FormatProperties(genericType, ref code); - code += String.Format("{0}.{1}.Add({2});", type.Name.ToCamelCase(), prop.Name, genericType.Name.ToCamelCase()) + Environment.NewLine; - } - else - { - FormatProperties(prop.PropertyType, ref code); - code += Environment.NewLine + String.Format("{0}.{1} = {2};", type.Name.ToCamelCase(), prop.Name, prop.Name.ToCamelCase()) + Environment.NewLine; - } - } - } - - /// <summary> - /// Clears the log. - /// </summary> - private void ClearLog() - { - _logTextBox.Clear(); - } - - /// <summary> - /// Saves the selected script file. - /// </summary> - private async void SaveFile() - { - if (SelectedCodeTab != null) - { - if (SelectedCodeTab.File == null) - { - SaveAsFile(); - } - else - { - Status = "Saving " + SelectedCodeTab.File + "..."; - File.WriteAllText(SelectedCodeTab.File, SelectedCodeTab.Code); - await Task.Delay(1000); - Status = "Ready"; - } - } - } - - /// <summary> - /// Saves the selected script file. - /// </summary> - private async void SaveAsFile() - { - if (SelectedCodeTab != null) - { - SaveFileDialog dlg = new SaveFileDialog(); - dlg.Filter = "C# Script Files|*.cs"; - dlg.DefaultExt = ".cs"; - if (dlg.ShowDialog().Value) - { - Status = "Saving " + dlg.FileName + "..."; - File.WriteAllText(dlg.FileName, SelectedCodeTab.Code); - SelectedCodeTab.File = dlg.FileName; - await Task.Delay(1000); - Status = "Ready"; - } - } - } - - /// <summary> - /// Opens a script from HD. - /// </summary> - private void OpenFile() - { - OpenFileDialog dlg = new OpenFileDialog(); - dlg.Filter = "C# Script Files|*.cs"; - dlg.Multiselect = true; - if (dlg.ShowDialog().Value) - { - foreach (var file in dlg.FileNames) - { - OpenFile(file); - } - } - } - - /// <summary> - /// Opens the file. - /// </summary> - /// <param name="file">The file.</param> - private void OpenFile(String file) - { - var newTab = new CodeTabVM(); - newTab.File = file; - newTab.Code = File.ReadAllText(file); - CodeTabs.Add(newTab); - SelectedCodeTab = newTab; - } - - /// <summary> - /// Toggles the USB adapter connection. - /// </summary> - private void ToggleConnection() - { - try - { - if (!IsConnected) - { - _adapter = new UsbTransportAdapter(SelectedPort); - _adapter.BaudRate = BaudRate; - _adapter.Connect().Wait(); - IsConnected = true; - } - else - { - _adapter.Disconnect().Wait(); - IsConnected = false; - } - } - catch (Exception ex) - { - MessageBox.Show(ex.ToString(), "Tango"); - } - } + StubsViewVM = new StubsViewVM(ConnectionMode.Internal); - /// <summary> - /// Creates a new script tab. - /// </summary> - private void CreateNewTab() - { - var newTab = new CodeTabVM(); - CodeTabs.Add(newTab); - SelectedCodeTab = newTab; - } - - /// <summary> - /// Runs the selected script tab. - /// </summary> - private async void RunTab() - { - await BuildTab(); - - if (SelectedCodeTab.Errors.Count > 0) return; - - IsRunning = true; - SelectedCodeTab.IsRunning = true; - _logTextBox.Text = (DateTime.Now.ToTimeString() + ": ") + "Executing script '" + SelectedCodeTab.Title + "'..." + Environment.NewLine; - - await Task.Factory.StartNew(async () => - { - try - { - _stubManager = new StubManager(_adapter, (txt) => - { - AppendTextLog(txt + Environment.NewLine); - }, (txt) => - { - AppendTextLog(txt); - }, () => - { - - }); - var thisStubManager = _stubManager; - _stubManager.Completed += Manager_Completed; - _stubManager.Failed += Manager_Failed; - _stubManager.Executed += Manager_Executed; - _stubManager.AutoLog = AppendLogAuto; - - ScriptEngine engine = new ScriptEngine(new StubOnExecuteParameters(_stubManager)); - - engine.ReferencedAssemblies.Add(this.GetType()); - engine.ReferencedAssemblies.Add(typeof(PMR.Stubs.CalculateRequest)); - engine.ReferencedAssemblies.Add(typeof(IMessage)); - await engine.Run(SelectedCodeTab.Code, Path.GetDirectoryName(SelectedCodeTab.File)); - - if (!thisStubManager.Aborted) - { - IsRunning = false; - SelectedCodeTab.IsRunning = false; - } - } - catch (Exception ex) - { - IsRunning = false; - SelectedCodeTab.IsRunning = false; - MessageBox.Show(ex.Message, "Tango"); - } - }); - } - - /// <summary> - /// Builds the tab. - /// </summary> - private Task BuildTab() - { - return Task.Factory.StartNew(() => - { - try - { - Status = "Compiling " + SelectedCodeTab.Title + "..."; - - var thisStubManager = _stubManager; - - ScriptEngine engine = new ScriptEngine(new StubOnExecuteParameters(_stubManager)); - - engine.ReferencedAssemblies.Add(this.GetType()); - engine.ReferencedAssemblies.Add(typeof(PMR.Stubs.CalculateRequest)); - engine.ReferencedAssemblies.Add(typeof(IMessage)); - var results = engine.Compile(SelectedCodeTab.Code, Path.GetDirectoryName(SelectedCodeTab.File)).Result; - - if (results.Count == 0) - { - SelectedCodeTab.Errors = new ObservableCollection<CompilerError>(); - Status = "Compiled successfully."; - } - else - { - SelectedCodeTab.Errors = results.ToObservableCollection(); - Status = results.Count + " compilation errors found!"; - } - } - catch (Exception ex) - { - Status = "Error compiling!"; - SelectedCodeTab.Errors = new ObservableCollection<CompilerError>() { new CompilerError() { Error = ex.Message } }; - } - }); - } - - /// <summary> - /// Stops the currently current script. - /// </summary> - private void StopTab() - { - if (_stubManager != null) - { - _stubManager.Abort(); - IsRunning = false; - SelectedCodeTab.IsRunning = false; - Status = "Stopped!"; - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Stopped!" + Environment.NewLine); - } - } - - #endregion - - #region Public Methods - - public void SetLogTextBox(TextBox logTextBox) - { - _logTextBox = logTextBox; - } - - #endregion - - #region Event Handlers - - /// <summary> - /// Handled the <see cref="StubManager"/> Executed event. - /// </summary> - /// <param name="sender">The sender.</param> - /// <param name="stubName">Name of the stub.</param> - private void Manager_Executed(object sender, string stubName) - { - if (AppendLogAuto) - { - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Executing '" + stubName + "'..." + Environment.NewLine); - } - - Status = "Executing " + stubName + "..."; - } - - /// <summary> - /// Handled the <see cref="StubManager"/> Failed event. - /// </summary> - /// <param name="sender">The sender.</param> - /// <param name="ex">The exception.</param> - private void Manager_Failed(object sender, Exception ex) - { - if (IsRunning) - { - if (AppendLogAuto) - { - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + ex.Message + Environment.NewLine); - } - - Status = "Failed!"; - } - } - - /// <summary> - /// Handled the <see cref="StubManager"/> Completed event. - /// </summary> - /// <param name="sender">The sender.</param> - /// <param name="response">The response.</param> - private void Manager_Completed(object sender, string response) - { - if (AppendLogAuto) - { - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Response Received:" + Environment.NewLine); - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + response + Environment.NewLine); - } - Status = "Completed"; + Application.Current.Exit += Current_Exit; } private void Current_Exit(object sender, ExitEventArgs e) { - LogManager.OverrideQueue = true; - LogManager.Log("Application Terminated"); - _settings.AutoLogResponse = AppendLogAuto; - _settings.SelectedPort = SelectedPort; - _settings.BaudRate = BaudRate; - _settings.LastTabs = CodeTabs.Select(x => x.File).ToList(); - _settings.Save(); + StubsViewVM.SaveSettings(); } - - private void AppendTextLog(String log) - { - LogManager.Log(log); - - InvokeUI(() => - { - if (_logTextBox.Text.Length > 99999) - { - _logTextBox.Clear(); - } - _logTextBox.AppendText(log); - }); - } - - private void ClearTextLog() - { - LogManager.Log("Log Cleared -----------------------------------------------------------------"); - - InvokeUI(() => - { - _logTextBox.Text = String.Empty; - }); - } - - #endregion } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/StubSnippetVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/StubSnippetVM.cs deleted file mode 100644 index 32964473a..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/StubSnippetVM.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.SharedUI; - -namespace Tango.Stubs.UI.ViewModels -{ - /// <summary> - /// Represents a single stub snippet view model. - /// </summary> - /// <seealso cref="Tango.SharedUI.ViewModel" /> - public class StubSnippetVM : ViewModel - { - private String _name; - /// <summary> - /// Gets or sets the stub name. - /// </summary> - public String Name - { - get { return _name; } - set { _name = value; RaisePropertyChanged(nameof(Name)); } - } - - private String _code; - /// <summary> - /// Gets or sets the snippet code. - /// </summary> - public String Code - { - get { return _code; } - set { _code = value; RaisePropertyChanged(nameof(Code)); } - } - - /// <summary> - /// Returns a <see cref="System.String" /> that represents this instance. - /// </summary> - /// <returns> - /// A <see cref="System.String" /> that represents this instance. - /// </returns> - public override string ToString() - { - return Name; - } - } -} diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml index 5113a972b..8cba3b74b 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml @@ -3,409 +3,12 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:stubs="clr-namespace:Tango.Stubs.Views;assembly=Tango.Stubs" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:views="clr-namespace:Tango.Stubs.UI.Views" - xmlns:fa="http://schemas.fontawesome.io/icons/" - xmlns:local="clr-namespace:Tango.Stubs.UI.Views" - xmlns:vm="clr-namespace:Tango.Stubs.UI.ViewModels" - xmlns:System="clr-namespace:System;assembly=mscorlib" - xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" - xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" - xmlns:transport="clr-namespace:Tango.Transport.Adapters;assembly=Tango.Transport" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1280"> - <UserControl.InputBindings> - <KeyBinding Key="S" Modifiers="Control" Command="{Binding SaveCommand}"/> - <KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="{Binding SaveAsCommand}"/> - <KeyBinding Key="F6" Command="{Binding BuildCommand}"/> - </UserControl.InputBindings> - - <UserControl.Resources> - - <ObjectDataProvider x:Key="baudRates" MethodName="GetValues" - ObjectType="{x:Type System:Enum}"> - <ObjectDataProvider.MethodParameters> - <x:Type TypeName="transport:UsbSerialBaudRates"/> - </ObjectDataProvider.MethodParameters> - </ObjectDataProvider> - - <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></BooleanToVisibilityConverter> - <converters:EnumToDescriptionConverter x:Key="EnumToDescriptionConverter" /> - <Style BasedOn="{StaticResource MetroTabItem}" TargetType="{x:Type TabItem}"> - <Style.Triggers> - <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}" Value="True"> - <Setter Property="Background" Value="#007ACC"></Setter> - </DataTrigger> - </Style.Triggers> - <Setter Property="mahapps:ControlsHelper.HeaderFontSize" Value="12"></Setter> - <Setter Property="HeaderTemplate"> - <Setter.Value> - <DataTemplate> - <Border> - <StackPanel Orientation="Horizontal"> - <mahapps:ProgressRing Width="5" Height="5" Margin="0 0 5 0" Foreground="White" Visibility="{Binding IsRunning,Converter={StaticResource BooleanToVisibilityConverter}}"></mahapps:ProgressRing> - <TextBlock Text="{Binding Title}" ToolTip="{Binding File}" Foreground="Gainsboro" VerticalAlignment="Center"></TextBlock> - <Button Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CloseTabCommand}" CommandParameter="{Binding}" Margin="5 0 0 0" Cursor="Hand" Width="24" Height="24" VerticalAlignment="Center" Style="{DynamicResource MetroCircleButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0"> - <StackPanel Orientation="Horizontal"> - <fa:ImageAwesome Width="10" Height="10" Icon="Close" Foreground="Gainsboro"></fa:ImageAwesome> - </StackPanel> - </Button> - </StackPanel> - </Border> - </DataTemplate> - </Setter.Value> - </Setter> - <Setter Property="ContentTemplate"> - <Setter.Value> - <DataTemplate> - <Grid Background="#181818"> - <Grid.RowDefinitions> - <RowDefinition Height="1*" /> - <RowDefinition Height="Auto" /> - </Grid.RowDefinitions> - <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay}" InsertSnippetCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.InsertSnippetCommand,Mode=TwoWay}" SaveCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.SaveCommand}" HighlightTypes="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.HighlightTypes}" IntellisenseTypes="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.IntellisenseTypes}" RunCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RunCommand}" StopCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.StopCommand}" /> - - <Grid Grid.Row="1"> - <Grid.Style> - <Style TargetType="Grid"> - <Setter Property="Visibility" Value="Visible"></Setter> - <Style.Triggers> - <DataTrigger Binding="{Binding Errors.Count}" Value="0"> - <Setter Property="Visibility" Value="Collapsed"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </Grid.Style> - <Border BorderThickness="1" BorderBrush="#4B4B4B" Margin="10"> - <DataGrid ItemsSource="{Binding Errors}" AutoGenerateColumns="False" Focusable="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" HeadersVisibility="None"> - <DataGrid.Columns> - <DataGridTemplateColumn Header="#" Width="50"> - <DataGridTemplateColumn.CellTemplate> - <DataTemplate> - <fa:ImageAwesome Icon="ExclamationTriangle" Width="16" Foreground="#FF5C5C" /> - </DataTemplate> - </DataGridTemplateColumn.CellTemplate> - </DataGridTemplateColumn> - <DataGridTextColumn Header="ERROR" Binding="{Binding Error}" MinWidth="200"></DataGridTextColumn> - <DataGridTemplateColumn Header="FILE" MinWidth="200"> - <DataGridTemplateColumn.CellTemplate> - <DataTemplate> - <TextBlock><Run>'</Run><Run Text="{Binding File}"></Run><Run>'</Run></TextBlock> - </DataTemplate> - </DataGridTemplateColumn.CellTemplate> - </DataGridTemplateColumn> - <DataGridTemplateColumn Header="POSITION"> - <DataGridTemplateColumn.CellTemplate> - <DataTemplate> - <TextBlock><Run>(</Run><Run Text="{Binding Line}"></Run><Run>,</Run><Run Text="{Binding Character}"></Run><Run>)</Run></TextBlock> - </DataTemplate> - </DataGridTemplateColumn.CellTemplate> - </DataGridTemplateColumn> - </DataGrid.Columns> - </DataGrid> - </Border> - </Grid> - </Grid> - </DataTemplate> - </Setter.Value> - </Setter> - </Style> - </UserControl.Resources> - <UserControl.Style> - <Style TargetType="UserControl"> - <Style.Triggers> - <DataTrigger Binding="{Binding IsRunning}" Value="True"> - <Setter Property="Cursor" Value="AppStarting"></Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </UserControl.Style> <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="Auto"/> - <RowDefinition Height="1*"/> - </Grid.RowDefinitions> - - <Grid> - <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}" InputGestureText="Ctrl+S"> - <MenuItem.Icon> - <fa:ImageAwesome Icon="Save" Width="12" Foreground="Gainsboro" Margin="2" /> - </MenuItem.Icon> - </MenuItem> - <MenuItem Header="Save as" Command="{Binding SaveAsCommand}" InputGestureText="Ctrl+Shift+S"> - <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> - <Separator/> - <MenuItem Header="Exit" Command="{Binding ExitCommand}"> - <MenuItem.Icon> - <fa:ImageAwesome Icon="SignOut" Width="12" Foreground="Gainsboro" Margin="2" /> - </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="Wizard" ItemsSource="{Binding CreateGroups}"> - <MenuItem.ItemContainerStyle> - <Style TargetType="{x:Type MenuItem}"> - <Setter Property="Padding" Value="2"></Setter> - <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CreateItemCommand}" /> - <Setter Property="CommandParameter" Value="{Binding}"></Setter> - </Style> - </MenuItem.ItemContainerStyle> - <MenuItem.ItemTemplate> - <HierarchicalDataTemplate DataType="{x:Type vm:CreateGroupVM}" ItemsSource="{Binding Path=Items}"> - <TextBlock Text="{Binding Name}"/> - </HierarchicalDataTemplate> - </MenuItem.ItemTemplate> - </MenuItem> - <MenuItem Header="Examples" ItemsSource="{Binding Examples}"> - <MenuItem.ItemContainerStyle> - <Style TargetType="{x:Type MenuItem}"> - <Setter Property="Padding" Value="2"></Setter> - <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.CreateExampleCommand}" /> - <Setter Property="CommandParameter" Value="{Binding}"></Setter> - </Style> - </MenuItem.ItemContainerStyle> - <MenuItem.ItemTemplate> - <DataTemplate> - <TextBlock Text="{Binding Name}" ToolTip="{Binding Code}"></TextBlock> - </DataTemplate> - </MenuItem.ItemTemplate> - </MenuItem> - <MenuItem Header="Debug"> - <MenuItem Header="Build (F6)" MinWidth="150" Command="{Binding BuildCommand}" > - <MenuItem.Icon> - <fa:ImageAwesome Icon="Cog" Width="12" Margin="2"> - <fa:ImageAwesome.Style> - <Style TargetType="fa:ImageAwesome"> - <Setter Property="Foreground" Value="#EF8E29"></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="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> - </Grid> - - <Grid Grid.Row="2"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="1019*"/> - <ColumnDefinition Width="220"/> - </Grid.ColumnDefinitions> - <Grid.RowDefinitions> - <RowDefinition Height="1*"/> - <RowDefinition Height="5"/> - <RowDefinition Height="0.5*"/> - </Grid.RowDefinitions> - - <Grid> - <TabControl x:Name="tabControl" Margin="5" ItemsSource="{Binding CodeTabs}" SelectedItem="{Binding SelectedCodeTab}"> - - </TabControl> - - <Grid HorizontalAlignment="Right" Margin="0 45 40 0" VerticalAlignment="Top" Visibility="{Binding IsRunning,Converter={StaticResource BooleanToVisibilityConverter}}"> - <StackPanel Orientation="Horizontal"> - <mahapps:ProgressRing Foreground="#007ACC" Width="20" Height="20"></mahapps:ProgressRing> - <TextBlock Text="Running..." FontStyle="Italic" Margin="10 0 0 0" FontSize="14" VerticalAlignment="Center"></TextBlock> - </StackPanel> - </Grid> - </Grid> - - <Grid Grid.Column="1" Grid.RowSpan="3"> - <Grid VerticalAlignment="Bottom" Height="25" Background="#007ACC"> - - </Grid> - <DockPanel> - <GroupBox Header="COMMUNICATION PORT" VerticalAlignment="Top" DockPanel.Dock="Top" Margin="0 2 0 0"> - <StackPanel> - <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Ports}" Height="35" SelectedItem="{Binding SelectedPort}"></ComboBox> - <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Source={StaticResource baudRates}}" Height="35" SelectedItem="{Binding BaudRate}" SelectedIndex="0"> - <ComboBox.ItemTemplate> - <DataTemplate> - <TextBlock Text="{Binding Path=.,Converter={StaticResource EnumToDescriptionConverter}}" /> - </DataTemplate> - </ComboBox.ItemTemplate> - </ComboBox> - </StackPanel> - </GroupBox> - - <GroupBox Header="CONNECTION" DockPanel.Dock="Bottom" VerticalAlignment="Bottom" Margin="0 10 0 25"> - <StackPanel> - <Button Height="50" MinWidth="100" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding ToggleConnectionCommand}"> - <Button.Style> - <Style TargetType="Button" BasedOn="{StaticResource AccentedSquareButtonStyle}"> - <Style.Triggers> - <DataTrigger Binding="{Binding IsConnected}" Value="False"> - <Setter Property="Content"> - <Setter.Value> - <StackPanel Orientation="Horizontal"> - <fa:ImageAwesome Icon="Link" Width="16"></fa:ImageAwesome> - <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">CONNECT</TextBlock> - </StackPanel> - </Setter.Value> - </Setter> - </DataTrigger> - <DataTrigger Binding="{Binding IsConnected}" Value="True"> - <Setter Property="Content"> - <Setter.Value> - <StackPanel Orientation="Horizontal"> - <fa:ImageAwesome Icon="Unlink" Width="16"></fa:ImageAwesome> - <TextBlock VerticalAlignment="Center" Margin="10 0 10 0">DISCONNECT</TextBlock> - </StackPanel> - </Setter.Value> - </Setter> - </DataTrigger> - </Style.Triggers> - </Style> - </Button.Style> - </Button> - </StackPanel> - </GroupBox> - - <GroupBox Header="STUB SNIPPETS" Margin="0 10 0 0"> - <Grid> - <ListBox BorderThickness="0" ItemsSource="{Binding StubSnippets}" HorizontalContentAlignment="Stretch" SelectedItem="{Binding SelectedStubSnippet}"> - <ListBox.ItemContainerStyle> - <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}"> - <Setter Property="Padding" Value="0"></Setter> - <Setter Property="Margin" Value="0 2 0 2"></Setter> - <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> - </Style> - </ListBox.ItemContainerStyle> - <ListBox.ItemTemplate> - <DataTemplate> - <Border BorderThickness="1" BorderBrush="#007ACC" Padding="8" Background="Transparent"> - <Border.InputBindings> - <MouseBinding Gesture="LeftDoubleClick" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.StubSnippetSelectedCommand}"/> - </Border.InputBindings> - <Grid> - <fa:ImageAwesome Icon="ArrowLeft" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5 0 0 0" Foreground="#007ACC" Width="16" Height="16"></fa:ImageAwesome> - <TextBlock VerticalAlignment="Center" FontSize="11" HorizontalAlignment="Center" Text="{Binding Name}"></TextBlock> - </Grid> - </Border> - </DataTemplate> - </ListBox.ItemTemplate> - </ListBox> - </Grid> - </GroupBox> - </DockPanel> - </Grid> - - <GridSplitter Margin="5 0 5 0" Grid.Row="1" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center"> - <GridSplitter.Background> - <LinearGradientBrush> - <GradientStop/> - <GradientStop Color="#007ACC" Offset="0.5"/> - <GradientStop Offset="1"/> - </LinearGradientBrush> - </GridSplitter.Background> - </GridSplitter> - - <Grid Grid.Row="2"> - <Grid.RowDefinitions> - <RowDefinition Height="1*"/> - <RowDefinition Height="25"/> - </Grid.RowDefinitions> - <GroupBox Header="Response"> - <Grid Background="#151515"> - <TextBox x:Name="txtLog" PreviewMouseDown="txtLog_PreviewMouseUp" FontFamily="Lucida Console" TextChanged="TextBox_TextChanged" Background="Transparent" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro"></TextBox> - - <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 -32 -6 0"> - <CheckBox VerticalAlignment="Center" Margin="0 0 20 0" IsChecked="{Binding AppendLogAuto}">Auto Logging</CheckBox> - <CheckBox x:Name="chkScroll" IsChecked="True" VerticalAlignment="Center" Margin="0 0 20 0">Scroll To End</CheckBox> - <Button Width="80" Height="25" Command="{Binding ClearCommand}">CLEAR</Button> - </StackPanel> - </Grid> - </GroupBox> - <StatusBar Background="#007ACC" Grid.Row="1"> - <TextBlock Text="{Binding Status}"></TextBlock> - </StatusBar> - </Grid> - </Grid> + <stubs:StubsView DataContext="{Binding StubsViewVM}" /> </Grid> </UserControl> diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml.cs index 06cc3d76c..8bf67e1c1 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml.cs @@ -18,38 +18,15 @@ using Tango.Stubs.UI.ViewModels; namespace Tango.Stubs.UI.Views { - /// <summary> - /// Interaction logic for MainView.xaml - /// </summary> - public partial class MainView : UserControl + /// <summary> + /// Interaction logic for MainView.xaml + /// </summary> + public partial class MainView : UserControl + { + public MainView() : base() { - private MainViewVM _vm; - - public MainView() : base() - { - InitializeComponent(); - Loaded += (_, __) => - { - _vm = DataContext as MainViewVM; - _vm.SetLogTextBox(txtLog); - - - }; - } - - //Auto scroll to bottom of response log each time it is changed. - private void TextBox_TextChanged(object sender, TextChangedEventArgs e) - { - if (chkScroll.IsChecked.Value) - { - txtLog.SelectionStart = txtLog.Text.Length; - txtLog.ScrollToEnd(); - } - } - - private void txtLog_PreviewMouseUp(object sender, MouseButtonEventArgs e) - { - chkScroll.IsChecked = false; - } + InitializeComponent(); + DataContext = new MainViewVM(); } + } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Windows/TextInputWindow.xaml b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Windows/TextInputWindow.xaml deleted file mode 100644 index cae2f94fe..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Windows/TextInputWindow.xaml +++ /dev/null @@ -1,25 +0,0 @@ -<mahapps:MetroWindow x:Class="Tango.Stubs.UI.Windows.TextInputWindow" - 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:mahapps="http://metro.mahapps.com/winfx/xaml/controls" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:Tango.Stubs.UI.Windows" - mc:Ignorable="d" - Title="Tango Stubs Execution Utility" ResizeMode="NoResize" ShowInTaskbar="False" ShowIconOnTitleBar="False" TitlebarHeight="40" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" Height="200" Width="500" WindowStartupLocation="CenterScreen" Background="#202020" Foreground="Gainsboro" DataContext="{Binding RelativeSource={RelativeSource Self}}"> - <Grid> - <Grid Margin="10"> - <Grid.RowDefinitions> - <RowDefinition Height="40*"/> - <RowDefinition Height="71*"/> - <RowDefinition Height="60"/> - </Grid.RowDefinitions> - - <TextBlock x:Name="lbMessage" VerticalAlignment="Center">The current operation requires you to provide some response in string format.</TextBlock> - - <TextBox x:Name="txtText" Grid.Row="1" Background="#151515" Foreground="Gainsboro" VerticalAlignment="Center" BorderBrush="DimGray"></TextBox> - - <Button Click="Button_Click" Grid.Row="2" HorizontalAlignment="Right" BorderThickness="0" Width="140" Height="35" VerticalAlignment="Bottom" IsDefault="True" mahapps:ButtonHelper.PreserveTextCase="True" Style="{StaticResource AccentedSquareButtonStyle}">OK</Button> - </Grid> - </Grid> -</mahapps:MetroWindow> diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Windows/TextInputWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Windows/TextInputWindow.xaml.cs deleted file mode 100644 index e15c690ec..000000000 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Windows/TextInputWindow.xaml.cs +++ /dev/null @@ -1,53 +0,0 @@ -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.Stubs.UI.Windows -{ - /// <summary> - /// Interaction logic for TextInputWindow.xaml - /// </summary> - public partial class TextInputWindow : MetroWindow - { - public String Response { get; set; } - - public TextInputWindow() - { - InitializeComponent(); - this.Loaded += TextInputWindow_Loaded; - } - - private void TextInputWindow_Loaded(object sender, RoutedEventArgs e) - { - txtText.Focus(); - } - - public TextInputWindow(String message, String defaultResponse) : this() - { - txtText.Text = defaultResponse; - - if (message != null) - { - lbMessage.Text = message; - } - } - - private void Button_Click(object sender, RoutedEventArgs e) - { - Response = txtText.Text; - DialogResult = true; - Close(); - } - } -} |
