aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities
diff options
context:
space:
mode:
authorRoy <roy.mail.net@gmail.com>2017-12-08 00:54:27 +0200
committerRoy <roy.mail.net@gmail.com>2017-12-08 00:54:27 +0200
commitdb4db5d05b42cbc795b3a38bba3e6c87f30d583f (patch)
tree6eb253e1bb8d267ffdf41b2e1ff14febfd4f62a9 /Software/Visual_Studio/Utilities
parentb457125866deb830b379cf3873e5cda3975b077a (diff)
downloadTango-db4db5d05b42cbc795b3a38bba3e6c87f30d583f.tar.gz
Tango-db4db5d05b42cbc795b3a38bba3e6c87f30d583f.zip
Stubs scripting improvements.
Diffstat (limited to 'Software/Visual_Studio/Utilities')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs2
-rw-r--r--Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs5
-rw-r--r--Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs91
-rw-r--r--Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml59
4 files changed, 140 insertions, 17 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs
index 9895e6993..68ff84013 100644
--- a/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs
+++ b/Software/Visual_Studio/Utilities/Tango.Stubs.CLI/Program.cs
@@ -71,7 +71,7 @@ namespace Tango.Stubs.CLI
}
else
{
- prop.SetValue(request, args[argIndex++]);
+ prop.SetValue(request, arg);
}
}
diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
index 8bfb0db7c..944decb9d 100644
--- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
+++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
@@ -19,6 +19,7 @@ namespace Tango.Stubs.UI
public event EventHandler<Exception> Failed;
public event EventHandler<String> Completed;
+ public event EventHandler<String> Executed;
public StubManager(UsbTransportAdapter adapter)
{
@@ -40,6 +41,8 @@ namespace Tango.Stubs.UI
OnFailed(new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + "."));
}
+ Executed?.Invoke(this, stubType.Name);
+
try
{
MessageContainer container = new MessageContainer();
@@ -65,7 +68,7 @@ namespace Tango.Stubs.UI
}
else
{
- prop.SetValue(request, args[argIndex++]);
+ prop.SetValue(request, arg);
}
}
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 5939dfd95..bb0632e56 100644
--- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs
@@ -16,7 +16,7 @@ namespace Tango.Stubs.UI.ViewModels
private UsbTransportAdapter _adapter;
public ObservableCollection<CodeTabVM> CodeTabs { get; set; }
- public ObservableCollection<Type> HighlightTypes { get; set; }
+ public ObservableCollection<KeyValuePair<String, Type>> HighlightTypes { get; set; }
private String _log;
@@ -26,7 +26,6 @@ namespace Tango.Stubs.UI.ViewModels
set { _log = value; RaisePropertyChanged(nameof(Log)); }
}
-
private CodeTabVM _selectedCodeTab;
public CodeTabVM SelectedCodeTab
@@ -35,10 +34,47 @@ namespace Tango.Stubs.UI.ViewModels
set { _selectedCodeTab = value; RaisePropertyChanged(nameof(SelectedCodeTab)); }
}
+ private bool _isConnected;
+
+ public bool IsConnected
+ {
+ get { return _isConnected; }
+ set { _isConnected = value; RaisePropertyChanged(nameof(IsConnected)); }
+ }
+
+ private List<String> _ports;
+ /// <summary>
+ /// Gets or sets the ports.
+ /// </summary>
+ public List<String> Ports
+ {
+ get { return _ports; }
+ set { _ports = value; RaisePropertyChanged(nameof(Ports)); }
+ }
+
+ private String _selectedPort;
+ /// <summary>
+ /// Gets or sets the selected port.
+ /// </summary>
+ public String SelectedPort
+ {
+ get { return _selectedPort; }
+ set { _selectedPort = value; RaisePropertyChanged(nameof(SelectedPort)); }
+ }
+
+ private String _status;
+
+ public String Status
+ {
+ get { return _status; }
+ set { _status = value; RaisePropertyChanged(nameof(Status)); }
+ }
+
public RelayCommand NewCommand { get; set; }
public RelayCommand<CodeTabVM> CloseTabCommand { get; set; }
public RelayCommand RunCommand { get; set; }
+ public RelayCommand ToggleConnectionCommand { get; set; }
public MainViewVM()
{
@@ -47,11 +83,42 @@ namespace Tango.Stubs.UI.ViewModels
CloseTabCommand = new RelayCommand<CodeTabVM>(OnTabClosing);
RunCommand = new RelayCommand(OnTabRun);
- HighlightTypes = new ObservableCollection<Type>();
- HighlightTypes.Add(typeof(StubManager));
+ HighlightTypes = new ObservableCollection<KeyValuePair<string, Type>>();
+ HighlightTypes.Add(new KeyValuePair<string, Type>("stubManager", typeof(StubManager)));
+
+ ToggleConnectionCommand = new RelayCommand(ToggleConnection);
- _adapter = new UsbTransportAdapter("COM2");
- _adapter.Connect().Wait();
+ Ports = new List<string>()
+ {
+ "COM1",
+ "COM2",
+ "COM3",
+ "COM4",
+ "COM5",
+ "COM6",
+ "COM7",
+ "COM8",
+ "COM9",
+ };
+
+ SelectedPort = Ports.First();
+
+ Status = "Read";
+ }
+
+ private void ToggleConnection()
+ {
+ if (!IsConnected)
+ {
+ _adapter = new UsbTransportAdapter(SelectedPort);
+ _adapter.Connect().Wait();
+ IsConnected = true;
+ }
+ else
+ {
+ _adapter.Disconnect().Wait();
+ IsConnected = false;
+ }
}
private void OnCreateNewTab()
@@ -68,34 +135,40 @@ namespace Tango.Stubs.UI.ViewModels
StubManager manager = new StubManager(_adapter);
manager.Completed += Manager_Completed;
manager.Failed += Manager_Failed;
+ manager.Executed += Manager_Executed;
ScriptEngine engine = new ScriptEngine(new StubOnExecuteParameters(manager));
engine.ReferencedAssemblies.Add(this.GetType());
await engine.Run(SelectedCodeTab.Code);
}
- catch (Exception ex)
+ catch
{
throw;
}
}
+ private void Manager_Executed(object sender, string e)
+ {
+ Status = "Executing " + e + "...";
+ }
+
private void Manager_Failed(object sender, Exception e)
{
Log += e.Message + Environment.NewLine;
+ Status = "Failed!";
}
private void Manager_Completed(object sender, string response)
{
Log += "Response Received:" + Environment.NewLine;
Log += response + Environment.NewLine;
+ Status = "Completed";
}
private void OnTabClosing(CodeTabVM codeTab)
{
CodeTabs.Remove(codeTab);
}
-
-
}
}
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 9f1c15947..1657908db 100644
--- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml
+++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml
@@ -34,7 +34,7 @@
<Setter.Value>
<DataTemplate>
<Grid Background="#181818">
- <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay}" RunCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RunCommand}" />
+ <controls:ScriptEditorControl Text="{Binding Code,Mode=TwoWay}" HighlightTypes="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.HighlightTypes}" RunCommand="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.RunCommand}" />
</Grid>
</DataTemplate>
</Setter.Value>
@@ -52,14 +52,14 @@
<MenuItem Header="File">
<MenuItem Header="New" Command="{Binding NewCommand}"></MenuItem>
<Separator/>
- <MenuItem Header="Open" MinWidth="150"></MenuItem>
+ <MenuItem Header="Open" MinWidth="150" Command="{Binding OpenCommand}"></MenuItem>
<Separator/>
- <MenuItem Header="Save"></MenuItem>
- <MenuItem Header="Save as"></MenuItem>
+ <MenuItem Header="Save" Command="{Binding SaveCommand}"></MenuItem>
+ <MenuItem Header="Save as" Command="{Binding SaveAsCommand}"></MenuItem>
<Separator/>
<MenuItem Header="Exit"></MenuItem>
</MenuItem>
- <MenuItem Header="Edit">
+ <!--<MenuItem Header="Edit">
<MenuItem Header="Cut" MinWidth="150"></MenuItem>
<Separator/>
<MenuItem Header="Copy"></MenuItem>
@@ -67,7 +67,7 @@
<Separator/>
<MenuItem Header="Undo"></MenuItem>
<MenuItem Header="Redo"></MenuItem>
- </MenuItem>
+ </MenuItem>-->
</Menu>
</Grid>
@@ -88,6 +88,46 @@
</TabControl>
</Grid>
+ <Grid Grid.Column="1" Grid.RowSpan="3">
+ <DockPanel Margin="5">
+ <StackPanel VerticalAlignment="Top" DockPanel.Dock="Top">
+ <TextBlock>Connection</TextBlock>
+ <ComboBox Margin="0 10 0 0" BorderThickness="0" ItemsSource="{Binding Ports}" Height="35" SelectedItem="{Binding SelectedPort}"></ComboBox>
+ </StackPanel>
+
+ <StackPanel DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
+ <Button Margin="0 0 0 22" 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>
+ </DockPanel>
+ </Grid>
+
<GridSplitter Margin="5 0 5 0" Grid.Row="1" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<GridSplitter.Background>
<LinearGradientBrush>
@@ -105,7 +145,14 @@
</Grid.RowDefinitions>
<TextBlock Foreground="Gainsboro" VerticalAlignment="Center" Margin="5 0 0 0">Response</TextBlock>
<Grid Background="Black" Grid.Row="1">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="169*"/>
+ <RowDefinition Height="25"/>
+ </Grid.RowDefinitions>
<TextBox x:Name="txtLog" TextChanged="TextBox_TextChanged" Background="Transparent" Text="{Binding Log}" BorderThickness="0" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" Padding="5" IsReadOnly="True" TextWrapping="Wrap" FontSize="11" Foreground="Gainsboro"></TextBox>
+ <StatusBar Grid.Row="1" Background="#CD5805">
+ <TextBlock Text="{Binding Status}"></TextBlock>
+ </StatusBar>
</Grid>
</Grid>
</Grid>