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/IContext.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs new file mode 100644 index 000000000..906047c2a --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Basic +{ + public interface IContext + { + void WriteLine(String s); + } +} -- cgit v1.3.1 From f06785ae3312a82b8f2237b55e8c4eeb174c3519 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 20 Apr 2020 23:28:38 +0300 Subject: Scripting. --- .../ConsoleApp8/ConsoleApp8/lib_template.csx | 14 ++ .../ConsoleApp8/ConsoleApp8/main_template.csx | 16 ++ .../FSE/Modules/Tango.FSE.Stubs/ITestContext.cs | 26 +++ .../FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs | 15 +- .../Tango.FSE.Stubs/Resources/main_template.csx | 2 +- .../Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj | 22 ++- .../FSE/Modules/Tango.FSE.Stubs/TestContext.cs | 179 +++++++++++++++++++++ .../ViewModels/TestDesignerViewVM.cs | 3 +- .../FSE/Modules/Tango.FSE.Stubs/packages.config | 6 + Software/Visual_Studio/FSE/Tango.FSE.UI/App.config | 8 +- .../FSE/Tango.FSE.UI/Tango.FSE.UI.csproj | 94 +++++++++-- .../Visual_Studio/FSE/Tango.FSE.UI/packages.config | 48 ++++++ .../Scripting/Tango.Scripting.Basic/IContext.cs | 2 +- .../Scripting/Tango.Scripting.Basic/Project.cs | 29 ++-- .../Scripting/Tango.Scripting.Basic/Script.cs | 5 +- 15 files changed, 431 insertions(+), 38 deletions(-) create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib_template.csx create mode 100644 Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main_template.csx create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs') diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib_template.csx b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib_template.csx new file mode 100644 index 000000000..93c79d32f --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/lib_template.csx @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +public class lib +{ + public void Show(String msg) + { + MessageBox.Show(msg); + } +} diff --git a/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main_template.csx b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main_template.csx new file mode 100644 index 000000000..61d086068 --- /dev/null +++ b/Software/Experiments/RoslynTest/ConsoleApp8/ConsoleApp8/main_template.csx @@ -0,0 +1,16 @@ +#load "lib.csx" + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConsoleApp8; + +public TestResult OnExecute(String msg) +{ + lib l = new lib(); + l.Show(msg); + + return new TestResult() { Value = "This is a return value" }; +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs new file mode 100644 index 000000000..671b2174a --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ITestContext.cs @@ -0,0 +1,26 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Integration.Operation; +using Tango.Scripting.Basic; + +namespace Tango.FSE.Stubs +{ + public interface ITestContext : IContext + { + IMessage Run(String stubName, params Object[] args); + IMessage Run(IMessage stub); + void RunContinuous(T stub, Action callback) where T : class, IMessage; + void RunContinuous(String stubName, Action callback, params Object[] args) where T : class, IMessage; + void WriteLine(Object obj); + void Write(Object obj); + void WriteLineHex(Object number, int digits); + void WriteHex(Object number, int digits); + void Clear(); + void WriteToFile(String filePath, String content); + void AppendToFile(String filePath, String content); + } +} 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 0625fa08f..00ab0caca 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs @@ -35,8 +35,17 @@ namespace Tango.FSE.Stubs { if (State != ProjectRunnerState.Compiling && State != ProjectRunnerState.Running) { - State = ProjectRunnerState.Compiling; - _currentSession = await Project.Run(null); + try + { + State = ProjectRunnerState.Compiling; + _currentSession = await Project.Run(null); + } + catch (Exception ex) + { + State = ProjectRunnerState.None; + throw ex; + } + State = ProjectRunnerState.Running; try @@ -62,7 +71,7 @@ namespace Tango.FSE.Stubs public void Stop() { - _currentSession.Abort(); + _currentSession?.Abort(); State = ProjectRunnerState.Aborted; } } 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 3d6c4f3b9..34604c6d3 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 @@ -7,7 +7,7 @@ using Tango.FSE.Stubs; public class Program { - public Object OnExecute(IContext context) + public Object OnExecute(ITestContext context) { return new 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 3e495564d..9058bf074 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,22 @@ + + ..\..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll + + + ..\..\..\packages\System.Reactive.Interfaces.3.1.1\lib\net45\System.Reactive.Interfaces.dll + + + ..\..\..\packages\System.Reactive.Linq.3.1.1\lib\net46\System.Reactive.Linq.dll + + + ..\..\..\packages\System.Reactive.PlatformServices.3.1.1\lib\net46\System.Reactive.PlatformServices.dll + + + ..\..\..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll + + ..\..\..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll @@ -80,8 +96,10 @@ + + @@ -115,7 +133,9 @@ ResXFileCodeGenerator Resources.Designer.cs - + + Designer + SettingsSingleFileGenerator diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs new file mode 100644 index 000000000..e40ccebfc --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestContext.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Google.Protobuf; +using Tango.Core.DI; +using Tango.FSE.Common.Notifications; +using Tango.FSE.Common.Threading; +using Tango.Integration.Operation; +using Tango.PMR; +using Tango.Scripting.Basic; + +namespace Tango.FSE.Stubs +{ + public class TestContext : ITestContext + { + private IMachineOperator _machineOperator; + private INotificationProvider _notificationProvider; + private IDispatcherProvider _dispatcherProvider; + + public TestContext(IMachineOperator machineOperator, INotificationProvider notificationProvider, IDispatcherProvider dispatcherProvider) + { + _machineOperator = machineOperator; + _notificationProvider = notificationProvider; + _dispatcherProvider = dispatcherProvider; + } + + public IMessage Run(string stubName, params object[] args) + { + var stubType = MessageFactory.GetAvailableRequestStubs().SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower()); + if (stubType == null) + { + throw new ArgumentException("Invalid stub '" + stubName + "'."); + } + + var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance); + + if (stubProps.Length > args.Length) + { + throw new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + "."); + } + + Object request = Activator.CreateInstance(stubType); + + int argIndex = 0; + foreach (var prop in stubProps) + { + Object arg = args[argIndex++]; + + if (prop.PropertyType == typeof(UInt32)) + { + prop.SetValue(request, UInt32.Parse(arg.ToString())); + } + else if (prop.PropertyType == typeof(bool)) + { + prop.SetValue(request, bool.Parse(arg.ToString())); + } + else if (prop.PropertyType.IsPrimitive) + { + object converted = Convert.ChangeType(arg, prop.PropertyType); + prop.SetValue(request, converted); + } + else + { + prop.SetValue(request, arg); + } + } + + return Run(request as IMessage); + } + + public IMessage Run(IMessage stub) + { + return _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) => + { + callback?.Invoke(msg as T); + + //Next + }, (ex) => + { + //OnFailed(ex); + //Error + }, () => + { + //OnCompleted("Continuous request completed."); + //Completed + }); + } + + public void RunContinuous(string stubName, Action callback, params object[] args) where T : class, IMessage + { + var stubType = MessageFactory.GetAvailableRequestStubs().SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower()); + if (stubType == null) + { + throw new ArgumentException("Invalid stub '" + stubName + "'."); + } + + var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance); + + if (stubProps.Length > args.Length) + { + throw new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + "."); + } + + IMessage request = Activator.CreateInstance(stubType) as IMessage; + + int argIndex = 0; + foreach (var prop in stubProps) + { + Object arg = args[argIndex++]; + + if (prop.PropertyType == typeof(UInt32)) + { + prop.SetValue(request, UInt32.Parse(arg.ToString())); + } + else if (prop.PropertyType == typeof(bool)) + { + prop.SetValue(request, bool.Parse(arg.ToString())); + } + else if (prop.PropertyType.IsPrimitive) + { + object converted = Convert.ChangeType(arg, prop.PropertyType); + prop.SetValue(request, converted); + } + else + { + prop.SetValue(request, arg); + } + } + + RunContinuous(request, callback as Action); + } + + public void WriteLine(object obj) + { + throw new NotImplementedException(); + } + + public void Write(object obj) + { + throw new NotImplementedException(); + } + + public void WriteLineHex(object number, int digits) + { + throw new NotImplementedException(); + } + + public void WriteHex(object number, int digits) + { + throw new NotImplementedException(); + } + + public void Clear() + { + throw new NotImplementedException(); + } + + public void WriteToFile(string filePath, string content) + { + throw new NotImplementedException(); + } + + public void AppendToFile(string filePath, string content) + { + throw new NotImplementedException(); + } + } +} 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 6544e643c..6e6873c9a 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 @@ -95,7 +95,8 @@ namespace Tango.FSE.Stubs.ViewModels private void CreateNewProject() { - var project = Project.New("test1", Encoding.UTF8.GetString(Properties.Resources.main_template)); + var project = Project.New("test1"); + project.Scripts.Add(Script.New("Program.csx", Encoding.UTF8.GetString(Properties.Resources.main_template), true)); project.Scripts.Add(Script.New("lib.csx", Encoding.UTF8.GetString(Properties.Resources.lib_template))); project.ReferenceAssemblies.Add(new ReferenceAssembly() { FromType = this.GetType() }); project.ReferenceAssemblies.Add(new ReferenceAssembly() { FromType = typeof(PMR.Common.MessageType) }); diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/packages.config b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/packages.config index dd8c723e4..d17a56d7d 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/packages.config +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/packages.config @@ -7,4 +7,10 @@ + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/App.config b/Software/Visual_Studio/FSE/Tango.FSE.UI/App.config index 7718ac028..291f23910 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/App.config +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/App.config @@ -1,9 +1,9 @@  - +
- + @@ -11,7 +11,7 @@ - + @@ -81,7 +81,7 @@ - + diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj b/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj index 6f37af1a0..72b4bf121 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Tango.FSE.UI.csproj @@ -68,6 +68,18 @@ ..\..\packages\MaterialDesignThemes.3.0.1\lib\net45\MaterialDesignThemes.Wpf.dll + + ..\..\packages\Microsoft.CodeAnalysis.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + + ..\..\packages\Microsoft.CodeAnalysis.CSharp.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + + ..\..\packages\Microsoft.CodeAnalysis.CSharp.Scripting.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Scripting.dll + + + ..\..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll + ..\..\packages\WindowsAPICodePack-Core.1.1.1\lib\Microsoft.WindowsAPICodePack.dll @@ -78,13 +90,38 @@ ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + ..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + ..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll + + + ..\..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll + + + ..\..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll + - + + ..\..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + + + ..\..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + ..\..\packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll @@ -100,6 +137,30 @@ ..\..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll + + ..\..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll + + + ..\..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + ..\..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll + + + ..\..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll + + + ..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll + @@ -114,6 +175,18 @@ 4.0 + + ..\..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + + + ..\..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll + + + ..\..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll + + + ..\..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll + @@ -535,15 +608,11 @@ - + + + + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - RD /S /Q "$(TargetDir)cs\" RD /S /Q "$(TargetDir)da\" @@ -602,4 +671,11 @@ if $(ConfigurationName) == Release del *.xml if $(ConfigurationName) == Release RD /S /Q "$(TargetDir)ProtoCompilers\" if $(ConfigurationName) == Release RD /S /Q "$(TargetDir)Roslyn\" + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/packages.config b/Software/Visual_Studio/FSE/Tango.FSE.UI/packages.config index 54a423b24..9bec9f247 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/packages.config +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/packages.config @@ -9,13 +9,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs index 906047c2a..d817c5d46 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/IContext.cs @@ -8,6 +8,6 @@ namespace Tango.Scripting.Basic { public interface IContext { - void WriteLine(String s); + } } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs index ff7a3acc2..31be3a714 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs @@ -78,7 +78,7 @@ namespace Tango.Scripting.Basic } } - public static Project New(String name, String code) + public static Project New(String name) { Project p = new Project(); @@ -88,14 +88,6 @@ namespace Tango.Scripting.Basic p.ReferenceAssemblies.Add(new ReferenceAssembly() { FromType = typeof(Enumerable) }); p.ReferenceAssemblies.Add(new ReferenceAssembly() { FromType = typeof(Form) }); p.ReferenceAssemblies.Add(new ReferenceAssembly() { FromType = typeof(Project) }); - - p.Scripts.Add(new Script() - { - Name = name, - IsEntryPoint = true, - Code = code, - }); - return p; } @@ -111,6 +103,7 @@ namespace Tango.Scripting.Basic foreach (var script in Scripts) { + script.LoadCount = 0; String code = script.Code; String codeFile = Path.Combine(tempFolder, script.Name); @@ -119,14 +112,14 @@ namespace Tango.Scripting.Basic foreach (var file in Scripts.Where(x => !x.IsEntryPoint && script != x).Select(x => Path.Combine(tempFolder, x.Name))) { loadingString = $"#load \"{file}\"\n"; + script.LoadCount++; } code = loadingString + code; if (!script.IsEntryPoint) { - - + //In case we use #load //foreach (var match in Regex.Matches(code, "#load \".+\"").OfType()) //{ // String line = match.ToString(); @@ -143,9 +136,6 @@ namespace Tango.Scripting.Basic // } // } //} - - - File.WriteAllText(codeFile, code); } else @@ -162,14 +152,19 @@ namespace Tango.Scripting.Basic var compileResults = s.Compile(); - foreach (var error in compileResults.Where(x => x.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Error || x.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Warning)) + foreach (var error in compileResults.Where(x => x.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Error)) { CompilationError cError = new CompilationError(); cError.File = System.IO.Path.GetFileName(error.Location.SourceTree.FilePath); + if (cError.File == String.Empty) + { + cError.File = Scripts.Single(x => x.IsEntryPoint).Name; + } + Script errorScript = Scripts.Single(x => x.Name == cError.File); cError.Message = error.GetMessage(); cError.Severity = error.Severity; var line = error.Location.GetMappedLineSpan(); - cError.Line = line.StartLinePosition.Line + 1; + cError.Line = line.StartLinePosition.Line + 1 + (errorScript != null ? errorScript.LoadCount : 0); cError.Column = line.StartLinePosition.Character + 1; cError.Length = line.EndLinePosition.Character - line.StartLinePosition.Character; result.Errors.Add(cError); @@ -185,7 +180,7 @@ namespace Tango.Scripting.Basic if (result.Errors.Count > 0) { - throw new InvalidOperationException("There were compilation errors."); + throw new InvalidOperationException($"Cannot run project with the following compilation errors:\n{String.Join(Environment.NewLine, result.Errors.Select(x => x.Message))}"); } Thread scriptThread = null; diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs index fce05636d..753026149 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Script.cs @@ -24,6 +24,8 @@ namespace Tango.Scripting.Basic set { _isSelected = value; RaisePropertyChangedAuto(); } } + [JsonIgnore] + public int LoadCount { get; internal set; } public static Script New(String file) { @@ -34,12 +36,13 @@ namespace Tango.Scripting.Basic }; } - public static Script New(String name, String code) + public static Script New(String name, String code, bool isEntryPoint = false) { return new Script() { Name = name, Code = code, + IsEntryPoint = isEntryPoint, }; } } -- cgit v1.3.1