diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-08 16:56:05 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-03-08 16:56:05 +0200 |
| commit | 860c4f663dfdd2ba7676d7e02bf0509b30389cd5 (patch) | |
| tree | c3e529d1c18edcdb0ee5a3c147d4fc273d294f50 | |
| parent | ef563b18e8afc5a30beed830f1615c4277021225 (diff) | |
| download | Tango-860c4f663dfdd2ba7676d7e02bf0509b30389cd5.tar.gz Tango-860c4f663dfdd2ba7676d7e02bf0509b30389cd5.zip | |
Stubs UI improvements !
9 files changed, 150 insertions, 23 deletions
diff --git a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionList.xaml b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionList.xaml index 484d43fda..5f5f1887d 100644 --- a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionList.xaml +++ b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionList.xaml @@ -38,11 +38,21 @@ <Style TargetType="{x:Type cc:CompletionList}"> <Style.Resources> - <!--<ResourceDictionary Source="/Theme.xaml"></ResourceDictionary>--> + <Style TargetType="ListBoxItem"> + <Setter Property="Background" Value="#202020"></Setter> + <Setter Property="Foreground" Value="Gainsboro"></Setter> + <Setter Property="Padding" Value="2"></Setter> + <Setter Property="BorderThickness" Value="0"></Setter> + <Style.Triggers> + <Trigger Property="IsSelected" Value="True"> + <Setter Property="Foreground" Value="#202020"></Setter> + </Trigger> + </Style.Triggers> + </Style> </Style.Resources> <Setter Property="Background" Value="#202020"></Setter> <Setter Property="BorderThickness" Value="0"></Setter> - <Setter Property="Template"> + <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type cc:CompletionList}"> <cc:CompletionListBox x:Name="PART_ListBox"> diff --git a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs index 9953b7a38..c5ee45f5f 100644 --- a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs +++ b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/CodeCompletion/CompletionWindow.cs @@ -45,7 +45,7 @@ namespace ICSharpCode.AvalonEdit.CodeCompletion // prevent user from resizing window to 0x0 this.MinHeight = 15; this.MinWidth = 30; - this.Background = new SolidColorBrush(Color.FromRgb(15, 15, 15)); + //this.Background = new SolidColorBrush(Color.FromRgb(15, 15, 15)); this.Foreground = Brushes.Gainsboro; toolTip.PlacementTarget = this; diff --git a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj index abf0d23a2..eafe583f4 100644 --- a/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj +++ b/Software/Visual_Studio/SideChains/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj @@ -59,7 +59,7 @@ </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'"> <Prefer32Bit>false</Prefer32Bit> - <OutputPath>bin\Release\</OutputPath> + <OutputPath>..\..\Build\Debug\</OutputPath> <DocumentationFile /> </PropertyGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> diff --git a/Software/Visual_Studio/Tango.Stubs/StubBase.cs b/Software/Visual_Studio/Tango.Stubs/StubBase.cs index ccc1a5496..ffebcb628 100644 --- a/Software/Visual_Studio/Tango.Stubs/StubBase.cs +++ b/Software/Visual_Studio/Tango.Stubs/StubBase.cs @@ -89,5 +89,10 @@ namespace Tango.Stubs { return typeof(MessageFactory).Assembly.GetTypes().Where(x => x.Namespace.Contains("Stubs") && x.Name.Contains("Request") && !x.Name.Contains("Reflection")).ToList(); } + + public static List<Type> GetAvailableRequestResponseStubs() + { + return typeof(MessageFactory).Assembly.GetTypes().Where(x => x.Namespace.Contains("Stubs") && !x.Name.Contains("Reflection")).ToList(); + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs index 68b249a8a..2a721184b 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Resources/CodeTabTemplate.cs @@ -7,14 +7,19 @@ 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++) { - stubManager.Run("calculate", 10, 5); - Thread.Sleep(10); + var response = stubManager.Run<CalculateResponse>("calculate", 10, 5); + + if (response.Sum == 15) + { + stubManager.WriteLine("OK!"); + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs index 150649c0b..6249b3577 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Controls; using Tango.PMR; using Tango.PMR.Common; using Tango.Transport.Adapters; @@ -19,6 +20,9 @@ namespace Tango.Stubs.UI 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. @@ -44,8 +48,12 @@ namespace Tango.Stubs.UI /// Initializes a new instance of the <see cref="StubManager"/> class. /// </summary> /// <param name="adapter">The adapter.</param> - public StubManager(UsbTransportAdapter adapter) + public StubManager(UsbTransportAdapter adapter, Action<String> writeLine, Action<String> write, Action clear) { + _writeLine = writeLine; + _write = write; + _clear = clear; + _adapter = adapter; } @@ -62,15 +70,15 @@ namespace Tango.Stubs.UI /// </summary> /// <param name="stubName">Name of the stub.</param> /// <param name="args">The arguments.</param> - public void Run(String stubName, params Object[] args) + public IMessage Run(String stubName, params Object[] args) { - if (Aborted) return; + if (Aborted) return null; var stubType = StubBase.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; + return null; } var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance); @@ -78,7 +86,7 @@ namespace Tango.Stubs.UI if (stubProps.Length > args.Length) { OnFailed(new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + ".")); - return; + return null; } Executed?.Invoke(this, stubType.Name); @@ -117,7 +125,7 @@ namespace Tango.Stubs.UI bool done = false; - TaskCompletionSource<IMessage> _completionSource = new TaskCompletionSource<IMessage>(); + IMessage message = null; Task.Factory.StartNew(() => { @@ -144,9 +152,8 @@ namespace Tango.Stubs.UI } } - IMessage message = MessageFactory.ExtractMessageFromContainer(responseContainer); + message = MessageFactory.ExtractMessageFromContainer(responseContainer); OnCompleted(JsonConvert.SerializeObject(message, Formatting.Indented)); - _completionSource.SetResult(message); done = true; }); @@ -154,11 +161,45 @@ namespace Tango.Stubs.UI { Thread.Sleep(2); } + + return message; } catch (Exception ex) { OnFailed(ex); } + + return null; + } + + public T Run<T>(String stubName, params Object[] args) where T : class, IMessage + { + return Run(stubName, args) as T; + } + + public void WriteLine(Object obj) + { + _writeLine(obj.ToString()); + } + + public void Write(Object obj) + { + _write(obj.ToString()); + } + + 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(); } /// <summary> 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 79d535aaf..f4e4aa124 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs @@ -1,4 +1,5 @@ -using Microsoft.Win32; +using Google.Protobuf; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -115,6 +116,14 @@ namespace Tango.Stubs.UI.ViewModels set { _isRunning = value; RaisePropertyChanged(nameof(IsRunning)); InvalidateRelayCommands(); } } + private bool _appendLogAuto; + + public bool AppendLogAuto + { + get { return _appendLogAuto; } + set { _appendLogAuto = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -188,6 +197,7 @@ namespace Tango.Stubs.UI.ViewModels /// </summary> public MainViewVM() { + AppendLogAuto = true; CodeTabs = new ObservableCollection<CodeTabVM>(); NewCommand = new RelayCommand(CreateNewTab); CloseTabCommand = new RelayCommand<CodeTabVM>(OnTabClosing); @@ -198,6 +208,11 @@ namespace Tango.Stubs.UI.ViewModels HighlightTypes = new ObservableCollection<KeyValuePair<string, Type>>(); HighlightTypes.Add(new KeyValuePair<string, Type>("stubManager", typeof(StubManager))); + foreach (var stubType in StubBase.GetAvailableRequestResponseStubs()) + { + HighlightTypes.Add(new KeyValuePair<string, Type>(stubType.GetType().Name, stubType)); + } + StubSnippets = new ObservableCollection<StubSnippetVM>(); foreach (var stubType in StubBase.GetAvailableRequestStubs()) @@ -207,12 +222,26 @@ namespace Tango.Stubs.UI.ViewModels 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; } - snippet.Code += String.Format("stubManager.Run(\"{0}\" ,{1});", stubType.Name, String.Join(", ", stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(x => x.PropertyType.Name == "string" ? "\"string\"" : x.PropertyType.Name))); + Type responseType = StubBase.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); } @@ -412,7 +441,16 @@ namespace Tango.Stubs.UI.ViewModels { try { - _stubManager = new StubManager(_adapter); + _stubManager = new StubManager(_adapter, (txt) => + { + AppendTextLog(txt + Environment.NewLine); + }, (txt) => + { + AppendTextLog(txt); + }, () => + { + + }); var thisStubManager = _stubManager; _stubManager.Completed += Manager_Completed; _stubManager.Failed += Manager_Failed; @@ -421,6 +459,8 @@ namespace Tango.Stubs.UI.ViewModels 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); if (!thisStubManager.Aborted) @@ -473,7 +513,11 @@ namespace Tango.Stubs.UI.ViewModels /// <param name="stubName">Name of the stub.</param> private void Manager_Executed(object sender, string stubName) { - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Executing '" + stubName + "'..." + Environment.NewLine); + if (AppendLogAuto) + { + AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Executing '" + stubName + "'..." + Environment.NewLine); + } + Status = "Executing " + stubName + "..."; } @@ -486,7 +530,11 @@ namespace Tango.Stubs.UI.ViewModels { if (IsRunning) { - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + ex.Message + Environment.NewLine); + if (AppendLogAuto) + { + AppendTextLog((DateTime.Now.ToTimeString() + ": ") + ex.Message + Environment.NewLine); + } + Status = "Failed!"; } } @@ -498,8 +546,11 @@ namespace Tango.Stubs.UI.ViewModels /// <param name="response">The response.</param> private void Manager_Completed(object sender, string response) { - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Response Received:" + Environment.NewLine); - AppendTextLog((DateTime.Now.ToTimeString() + ": ") + response + Environment.NewLine); + if (AppendLogAuto) + { + AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Response Received:" + Environment.NewLine); + AppendTextLog((DateTime.Now.ToTimeString() + ": ") + response + Environment.NewLine); + } Status = "Completed"; } @@ -512,11 +563,20 @@ namespace Tango.Stubs.UI.ViewModels private void AppendTextLog(String log) { - InvokeUI(() => + InvokeUI(() => { _logTextBox.AppendText(log); }); } + + private void ClearTextLog() + { + InvokeUI(() => + { + _logTextBox.Text = String.Empty; + }); + } + #endregion } } 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 cf0ccf657..1ba809a28 100644 --- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/Views/MainView.xaml @@ -280,7 +280,11 @@ <GroupBox Header="Response"> <Grid Background="#151515"> <TextBox x:Name="txtLog" 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> - <Button HorizontalAlignment="Right" VerticalAlignment="Top" Width="80" Height="25" Margin="0 -32 -6 0" Command="{Binding ClearCommand}">CLEAR</Button> + + <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 -32 -6 0"> + <CheckBox VerticalAlignment="Center" Margin="0 0 20 0" IsChecked="{Binding AppendLogAuto}">Log response automatically</CheckBox> + <Button Width="80" Height="25" Command="{Binding ClearCommand}">CLEAR</Button> + </StackPanel> </Grid> </GroupBox> <StatusBar Background="#007ACC" Grid.Row="1"> 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 822dc1824..2e9878453 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 @@ -32,6 +32,8 @@ namespace Tango.Stubs.UI.Views { _vm = DataContext as MainViewVM; _vm.SetLogTextBox(txtLog); + + }; } |
