diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-27 11:52:18 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-04-27 11:52:18 +0300 |
| commit | c2053da2800be48d49d473b3da80954afbcc0a15 (patch) | |
| tree | 9d063dfb8a8f84e5f7ce8fa70e989620b0a01b63 /Software | |
| parent | 0c3ff71389d4a9a4c5e8454fac594705119b4dd1 (diff) | |
| download | Tango-c2053da2800be48d49d473b3da80954afbcc0a15.tar.gz Tango-c2053da2800be48d49d473b3da80954afbcc0a15.zip | |
TestDesigner improvements..
Diffstat (limited to 'Software')
12 files changed, 272 insertions, 3 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ArrayParsingStyle.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ArrayParsingStyle.cs new file mode 100644 index 000000000..1380f6564 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ArrayParsingStyle.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Stubs +{ + public enum ArrayParsingStyle + { + Comma, + SquareBrackets, + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs index ea87a4f19..97cf9a433 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs @@ -11,5 +11,6 @@ namespace Tango.FSE.Stubs.Contracts { void FormatCode(); void HighlightCode(int position, int length); + void InsertCode(String code); } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/CreateGroup.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/CreateGroup.cs new file mode 100644 index 000000000..de8de7107 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/CreateGroup.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.FSE.Stubs +{ + public class CreateGroup : ExtendedObject + { + public String Name { get; set; } + + public List<CreateItem> Items { get; set; } + + public CreateGroup() + { + Items = new List<CreateItem>(); + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/CreateItem.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/CreateItem.cs new file mode 100644 index 000000000..be1d00df4 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/CreateItem.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.FSE.Stubs +{ + public class CreateItem : ExtendedObject + { + public Type Type { get; set; } + + public String Name { get; set; } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs index 0897517ae..fc3344fa8 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs @@ -1,5 +1,6 @@ using Google.Protobuf; using System; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -27,10 +28,12 @@ namespace Tango.FSE.Stubs void Write(Object obj); void WriteLineHex(Object number, int digits); void WriteHex(Object number, int digits); + void WriteLineArray(IEnumerable array, ArrayParsingStyle style); void Clear(); void WriteToFile(String filePath, String content); void AppendToFile(String filePath, String content); T GetInput<T>(String key); + List<T> GetInputArray<T>(String key); Object GetInput(String key); void Fail(String message); void ShowInfo(String message); diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs index 74f95a437..813f31532 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,6 +14,11 @@ namespace Tango.FSE.Stubs public String Name { get; set; } public Object Value { get; set; } + internal bool IsValueArray + { + get { return Value != null && typeof(IEnumerable).IsAssignableFrom(Value.GetType()) && Value.GetType() != typeof(String); } + } + public Result() { diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj index 4a589277c..67bd5dfc8 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj @@ -96,7 +96,10 @@ <Reference Include="PresentationFramework" /> </ItemGroup> <ItemGroup> + <Compile Include="ArrayParsingStyle.cs" /> <Compile Include="Contracts\ITestDesignerView.cs" /> + <Compile Include="CreateGroup.cs" /> + <Compile Include="CreateItem.cs" /> <Compile Include="Designer\ProjectModel.cs" /> <Compile Include="Designer\ScriptTabModel.cs" /> <Compile Include="Dialogs\AddReferenceAssemblyView.xaml.cs"> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs index d043a7165..9761a9378 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -206,7 +207,7 @@ namespace Tango.FSE.Stubs if (obj != null) { - if (obj.GetType().IsClass) + if (!obj.GetType().IsValueTypeOrString()) { line = obj.ToJsonString(); } @@ -303,6 +304,16 @@ namespace Tango.FSE.Stubs } } + public List<T> GetInputArray<T>(String key) + { + var value = GetInput(key); + + String[] arr = value.ToStringSafe().Split(','); + var list = new List<T>(arr.Select(x => (T)Convert.ChangeType(x, typeof(T)))); + + return list; + } + public object GetInput(string key) { TestInput input = null; @@ -409,5 +420,31 @@ namespace Tango.FSE.Stubs vm.FinalizeModel(); return model; } + + public void WriteLineArray(IEnumerable array, ArrayParsingStyle style) + { + String line = String.Empty; + + List<Object> list = new List<object>(); + + foreach (var item in array) + { + list.Add(item); + } + + if (style == ArrayParsingStyle.Comma) + { + line = String.Join(", ", list.Select(x => x.ToStringSafe())); + } + else + { + foreach (var item in list) + { + line += $"[{item.ToStringSafe()}] "; + } + } + + WriteLine(line); + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs index de1dfc50b..cc5cdfdc7 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs @@ -143,6 +143,14 @@ namespace Tango.FSE.Stubs.ViewModels set { _isPublishPanelOpened = value; RaisePropertyChangedAuto(); } } + private List<CreateGroup> _createGroups; + public List<CreateGroup> CreateGroups + { + get { return _createGroups; } + set { _createGroups = value; RaisePropertyChangedAuto(); } + } + + #endregion #region Commands @@ -170,6 +178,7 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand UnPublishProjectCommand { get; set; } public RelayCommand TogglePublishPanelCommand { get; set; } public RelayCommand<Script> RenameLibraryCommand { get; set; } + public RelayCommand<CreateItem> CreateItemCommand { get; set; } #endregion @@ -213,6 +222,85 @@ namespace Tango.FSE.Stubs.ViewModels UnPublishProjectCommand = new RelayCommand(UnPublishProject); TogglePublishPanelCommand = new RelayCommand(() => IsPublishPanelOpened = !IsPublishPanelOpened); RenameLibraryCommand = new RelayCommand<Script>(RenameLibrary); + CreateItemCommand = new RelayCommand<CreateItem>(AutoCreateItem); + } + + #endregion + + #region Auto Creation + + private void InitCreateGroups() + { + var groups = new List<CreateGroup>(); + + 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)) + { + CreateGroup group = new CreateGroup(); + group.Name = typesGroup.First().Namespace.Split('.').Last(); + + foreach (var type in typesGroup) + { + group.Items.Add(new CreateItem() + { + Name = type.Name, + Type = type, + }); + } + + groups.Add(group); + } + + CreateGroups = groups; + } + + private void AutoCreateItem(CreateItem item) + { + if (item != null) + { + try + { + String code = String.Empty; + FormatProperties(item.Type, ref code); + View.InsertCode(code); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error generating code for {item.Type.Name}."); + NotificationProvider.ShowError($"Error generating code for {item.Type.Name}."); + } + } + } + + 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; + } + } } #endregion @@ -224,6 +312,18 @@ namespace Tango.FSE.Stubs.ViewModels _compileTimer = new System.Timers.Timer(2000); _compileTimer.Elapsed += _compileTimer_Tick; _compileTimer.Start(); + + Task.Factory.StartNew(() => + { + try + { + InitCreateGroups(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error generating test designer auto creation groups."); + } + }); } public override void OnNavigatedTo() diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml index 361e5c186..97f8cea6b 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml @@ -119,6 +119,19 @@ </MenuItem.Icon> </MenuItem> </MenuItem> + <MenuItem Header="_Wizard" ItemsSource="{Binding CreateGroups}"> + <MenuItem.ItemContainerStyle> + <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}"> + <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 global:CreateItem}" ItemsSource="{Binding Path=Items}"> + <TextBlock Text="{Binding Name}"/> + </HierarchicalDataTemplate> + </MenuItem.ItemTemplate> + </MenuItem> <MenuItem Header="Publish"> <MenuItem Header="_Publish Project" InputGestureText="Ctrl+P" Command="{Binding TogglePublishPanelCommand}" MinWidth="250"> <MenuItem.Icon> @@ -376,7 +389,52 @@ <editors:ScriptEditor ReferenceAssemblies="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.LoadedAssemblies}" AdditionalScripts="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.Project.AdditionalScripts}" - Code="{Binding Code,Mode=TwoWay}" /> + Code="{Binding Code,Mode=TwoWay}"> + + <editors:ScriptEditor.ContextMenu> + <ContextMenu> + <MenuItem Header="_Cut" Command="Cut"> + <MenuItem.Icon> + <material:PackIcon Kind="ContentCut" /> + </MenuItem.Icon> + </MenuItem> + <MenuItem Header="_Copy" Command="Copy"> + <MenuItem.Icon> + <material:PackIcon Kind="ContentCopy" /> + </MenuItem.Icon> + </MenuItem> + <MenuItem Header="_Paste" Command="Paste"> + <MenuItem.Icon> + <material:PackIcon Kind="ContentPaste" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> + <MenuItem Header="_Format Code" InputGestureText="Ctrl+K+D" Command="{Binding Source={StaticResource proxy},Path=Data.FormatCodeCommand}"> + <MenuItem.Icon> + <material:PackIcon Kind="FormatColumns" /> + </MenuItem.Icon> + </MenuItem> + <Separator/> + <MenuItem Header="_Wizard" ItemsSource="{Binding Source={StaticResource proxy},Path=Data.CreateGroups}"> + <MenuItem.Icon> + <material:PackIcon Kind="Wand" /> + </MenuItem.Icon> + <MenuItem.ItemContainerStyle> + <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}"> + <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 global:CreateItem}" ItemsSource="{Binding Path=Items}"> + <TextBlock Text="{Binding Name}"/> + </HierarchicalDataTemplate> + </MenuItem.ItemTemplate> + </MenuItem> + </ContextMenu> + </editors:ScriptEditor.ContextMenu> + + </editors:ScriptEditor> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> @@ -392,7 +450,7 @@ <DockPanel> <Grid DockPanel.Dock="Top" Height="28" Background="{StaticResource FSE_PrimaryBackgroundBrush}"> <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" FontFamily="{StaticResource hand}">Output</TextBlock> - <controls:IconButton Height="32" Cursor="Hand" ToolTip="Clear" Width="32" Icon="DeleteEmpty" Foreground="{StaticResource FSE_GrayBrush}" HorizontalAlignment="Right" VerticalAlignment="Center" /> + <controls:IconButton Command="{Binding ClearOutputCommand}" Height="32" Cursor="Hand" ToolTip="Clear" Width="32" Icon="DeleteEmpty" Foreground="{StaticResource FSE_GrayBrush}" HorizontalAlignment="Right" VerticalAlignment="Center" /> <Rectangle VerticalAlignment="Bottom" Stroke="Black" StrokeThickness="2" /> </Grid> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs index 3636f7d50..b91ede833 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs @@ -53,5 +53,10 @@ namespace Tango.FSE.Stubs.Views { GetCurrentEditor()?.Highlight(position, length); } + + public void InsertCode(string code) + { + GetCurrentEditor()?.InsertCode(code); + } } } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index d7d72ec0b..2da7d3e46 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -2126,6 +2126,11 @@ namespace Tango.Scripting.Editors Select(position, Math.Max(length, 1)); } + public void InsertCode(String code) + { + Document.Insert(TextArea.Caret.Offset, code); + } + #endregion } } |
