From 9b7875d904456c34c3698d7fc569078f99ed5187 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 19 Apr 2020 23:12:56 +0300 Subject: Scripting refactoring. --- .../Scripting/Tango.Scripting.Basic/Script.cs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs new file mode 100644 index 000000000..aab22912d --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Scripting.Core; + +namespace Tango.Scripting.Basic +{ + public class Script : ExtendedObject, IScriptSource + { + public String Name { get; set; } + public String Code { get; set; } + public bool IsEntryPoint { get; set; } + + public static Script New(String file) + { + return new Script() + { + Name = Path.GetFileName(file), + Code = System.IO.File.ReadAllText(file), + }; + } + } +} -- cgit v1.3.1 From 17abbf35ba72283c6dab9135f1e75b7057371431 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 20 Apr 2020 07:22:48 +0300 Subject: Scripting.. --- .../FSE/Modules/Tango.FSE.Stubs/App.xaml | 2 + .../Tango.FSE.Stubs/Designer/ProjectModel.cs | 20 + .../Tango.FSE.Stubs/Designer/ScriptTabModel.cs | 22 ++ .../FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs | 69 ++++ .../Modules/Tango.FSE.Stubs/ProjectRunnerState.cs | 18 + .../Properties/Resources.Designer.cs | 64 ++-- .../Tango.FSE.Stubs/Properties/Resources.resx | 20 +- .../Tango.FSE.Stubs/Resources/lib_template.csx | 14 + .../Tango.FSE.Stubs/Resources/main_template.csx | 19 + .../Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj | 26 ++ .../Modules/Tango.FSE.Stubs/Themes/Generic.xaml | 403 +++++++++++++++++++++ .../Modules/Tango.FSE.Stubs/ViewModelLocator.cs | 18 + .../Tango.FSE.Stubs/ViewModels/MainViewVM.cs | 8 +- .../ViewModels/TestDesignerViewVM.cs | 121 +++++++ .../Tango.FSE.Stubs/ViewModels/TestRunnerViewVM.cs | 13 + .../Modules/Tango.FSE.Stubs/Views/MainView.xaml | 8 +- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 324 +++++++++++++++++ .../Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs | 38 ++ .../Tango.FSE.Stubs/Views/TestRunnerView.xaml | 14 + .../Tango.FSE.Stubs/Views/TestRunnerView.xaml.cs | 28 ++ .../FSE/Tango.FSE.Common/Resources/Colors.xaml | 25 ++ Software/Visual_Studio/FSE/Tango.FSE.UI/App.config | 16 +- .../FSE/Tango.FSE.UI/Tango.FSE.UI.csproj | 3 + .../Visual_Studio/FSE/Tango.FSE.UI/packages.config | 50 +++ .../Scripting/Tango.Scripting.Basic/Project.cs | 16 +- .../Tango.Scripting.Basic/ProjectSession.cs | 12 +- .../Tango.Scripting.Basic/ReferenceAssembly.cs | 5 + .../Scripting/Tango.Scripting.Basic/Script.cs | 21 +- .../Tango.Scripting.Editors/Intellisense/Utils.cs | 14 +- 29 files changed, 1361 insertions(+), 50 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ProjectModel.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ScriptTabModel.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunnerState.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/lib_template.csx create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/main_template.csx create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Themes/Generic.xaml create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestRunnerViewVM.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestRunnerView.xaml create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestRunnerView.xaml.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs') diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/App.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/App.xaml index 4261db47e..cf67bdbba 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/App.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/App.xaml @@ -10,6 +10,8 @@ + + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ProjectModel.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ProjectModel.cs new file mode 100644 index 000000000..b5208c008 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ProjectModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.FSE.Stubs.Designer +{ + public class ProjectModel : ExtendedObject + { + public ObservableCollection Scripts { get; set; } + + public ProjectModel() + { + Scripts = new ObservableCollection(); + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ScriptTabModel.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ScriptTabModel.cs new file mode 100644 index 000000000..4fba3213d --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Designer/ScriptTabModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Scripting.Basic; + +namespace Tango.FSE.Stubs.Designer +{ + public class ScriptTabModel : ExtendedObject + { + public Script Script { get; set; } + + private bool _isSelected; + public bool IsSelected + { + get { return _isSelected; } + set { _isSelected = value; RaisePropertyChangedAuto(); } + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs new file mode 100644 index 000000000..0625fa08f --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Scripting.Basic; + +namespace Tango.FSE.Stubs +{ + public class ProjectRunner : ExtendedObject + { + private ProjectSession _currentSession; + + private ProjectRunnerState _state; + public ProjectRunnerState State + { + get { return _state; } + private set { _state = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(IsRunning)); } + } + + public bool IsRunning + { + get { return State == ProjectRunnerState.Compiling || State == ProjectRunnerState.Running; } + } + + public Project Project { get; private set; } + + public ProjectRunner(Project project) + { + Project = project; + } + + public async Task Run() + { + if (State != ProjectRunnerState.Compiling && State != ProjectRunnerState.Running) + { + State = ProjectRunnerState.Compiling; + _currentSession = await Project.Run(null); + State = ProjectRunnerState.Running; + + try + { + var result = await _currentSession.WaitForCompletion(); + State = ProjectRunnerState.Completed; + return result; + } + catch (OperationCanceledException) + { + State = ProjectRunnerState.Aborted; + throw; + } + catch (Exception) + { + State = ProjectRunnerState.Failed; + throw; + } + } + + throw new InvalidOperationException("Project is already running."); + } + + public void Stop() + { + _currentSession.Abort(); + State = ProjectRunnerState.Aborted; + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunnerState.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunnerState.cs new file mode 100644 index 000000000..034426742 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunnerState.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Stubs +{ + public enum ProjectRunnerState + { + None, + Compiling, + Running, + Completed, + Failed, + Aborted +} +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.Designer.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.Designer.cs index 4d805d4c8..30aff0d9b 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.Designer.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace Tango.FSE.Stubs.Properties -{ - - +namespace Tango.FSE.Stubs.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,53 +19,65 @@ namespace Tango.FSE.Stubs.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.FSE.Stubs.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] lib_template { + get { + object obj = ResourceManager.GetObject("lib_template", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] main_template { + get { + object obj = ResourceManager.GetObject("main_template", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.resx b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.resx index af7dbebba..87094c4e4 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.resx +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,16 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\lib_template.csx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\main_template.csx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/lib_template.csx b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/lib_template.csx new file mode 100644 index 000000000..f3fd6b36a --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/lib_template.csx @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.FSE.Stubs; + +public class NewLibrary +{ + public double Calc(double a, double b) + { + return a + b; + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/main_template.csx b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/main_template.csx new file mode 100644 index 000000000..3d6c4f3b9 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Resources/main_template.csx @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.FSE.Stubs; + +public class Program +{ + public Object OnExecute(IContext context) + { + + return new + { + Item1 = "Item 1", + Item2 = "Item 2" + }; + } +} \ No newline at end of file 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 3222674ef..3e495564d 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 @@ -78,12 +78,24 @@ + + + + + + MainView.xaml + + TestDesignerView.xaml + + + TestRunnerView.xaml + @@ -109,6 +121,8 @@ SettingsSingleFileGenerator Settings.Designer.cs + + @@ -173,10 +187,22 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Themes/Generic.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Themes/Generic.xaml new file mode 100644 index 000000000..7d8801297 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Themes/Generic.xaml @@ -0,0 +1,403 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModelLocator.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModelLocator.cs index fe7ef42fa..6d151e5b8 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModelLocator.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModelLocator.cs @@ -13,6 +13,8 @@ namespace Tango.FSE.Stubs static ViewModelLocator() { TangoIOC.Default.Register(); + TangoIOC.Default.Register(); + TangoIOC.Default.Register(); } public static MainViewVM MainViewVM @@ -22,5 +24,21 @@ namespace Tango.FSE.Stubs return TangoIOC.Default.GetInstance(); } } + + public static TestRunnerViewVM TestRunnerViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } + + public static TestDesignerViewVM TestDesignerViewVM + { + get + { + return TangoIOC.Default.GetInstance(); + } + } } } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/MainViewVM.cs index 411335c02..02d2f8b53 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/MainViewVM.cs @@ -6,10 +6,12 @@ using System.Text; using System.Threading.Tasks; using Tango.FSE.Common; using Tango.FSE.Common.Navigation; +using Tango.FSE.Stubs.Views; using Tango.SharedUI.Helpers; namespace Tango.FSE.Stubs.ViewModels { + [NavigationContainer] public class MainViewVM : FSEViewModel { public override void OnApplicationStarted() @@ -18,7 +20,7 @@ namespace Tango.FSE.Stubs.ViewModels { NavigationManager.MenuItems.Add(new NavigationMenuItem(() => { - NavigationManager.NavigateTo(); + NavigationManager.NavigateTo(nameof(TestRunnerView)); }) { Name = "Test Runner", @@ -29,11 +31,11 @@ namespace Tango.FSE.Stubs.ViewModels NavigationManager.MenuItems.Add(new NavigationMenuItem(() => { - NavigationManager.NavigateTo(); + NavigationManager.NavigateTo(nameof(TestDesignerView)); }) { Name = "Test Designer", - Index = 6, + Index = 7, Description = "Create and test new test runner projects.", Image = ResourceHelper.GetImageFromResources("Images/test_designer.png"), }); 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 new file mode 100644 index 000000000..6544e643c --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs @@ -0,0 +1,121 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.Commands; +using Tango.FSE.Common; +using Tango.Integration.Operation; +using Tango.Scripting.Basic; +using Tango.Transport; + +namespace Tango.FSE.Stubs.ViewModels +{ + public class TestDesignerViewVM : FSEViewModel + { + private Project _project; + public Project Project + { + get { return _project; } + set { _project = value; RaisePropertyChangedAuto(); OnProjectChanged(); } + } + + private ProjectRunner _projectRunner; + public ProjectRunner ProjectRunner + { + get { return _projectRunner; } + set { _projectRunner = value; RaisePropertyChangedAuto(); } + } + + public ObservableCollection