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.Test/App.config | 6 + .../Scripting/Tango.Scripting.Test/App.xaml | 9 ++ .../Scripting/Tango.Scripting.Test/App.xaml.cs | 17 +++ .../Scripting/Tango.Scripting.Test/MainWindow.xaml | 38 ++++++ .../Tango.Scripting.Test/MainWindow.xaml.cs | 46 +++++++ .../Scripting/Tango.Scripting.Test/MainWindowVM.cs | 62 ++++++++++ .../Properties/AssemblyInfo.cs | 55 +++++++++ .../Properties/Resources.Designer.cs | 73 ++++++++++++ .../Tango.Scripting.Test/Properties/Resources.resx | 124 +++++++++++++++++++ .../Properties/Settings.Designer.cs | 30 +++++ .../Properties/Settings.settings | 7 ++ .../Tango.Scripting.Test/Resources/template.csx | 18 +++ .../Tango.Scripting.Test.csproj | 132 +++++++++++++++++++++ .../Scripting/Tango.Scripting.Test/lib.csx | 13 ++ 14 files changed, 630 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.config create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindowVM.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.Designer.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.resx create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.Designer.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.settings create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Resources/template.csx create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/Tango.Scripting.Test.csproj create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Test/lib.csx (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Test') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.config new file mode 100644 index 000000000..731f6de6c --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml new file mode 100644 index 000000000..731c7f907 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml.cs new file mode 100644 index 000000000..e1965607a --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.Scripting.Test +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml new file mode 100644 index 000000000..c1d784f10 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml.cs new file mode 100644 index 000000000..07958493d --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindow.xaml.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +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.Forms; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Scripting.Editors; + +namespace Tango.Scripting.Test +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + ScriptEditor.AssemblyCacheProgress += ScriptEditor_AssemblyCacheProgress; + ScriptEditor.LoadCachedAssemblies(new List() + { + typeof(String).Assembly, + typeof(Enumerable).Assembly, + typeof(Form).Assembly, + typeof(System.Drawing.Point).Assembly + }); + + InitializeComponent(); + DataContext = new MainWindowVM(); + } + + private void ScriptEditor_AssemblyCacheProgress(object sender, Tango.Core.TangoProgressChangedEventArgs e) + { + Debug.WriteLine(e.Progress.ToString()); + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindowVM.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindowVM.cs new file mode 100644 index 000000000..203196fda --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/MainWindowVM.cs @@ -0,0 +1,62 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Tango.Core.Commands; +using Tango.Scripting.Basic; +using Tango.SharedUI; + +namespace Tango.Scripting.Test +{ + public class MainWindowVM : ViewModel + { + public RelayCommand AddScriptCommand { get; set; } + public RelayCommand RunCommand { get; set; } + + private Project _project; + public Project Project + { + get { return _project; } + set { _project = value; RaisePropertyChangedAuto(); } + } + + public MainWindowVM() + { + Project = Project.New("untitled", Encoding.Default.GetString(Properties.Resources.template)); + AddScriptCommand = new RelayCommand(AddScriptFile); + RunCommand = new RelayCommand(RunProject); + } + + private void AddScriptFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Filter = "CSharp Script|*.csx"; + if (dlg.ShowDialog().Value) + { + AddScript(dlg.FileName); + } + } + + private void AddScript(String file) + { + Project.Scripts.Add(Script.New(file)); + } + + private async void RunProject() + { + var session = await Project.Run(null); + + session.StateChanged += (x, e) => + { + if (e.State == ProjectSessionState.Completed) + { + MessageBox.Show(e.ReturnValue.ToString()); + } + }; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f85cc741b --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.Scripting.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Scripting.Test")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.Designer.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.Designer.cs new file mode 100644 index 000000000..3cc3d2906 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.Test.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // 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", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + 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() { + } + + /// + /// 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 (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Tango.Scripting.Test.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 { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] template { + get { + object obj = ResourceManager.GetObject("template", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.resx b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.resx new file mode 100644 index 000000000..37de48988 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\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/Scripting/Tango.Scripting.Test/Properties/Settings.Designer.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.Designer.cs new file mode 100644 index 000000000..05e12ac76 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.Test.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.settings b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Resources/template.csx b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Resources/template.csx new file mode 100644 index 000000000..524b1bb24 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Resources/template.csx @@ -0,0 +1,18 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Tango.Scripting.Basic; + +public class Program +{ + public object OnExecute(IContext context) + { + + + return new + { + Item1 = "1", + Item2 = "2" + }; + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Tango.Scripting.Test.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Tango.Scripting.Test.csproj new file mode 100644 index 000000000..46c6d6453 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/Tango.Scripting.Test.csproj @@ -0,0 +1,132 @@ + + + + + Debug + AnyCPU + {564A30E2-E681-422A-9528-3E8CE301B837} + WinExe + Tango.Scripting.Test + Tango.Scripting.Test + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + True + True + Resources.resx + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + + Code + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {8491d07b-c1f6-4b62-a412-41b9fd2d6538} + Tango.SharedUI + + + {2b29a699-1d65-463a-8250-a2ce81d019c9} + Tango.Scripting.Basic + + + {5812e1c6-abaa-4066-94ac-971c27b4f46a} + Tango.Scripting.Core + + + {da62fa39-668b-47a6-b0f2-d2c1daf777b0} + Tango.Scripting.Editors + + + + + 4.7.0.9 + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Test/lib.csx b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/lib.csx new file mode 100644 index 000000000..bada6e745 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Test/lib.csx @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +public class MyClass +{ + public String Do() + { + return "Hi From Lib"; + } +} -- cgit v1.3.1 From 499e0a03bb41e2330a47ccca83e6e6dfe7c5a634 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 22 Apr 2020 02:08:25 +0300 Subject: Scripting. --- .../FSE/Modules/Tango.FSE.Stubs/ITestContext.cs | 6 + .../FSE/Modules/Tango.FSE.Stubs/ITestLogger.cs | 15 + .../FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs | 111 ++++--- .../Tango.FSE.Stubs/Resources/main_template.csx | 11 +- .../FSE/Modules/Tango.FSE.Stubs/Result.cs | 33 ++ .../FSE/Modules/Tango.FSE.Stubs/ResultType.cs | 15 + .../Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj | 4 + .../FSE/Modules/Tango.FSE.Stubs/TestContext.cs | 69 ++++- .../ViewModels/TestDesignerViewVM.cs | 162 +++++++++- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 111 ++++--- .../FSE/Tango.FSE.Common/FSEViewModel.cs | 7 + .../FSE/Tango.FSE.Common/Resources/Converters.xaml | 1 + .../Tango.Scripting.Basic/GlobalObject.cs | 4 +- .../Scripting/Tango.Scripting.Basic/Project.cs | 23 +- .../Tango.Scripting.Basic/ProjectManager.cs | 18 -- .../Tango.Scripting.Basic/ProjectSession.cs | 6 +- .../Tango.Scripting.Basic.csproj | 1 - .../Tango.Scripting.Editors/CachedUsing.cs | 20 ++ .../Tango.Scripting.Editors/Images/event.png | Bin 0 -> 210 bytes .../Intellisense/EventCompletionItem.cs | 22 ++ .../Intellisense/KnownType.cs | 24 +- .../Intellisense/KnownTypeEvent.cs | 21 ++ .../Tango.Scripting.Editors/ScriptEditor.cs | 334 ++++++++++++++++----- .../Tango.Scripting.Editors.csproj | 8 +- .../Tango.Scripting.Editors/Themes/Generic.xaml | 3 + .../Tango.Scripting.Test/MainWindow.xaml.cs | 9 +- .../Scripting/Tango.Scripting.Test/MainWindowVM.cs | 13 +- .../Converters/EnumToIntConverter.cs | 23 ++ .../Tango.SharedUI/Tango.SharedUI.csproj | 3 +- 29 files changed, 855 insertions(+), 222 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestLogger.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ResultType.cs delete mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectManager.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedUsing.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Images/event.png create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs create mode 100644 Software/Visual_Studio/Tango.SharedUI/Converters/EnumToIntConverter.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Test') 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 671b2174a..41b13f2d2 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs @@ -1,6 +1,7 @@ using Google.Protobuf; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,6 +12,11 @@ namespace Tango.FSE.Stubs { public interface ITestContext : IContext { + ReadOnlyCollection Results { get; } + Result AddResult(ResultType type, String name, object value); + Result AddResult(Result result); + void RemoveResult(Result result); + void ClearResults(); IMessage Run(String stubName, params Object[] args); IMessage Run(IMessage stub); void RunContinuous(T stub, Action callback) where T : class, IMessage; diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestLogger.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestLogger.cs new file mode 100644 index 000000000..286bc07ea --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestLogger.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Stubs +{ + public interface ITestLogger + { + void WriteLine(String text); + void Write(String text); + void Clear(); + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs index 00ab0caca..de93305d8 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs @@ -10,63 +10,104 @@ namespace Tango.FSE.Stubs { public class ProjectRunner : ExtendedObject { - private ProjectSession _currentSession; + private ProjectSession _currentSession; private ProjectRunnerState _state; public ProjectRunnerState State { get { return _state; } - private set { _state = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(IsRunning)); } + private set + { + _state = value; + RaisePropertyChangedAuto(); + RaisePropertyChanged(nameof(IsRunning)); + RaisePropertyChanged(nameof(IsCompiling)); + RaisePropertyChanged(nameof(CanRun)); + RaisePropertyChanged(nameof(CanCompile)); + } } public bool IsRunning { - get { return State == ProjectRunnerState.Compiling || State == ProjectRunnerState.Running; } + get { return State == ProjectRunnerState.Running; } + } + + public bool IsCompiling + { + get { return State == ProjectRunnerState.Compiling; } } - public Project Project { get; private set; } + public bool CanCompile + { + get { return State != ProjectRunnerState.Running && State != ProjectRunnerState.Compiling; } + } - public ProjectRunner(Project project) + public bool CanRun + { + get { return State != ProjectRunnerState.Running && State != ProjectRunnerState.Compiling; } + } + + public Project Project { get; private set; } + + public ProjectRunner(Project project) { Project = project; } - public async Task Run() + public async Task Compile() { - if (State != ProjectRunnerState.Compiling && State != ProjectRunnerState.Running) + try + { + State = ProjectRunnerState.Compiling; + var result = await Project.Compile(); + State = ProjectRunnerState.None; + return result; + } + catch (Exception) + { + throw; + } + finally { - try - { - State = ProjectRunnerState.Compiling; - _currentSession = await Project.Run(null); - } - catch (Exception ex) - { - State = ProjectRunnerState.None; - throw ex; - } + State = ProjectRunnerState.None; + } + } - State = ProjectRunnerState.Running; + public async Task Run(TestContext context) + { + if (!CanRun) + { + throw new InvalidOperationException("Project is already running."); + } - try - { - var result = await _currentSession.WaitForCompletion(); - State = ProjectRunnerState.Completed; - return result; - } - catch (OperationCanceledException) - { - State = ProjectRunnerState.Aborted; - throw; - } - catch (Exception) - { - State = ProjectRunnerState.Failed; - throw; - } + try + { + State = ProjectRunnerState.Compiling; + _currentSession = await Project.Run(context); + } + catch (Exception ex) + { + State = ProjectRunnerState.None; + throw ex; } - throw new InvalidOperationException("Project is already running."); + State = ProjectRunnerState.Running; + + try + { + var result = await _currentSession.WaitForCompletion(); + State = ProjectRunnerState.Completed; + } + catch (OperationCanceledException) + { + State = ProjectRunnerState.Aborted; + throw; + } + catch (Exception) + { + State = ProjectRunnerState.Failed; + throw; + } } public void Stop() 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 index 34604c6d3..c50f70c5f 100644 --- 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 @@ -1,19 +1,18 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.FSE.Stubs; public class Program { - public Object OnExecute(ITestContext context) + public void OnExecute(ITestContext context) { - return new - { - Item1 = "Item 1", - Item2 = "Item 2" - }; + context.AddResult(ResultType.Passed, "My Value Name", "Test for this value has passed."); + } } \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs new file mode 100644 index 000000000..74f95a437 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Result.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.ExtensionMethods; + +namespace Tango.FSE.Stubs +{ + public class Result + { + public ResultType Type { get; set; } + public String Name { get; set; } + public Object Value { get; set; } + + public Result() + { + + } + + public Result(ResultType type, String name, Object value) : this() + { + Type = type; + Name = name; + Value = value; + } + + public override string ToString() + { + return this.ToJsonString(); + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ResultType.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ResultType.cs new file mode 100644 index 000000000..e19f58b4f --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ResultType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Stubs +{ + public enum ResultType + { + Passed, + Failed, + Warning, + } +} 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 9058bf074..faf3615be 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 @@ -61,6 +61,7 @@ + ..\..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll @@ -97,8 +98,11 @@ + + + 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 e40ccebfc..83823a27c 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Reflection; using System.Text; @@ -7,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Google.Protobuf; using Tango.Core.DI; +using Tango.FSE.Common.Connection; using Tango.FSE.Common.Notifications; using Tango.FSE.Common.Threading; using Tango.Integration.Operation; @@ -17,15 +20,23 @@ namespace Tango.FSE.Stubs { public class TestContext : ITestContext { - private IMachineOperator _machineOperator; - private INotificationProvider _notificationProvider; - private IDispatcherProvider _dispatcherProvider; + private ITestLogger _logger; - public TestContext(IMachineOperator machineOperator, INotificationProvider notificationProvider, IDispatcherProvider dispatcherProvider) + [TangoInject] + private IMachineProvider MachineProvider; + + [TangoInject] + private INotificationProvider NotificationProvider { get; set; } + + [TangoInject] + private IDispatcherProvider DispatcherProvider { get; set; } + + public ReadOnlyCollection Results { get; private set; } + + public TestContext(ITestLogger logger) { - _machineOperator = machineOperator; - _notificationProvider = notificationProvider; - _dispatcherProvider = dispatcherProvider; + _logger = logger; + Results = new ReadOnlyCollection(new List()); } public IMessage Run(string stubName, params object[] args) @@ -74,14 +85,14 @@ namespace Tango.FSE.Stubs public IMessage Run(IMessage stub) { - return _machineOperator.SendRequest(stub, new Transport.TransportRequestConfig()).Result; + return MachineProvider.MachineOperator.SendRequest(stub, new Transport.TransportRequestConfig()).Result; } public void RunContinuous(T stub, Action callback) where T : class, IMessage { Type stubType = stub.GetType(); - _machineOperator.SendContinuousRequest(stub, new Transport.TransportContinuousRequestConfig()).Subscribe((msg) => + MachineProvider.MachineOperator.SendContinuousRequest(stub, new Transport.TransportContinuousRequestConfig()).Subscribe((msg) => { callback?.Invoke(msg as T); @@ -143,37 +154,63 @@ namespace Tango.FSE.Stubs public void WriteLine(object obj) { - throw new NotImplementedException(); + _logger?.WriteLine(obj != null ? obj.ToString() : "null"); } public void Write(object obj) { - throw new NotImplementedException(); + _logger?.Write(obj != null ? obj.ToString() : "null"); } public void WriteLineHex(object number, int digits) { - throw new NotImplementedException(); + _logger?.WriteLine("#" + Convert.ToInt32(number).ToString("X" + digits.ToString())); } public void WriteHex(object number, int digits) { - throw new NotImplementedException(); + _logger?.Write("#" + Convert.ToInt32(number).ToString("X" + digits.ToString())); } public void Clear() { - throw new NotImplementedException(); + _logger?.Clear(); } public void WriteToFile(string filePath, string content) { - throw new NotImplementedException(); + File.WriteAllText(filePath, content); } public void AppendToFile(string filePath, string content) { - throw new NotImplementedException(); + File.AppendAllText(filePath, content); + } + + public Result AddResult(ResultType type, string name, object value) + { + var result = new Result(type, name, value); + return AddResult(result); + } + + public Result AddResult(Result result) + { + List results = new List(Results); + results.Add(result); + Results = new ReadOnlyCollection(results); + return result; + } + + public void RemoveResult(Result result) + { + List results = new List(Results); + results.Remove(result); + Results = new ReadOnlyCollection(results); + } + + public void ClearResults() + { + Results = new ReadOnlyCollection(new List()); } } } 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 6e6873c9a..d87fe0ff3 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 @@ -5,18 +5,38 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Input; +using Tango.Core; using Tango.Core.Commands; +using Tango.Core.ExtensionMethods; using Tango.FSE.Common; using Tango.Integration.Operation; using Tango.Scripting.Basic; +using Tango.Scripting.Editors; +using Tango.SharedUI.Components; +using Tango.SharedUI.Helpers; using Tango.Transport; namespace Tango.FSE.Stubs.ViewModels { - public class TestDesignerViewVM : FSEViewModel + public class TestDesignerViewVM : FSEViewModel, ITestLogger { - private Project _project; - public Project Project + public enum ToolWindows + { + Output, + Errors, + Results + } + + private ToolWindows _selectedToolWindow; + public ToolWindows SelectedToolWindow + { + get { return _selectedToolWindow; } + set { _selectedToolWindow = value; RaisePropertyChangedAuto(); } + } + + private Project _project; + public Project Project { get { return _project; } set { _project = value; RaisePropertyChangedAuto(); OnProjectChanged(); } @@ -29,6 +49,13 @@ namespace Tango.FSE.Stubs.ViewModels set { _projectRunner = value; RaisePropertyChangedAuto(); } } + private List _compilationErrors; + public List CompilationErrors + { + get { return _compilationErrors; } + set { _compilationErrors = value; RaisePropertyChangedAuto(); } + } + public ObservableCollection