diff options
Diffstat (limited to 'Software/Visual_Studio/Scripting')
48 files changed, 2134 insertions, 33 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/CompilationError.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/CompilationError.cs new file mode 100644 index 000000000..27c710b2f --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/CompilationError.cs @@ -0,0 +1,19 @@ +using Microsoft.CodeAnalysis; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Basic +{ + public class CompilationError + { + public String File { get; set; } + public String Message { get; set; } + public DiagnosticSeverity Severity { get; set; } + public int Line { get; set; } + public int Column { get; set; } + public int Length { get; set; } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/CompilationResult.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/CompilationResult.cs new file mode 100644 index 000000000..d3676acc0 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/CompilationResult.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core.IO; + +namespace Tango.Scripting.Basic +{ + public class CompilationResult + { + public List<CompilationError> Errors { get; set; } + public TemporaryFolder TemporaryProjectPath { get; set; } + public Microsoft.CodeAnalysis.Scripting.Script Script { get; set; } + + public CompilationResult() + { + Errors = new List<CompilationError>(); + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/GlobalObject.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/GlobalObject.cs new file mode 100644 index 000000000..fc48bb2a2 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/GlobalObject.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 class GlobalObject + { + public IContext GlobalContext { get; set; } + } +} 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); + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs new file mode 100644 index 000000000..ddf61e124 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs @@ -0,0 +1,211 @@ +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.Scripting; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using Tango.Core; +using Tango.Core.IO; +using Tango.Scripting.Core; +using System.IO; + +namespace Tango.Scripting.Basic +{ + public class Project : ExtendedObject + { + public String Name { get; set; } + + public ApartmentState ApartmentState { get; set; } + + public ObservableCollection<ReferenceAssembly> ReferenceAssemblies { get; set; } + + [JsonIgnore] + public ObservableCollection<Assembly> ReferenceAssembliesLoaded { get; set; } + + public ObservableCollection<Script> Scripts { get; set; } + + public ObservableCollection<IScriptSource> AdditionalScripts + { + get + { + return Scripts.Where(x => !x.IsEntryPoint).Cast<IScriptSource>().ToObservableCollection(); + } + } + + public Project() + { + ApartmentState = ApartmentState.MTA; + + ReferenceAssemblies = new ObservableCollection<ReferenceAssembly>(); + ReferenceAssemblies.CollectionChanged += ReferenceAssemblies_CollectionChanged; + + ReferenceAssembliesLoaded = new ObservableCollection<Assembly>(); + Scripts = new ObservableCollection<Script>(); + Scripts.CollectionChanged += (x, e) => { RaisePropertyChanged(nameof(AdditionalScripts)); }; + } + + private void ReferenceAssemblies_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + LoadReferenceAssemblies(); + } + + private void LoadReferenceAssemblies() + { + ReferenceAssembliesLoaded.Clear(); + + foreach (var type in ReferenceAssemblies) + { + ReferenceAssembliesLoaded.Add(type.FromType.Assembly); + } + } + + public static Project New(String name, String code) + { + Project p = new Project(); + + p.Name = name; + + p.ReferenceAssemblies.Add(new ReferenceAssembly() { FromType = typeof(String) }); + 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 = "main.csx", + IsEntryPoint = true, + Code = code, + }); + + return p; + } + + public Task<CompilationResult> Compile() + { + return Task.Factory.StartNew<CompilationResult>(() => + { + var result = new CompilationResult(); + var tempFolder = TemporaryManager.CreateFolder(Name); + result.TemporaryProjectPath = tempFolder; + + String mainScriptCode = String.Empty; + + foreach (var script in Scripts) + { + String code = script.Code; + String codeFile = Path.Combine(tempFolder, script.Name); + + String loadingString = String.Empty; + + foreach (var file in Scripts.Where(x => !x.IsEntryPoint && script != x).Select(x => Path.Combine(tempFolder, x.Name))) + { + loadingString = $"#load \"{file}\"\n"; + } + + code = loadingString + code; + + if (!script.IsEntryPoint) + { + + + //foreach (var match in Regex.Matches(code, "#load \".+\"").OfType<Match>()) + //{ + // String line = match.ToString(); + // var pathMatch = Regex.Match(line, "(?<=\")(.*?)(?=\")"); + // if (pathMatch.Success) + // { + // String path = pathMatch.ToString(); + + // if (!System.IO.Path.IsPathRooted(path)) + // { + // StringBuilder builder = new StringBuilder(code); + // builder.Insert(match.Index + pathMatch.Index, System.IO.Path.GetFullPath(tempFolder + "\\")); + // code = builder.ToString(); + // } + // } + //} + + + + File.WriteAllText(codeFile, code); + } + else + { + code += Environment.NewLine + Environment.NewLine + "return new Program().OnExecute(GlobalContext);"; + mainScriptCode = code; + } + } + + var scriptOptions = ScriptOptions.Default.WithReferences(ReferenceAssembliesLoaded); + + var s = CSharpScript.Create<object>(mainScriptCode, scriptOptions, typeof(GlobalObject)); + result.Script = s; + + var compileResults = s.Compile(); + + foreach (var error in compileResults.Where(x => x.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Error || x.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Warning)) + { + CompilationError cError = new CompilationError(); + cError.File = System.IO.Path.GetFileName(error.Location.SourceTree.FilePath); + cError.Message = error.GetMessage(); + cError.Severity = error.Severity; + var line = error.Location.GetMappedLineSpan(); + cError.Line = line.StartLinePosition.Line + 1; + cError.Column = line.StartLinePosition.Character + 1; + cError.Length = line.EndLinePosition.Character - line.StartLinePosition.Character; + result.Errors.Add(cError); + } + + return result; + }); + } + + public async Task<ProjectSession> Run(IContext context) + { + var result = await Compile(); + + if (result.Errors.Count > 0) + { + throw new InvalidOperationException("There were compilation errors."); + } + + Thread scriptThread = null; + ProjectSession session = null; + + session = new ProjectSession(this, () => + { + scriptThread.Abort(); + }); + + scriptThread = new Thread(() => + { + try + { + var runResult = result.Script.RunAsync(globals: new GlobalObject() { GlobalContext = context }).Result; + session.Completed(runResult.ReturnValue); + } + catch (ThreadAbortException) + { + + } + catch (Exception ex) + { + session.Failed(ex.InnerException); + } + }); + + scriptThread.SetApartmentState(ApartmentState); + scriptThread.IsBackground = true; + scriptThread.Start(); + + return session; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectManager.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectManager.cs new file mode 100644 index 000000000..3af7530bc --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectManager.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Basic +{ + public class ProjectManager + { + public Project Project { get; set; } + + public ProjectManager(Project project) + { + Project = project; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs new file mode 100644 index 000000000..a613f2bcc --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Basic +{ + public class ProjectSession + { + private Action _abortAction; + + public event EventHandler<ProjectSessionStateChangedEventArgs> StateChanged; + + public ProjectSessionState State { get; set; } + + public Project Project { get; set; } + + public ProjectSession(Project project, Action abortAction) + { + Project = project; + _abortAction = abortAction; + } + + public void Abort() + { + _abortAction(); + State = ProjectSessionState.Aborted; + RaiseStateChanged(); + } + + internal void Failed(Exception ex) + { + State = ProjectSessionState.Failed; + RaiseStateChanged(null, ex); + } + + internal void Completed(object returnValue) + { + State = ProjectSessionState.Completed; + RaiseStateChanged(returnValue, null); + } + + private void RaiseStateChanged(object returnValue = null, Exception ex = null) + { + StateChanged?.Invoke(this, + new ProjectSessionStateChangedEventArgs() + { + ReturnValue = returnValue, + State = State, + Exception = ex + }); + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSessionState.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSessionState.cs new file mode 100644 index 000000000..e47eecb8c --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSessionState.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Basic +{ + public enum ProjectSessionState + { + Running, + Completed, + Aborted, + Failed, + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSessionStateChangedEventArgs.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSessionStateChangedEventArgs.cs new file mode 100644 index 000000000..53ea96cd6 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSessionStateChangedEventArgs.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Basic +{ + public class ProjectSessionStateChangedEventArgs : EventArgs + { + public Object ReturnValue { get; set; } + + public ProjectSessionState State { get; set; } + + public Exception Exception { get; set; } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..20a020e63 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/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.Basic")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Scripting.Basic")] +[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 +//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file +//inside a <PropertyGroup>. For example, if you are using US english +//in your source files, set the <UICulture> 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.Basic/Properties/Resources.Designer.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Resources.Designer.cs new file mode 100644 index 000000000..97b6a82b6 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// 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. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.Basic.Properties { + using System; + + + /// <summary> + /// A strongly-typed resource class, for looking up localized strings, etc. + /// </summary> + // 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() { + } + + /// <summary> + /// Returns the cached ResourceManager instance used by this class. + /// </summary> + [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.Basic.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// <summary> + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// </summary> + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// <summary> + /// Looks up a localized resource of type System.Byte[]. + /// </summary> + internal static byte[] template { + get { + object obj = ResourceManager.GetObject("template", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Resources.resx b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Resources.resx new file mode 100644 index 000000000..37de48988 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Resources.resx @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + <data name="template" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\template.csx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </data> +</root>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Settings.Designer.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Settings.Designer.cs new file mode 100644 index 000000000..cb477c7a2 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// 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. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.Basic.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.Basic/Properties/Settings.settings b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Settings.settings new file mode 100644 index 000000000..033d7a5e9 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Properties/Settings.settings @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='utf-8'?> +<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)"> + <Profiles> + <Profile Name="(Default)" /> + </Profiles> + <Settings /> +</SettingsFile>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ReferenceAssembly.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ReferenceAssembly.cs new file mode 100644 index 000000000..15ef49639 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ReferenceAssembly.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 class ReferenceAssembly + { + public Type FromType { get; set; } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Resources/template.csx b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Resources/template.csx new file mode 100644 index 000000000..307e1e483 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Resources/template.csx @@ -0,0 +1,16 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Tango.Scripting.Basic; + +public class MainScript +{ + 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.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), + }; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Tango.Scripting.Basic.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Tango.Scripting.Basic.csproj new file mode 100644 index 000000000..8af52748a --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Tango.Scripting.Basic.csproj @@ -0,0 +1,186 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{2B29A699-1D65-463A-8250-A2CE81D019C9}</ProjectGuid> + <OutputType>library</OutputType> + <RootNamespace>Tango.Scripting.Basic</RootNamespace> + <AssemblyName>Tango.Scripting.Basic</AssemblyName> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <WarningLevel>4</WarningLevel> + <Deterministic>true</Deterministic> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.CodeAnalysis, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.CodeAnalysis.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll</HintPath> + </Reference> + <Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath> + </Reference> + <Reference Include="Microsoft.CodeAnalysis.CSharp.Scripting, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.Scripting.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Scripting.dll</HintPath> + </Reference> + <Reference Include="Microsoft.CodeAnalysis.Scripting, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll</HintPath> + </Reference> + <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath> + </Reference> + <Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> + </Reference> + <Reference Include="System.ComponentModel.Composition" /> + <Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath> + </Reference> + <Reference Include="System.Data" /> + <Reference Include="System.Diagnostics.FileVersionInfo, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll</HintPath> + </Reference> + <Reference Include="System.Diagnostics.StackTrace, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll</HintPath> + </Reference> + <Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath> + </Reference> + <Reference Include="System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath> + </Reference> + <Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath> + </Reference> + <Reference Include="System.Numerics" /> + <Reference Include="System.Reflection.Metadata, Version=1.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> + </Reference> + <Reference Include="System.Text.Encoding.CodePages, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll</HintPath> + </Reference> + <Reference Include="System.Threading.Thread, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll</HintPath> + </Reference> + <Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath> + </Reference> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xaml"> + <RequiredTargetFramework>4.0</RequiredTargetFramework> + </Reference> + <Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath> + </Reference> + <Reference Include="System.Xml.XmlDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll</HintPath> + </Reference> + <Reference Include="System.Xml.XPath, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll</HintPath> + </Reference> + <Reference Include="System.Xml.XPath.XDocument, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll</HintPath> + </Reference> + <Reference Include="WindowsBase" /> + <Reference Include="PresentationCore" /> + <Reference Include="PresentationFramework" /> + </ItemGroup> + <ItemGroup> + <Page Include="Themes\Generic.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + </ItemGroup> + <ItemGroup> + <Compile Include="CompilationError.cs" /> + <Compile Include="CompilationResult.cs" /> + <Compile Include="GlobalObject.cs" /> + <Compile Include="Project.cs" /> + <Compile Include="ProjectManager.cs" /> + <Compile Include="ReferenceAssembly.cs" /> + <Compile Include="Properties\AssemblyInfo.cs"> + <SubType>Code</SubType> + </Compile> + <Compile Include="Properties\Resources.Designer.cs"> + <AutoGen>True</AutoGen> + <DesignTime>True</DesignTime> + <DependentUpon>Resources.resx</DependentUpon> + </Compile> + <Compile Include="Properties\Settings.Designer.cs"> + <AutoGen>True</AutoGen> + <DependentUpon>Settings.settings</DependentUpon> + <DesignTimeSharedInput>True</DesignTimeSharedInput> + </Compile> + <Compile Include="Script.cs" /> + <Compile Include="IContext.cs" /> + <Compile Include="ProjectSession.cs" /> + <Compile Include="ProjectSessionState.cs" /> + <Compile Include="ProjectSessionStateChangedEventArgs.cs" /> + <EmbeddedResource Include="Properties\Resources.resx"> + <Generator>ResXFileCodeGenerator</Generator> + <LastGenOutput>Resources.Designer.cs</LastGenOutput> + </EmbeddedResource> + <None Include="app.config" /> + <None Include="packages.config" /> + <None Include="Properties\Settings.settings"> + <Generator>SettingsSingleFileGenerator</Generator> + <LastGenOutput>Settings.Designer.cs</LastGenOutput> + </None> + <None Include="Resources\template.csx" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Scripting.Core\Tango.Scripting.Core.csproj"> + <Project>{5812E1C6-ABAA-4066-94AC-971C27B4F46A}</Project> + <Name>Tango.Scripting.Core</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" /> + <Analyzer Include="..\..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Themes/Generic.xaml b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Themes/Generic.xaml new file mode 100644 index 000000000..a6b1f858a --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Themes/Generic.xaml @@ -0,0 +1,6 @@ +<ResourceDictionary + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:Tango.Scripting.Basic"> + +</ResourceDictionary> diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/app.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/app.config new file mode 100644 index 000000000..451526a2c --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/app.config @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-5.0.5.0" newVersion="5.0.5.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/packages.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/packages.config new file mode 100644 index 000000000..fd135245d --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/packages.config @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net461" /> + <package id="Microsoft.CodeAnalysis.Common" version="2.4.0" targetFramework="net461" /> + <package id="Microsoft.CodeAnalysis.CSharp" version="2.4.0" targetFramework="net461" /> + <package id="Microsoft.CodeAnalysis.CSharp.Scripting" version="2.4.0" targetFramework="net461" /> + <package id="Microsoft.CodeAnalysis.Scripting" version="2.4.0" targetFramework="net461" /> + <package id="Microsoft.CodeAnalysis.Scripting.Common" version="2.4.0" targetFramework="net461" /> + <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" /> + <package id="System.AppContext" version="4.3.0" targetFramework="net461" /> + <package id="System.Collections" version="4.3.0" targetFramework="net461" /> + <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" /> + <package id="System.Collections.Immutable" version="1.3.1" targetFramework="net461" /> + <package id="System.Console" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.FileVersionInfo" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.StackTrace" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" /> + <package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="net461" /> + <package id="System.Globalization" version="4.3.0" targetFramework="net461" /> + <package id="System.IO" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.Compression" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="System.Linq" version="4.3.0" targetFramework="net461" /> + <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" /> + <package id="System.Reflection" version="4.3.0" targetFramework="net461" /> + <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" /> + <package id="System.Reflection.Metadata" version="1.4.2" targetFramework="net461" /> + <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" /> + <package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" /> + <package id="System.Text.Encoding.CodePages" version="4.3.0" targetFramework="net461" /> + <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading.Tasks.Parallel" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading.Thread" version="4.3.0" targetFramework="net461" /> + <package id="System.ValueTuple" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.XmlDocument" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.XPath" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.XPath.XDocument" version="4.3.0" targetFramework="net461" /> +</packages>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Core/IScriptSource.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Core/IScriptSource.cs new file mode 100644 index 000000000..831d65935 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Core/IScriptSource.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Core +{ + public interface IScriptSource + { + String Code { get; set; } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Core/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Core/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..8b788d4cf --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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.Core")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Scripting.Core")] +[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)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5812e1c6-abaa-4066-94ac-971c27b4f46a")] + +// 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.Core/Tango.Scripting.Core.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Core/Tango.Scripting.Core.csproj new file mode 100644 index 000000000..aa4bbb240 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Core/Tango.Scripting.Core.csproj @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{5812E1C6-ABAA-4066-94AC-971C27B4F46A}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Tango.Scripting.Core</RootNamespace> + <AssemblyName>Tango.Scripting.Core</AssemblyName> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <Deterministic>true</Deterministic> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="IScriptSource.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedAssembly.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedAssembly.cs new file mode 100644 index 000000000..b0178e63e --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedAssembly.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Scripting.Editors.Intellisense; + +namespace Tango.Scripting.Editors +{ + public class CachedAssembly + { + public String Name { get; set; } + public List<KnownType> KnownTypes { get; set; } + + public CachedAssembly() + { + KnownTypes = new List<KnownType>(); + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Document/UndoStack.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Document/UndoStack.cs index f0a759b23..86e1fa33e 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Document/UndoStack.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Document/UndoStack.cs @@ -414,7 +414,7 @@ namespace Tango.Scripting.Editors.Document /// </summary> public void ClearAll() { - ThrowIfUndoGroupOpen(); + //ThrowIfUndoGroupOpen(); actionCountInUndoGroup = 0; optionalActionCount = 0; if (undostack.Count != 0) { diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd index 409825b42..6f400c4f5 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Highlighting/Resources/CSharp-Mode.xshd @@ -194,6 +194,7 @@ <Word>enum</Word> <Word>float</Word> <Word>int</Word> + <Word>object</Word> <Word>string</Word> <Word>long</Word> <Word>sbyte</Word> diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs index 28f9ccb9a..6675eb582 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs @@ -14,8 +14,8 @@ namespace Tango.Scripting.Editors.Intellisense public class KnownType { private bool _initialized; - private bool _documentationLoaded; + public bool DocumentationLoaded { get; set; } public Type Type { get; private set; } public String Name { get; private set; } public String TypeDefinition { get; private set; } @@ -135,6 +135,7 @@ namespace Tango.Scripting.Editors.Intellisense m.Name = method.Name; m.ReturnType = method.ReturnType; m.ReturnTypeFriendlyName = method.ReturnType.GetFriendlyName(); + m.IsStatic = method.IsStatic; if (method.IsGenericMethod) { @@ -148,6 +149,11 @@ namespace Tango.Scripting.Editors.Intellisense bool isLinq = method.DeclaringType == typeof(Enumerable); + if (isLinq) + { + m.IsStatic = false; + } + for (int j = 0; j < parameters.Count; j++) { var parameter = parameters[j]; @@ -211,9 +217,9 @@ namespace Tango.Scripting.Editors.Intellisense public void LoadDocumentation() { - if (!_documentationLoaded) + if (!DocumentationLoaded) { - _documentationLoaded = true; + DocumentationLoaded = true; Utils.LoadKnownTypeDocs(this); } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs index f84e26fe5..4cedad377 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeMethod.cs @@ -8,6 +8,8 @@ namespace Tango.Scripting.Editors.Intellisense { public class KnownTypeMethod : KnownTypeMember { + public bool IsStatic { get; set; } + public List<KnownTypeMethodParameter> Parameters { get; set; } public List<String> TypeArguments { get; set; } diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index d06862cef..a4493d2c4 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -1,5 +1,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -23,7 +24,9 @@ using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading; using System.Xml; +using Tango.Core; using Tango.Core.Commands; +using Tango.Scripting.Core; using Tango.Scripting.Editors.CodeCompletion; using Tango.Scripting.Editors.Document; using Tango.Scripting.Editors.Editing; @@ -52,6 +55,14 @@ namespace Tango.Scripting.Editors private List<KnownType> _knownTypes; private List<ScriptType> _declaredTypes; private bool _isLoadingTypes; + private static JsonSerializerSettings _jsonSettings; + private static Dictionary<Type, KnownType> _knownTypesCache; + private static String KNOWN_TYPES_CACHE_FOLDER; + private static List<CachedAssembly> _cachedAssemblies; + private static bool _isLoadingCachedAssemblies; + private static bool _isCacheAssembliesLoaded; + + public static event EventHandler<TangoProgressChangedEventArgs<int>> AssemblyCacheProgress; #region Mini Classes @@ -110,13 +121,13 @@ namespace Tango.Scripting.Editors /// <summary> /// Gets or sets the reference assemblies. /// </summary> - public ObservableCollection<ReferenceAssembly> ReferenceAssemblies + public ObservableCollection<Assembly> ReferenceAssemblies { - get { return (ObservableCollection<ReferenceAssembly>)GetValue(ReferenceAssembliesProperty); } + get { return (ObservableCollection<Assembly>)GetValue(ReferenceAssembliesProperty); } set { SetValue(ReferenceAssembliesProperty, value); } } public static readonly DependencyProperty ReferenceAssembliesProperty = - DependencyProperty.Register("ReferenceAssemblies", typeof(ObservableCollection<ReferenceAssembly>), typeof(ScriptEditor), new PropertyMetadata(null)); + DependencyProperty.Register("ReferenceAssemblies", typeof(ObservableCollection<Assembly>), typeof(ScriptEditor), new PropertyMetadata(null)); public Object CurrentPopupContent { @@ -126,6 +137,21 @@ namespace Tango.Scripting.Editors public static readonly DependencyProperty CurrentPopupContentProperty = DependencyProperty.Register("CurrentPopupContent", typeof(Object), typeof(ScriptEditor), new PropertyMetadata(null)); + public String Code + { + get { return (String)GetValue(CodeProperty); } + set { SetValue(CodeProperty, value); } + } + public static readonly DependencyProperty CodeProperty = + DependencyProperty.Register("Code", typeof(String), typeof(ScriptEditor), new PropertyMetadata(null, (d, e) => (d as ScriptEditor).OnCodeChanged())); + + public ObservableCollection<IScriptSource> AdditionalScripts + { + get { return (ObservableCollection<IScriptSource>)GetValue(AdditionalScriptsProperty); } + set { SetValue(AdditionalScriptsProperty, value); } + } + public static readonly DependencyProperty AdditionalScriptsProperty = + DependencyProperty.Register("AdditionalScripts", typeof(ObservableCollection<IScriptSource>), typeof(ScriptEditor), new PropertyMetadata(null)); #endregion @@ -137,6 +163,21 @@ namespace Tango.Scripting.Editors static ScriptEditor() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ScriptEditor), new FrameworkPropertyMetadata(typeof(ScriptEditor))); + + if (KNOWN_TYPES_CACHE_FOLDER == null) + { + KNOWN_TYPES_CACHE_FOLDER = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Scripting", "Cache"); + Directory.CreateDirectory(KNOWN_TYPES_CACHE_FOLDER); + } + + _jsonSettings = new JsonSerializerSettings() + { + TypeNameHandling = TypeNameHandling.Auto, + PreserveReferencesHandling = PreserveReferencesHandling.All + }; + + _knownTypesCache = new Dictionary<Type, KnownType>(); + _cachedAssemblies = new List<CachedAssembly>(); } /// <summary> @@ -148,12 +189,11 @@ namespace Tango.Scripting.Editors _current_usings = new List<string>(); - ReferenceAssemblies = new ObservableCollection<ReferenceAssembly>(); + //ReferenceAssemblies = new ObservableCollection<ReferenceAssembly>(); - //Add basic assemblies... - ReferenceAssemblies.Add(new ReferenceAssembly(typeof(String))); //mscorelib - ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Enumerable))); //System.Core - ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Tango.Core.CoreSettings))); //System.Core + ////Add basic assemblies... + //ReferenceAssemblies.Add(new ReferenceAssembly(typeof(String))); //mscorelib + //ReferenceAssemblies.Add(new ReferenceAssembly(typeof(Enumerable))); //System.Core _knownTypes = new List<KnownType>(); _parser = new ScriptParser(); @@ -175,6 +215,29 @@ namespace Tango.Scripting.Editors completionWindow.AllowsTransparency = true; completionWindow.ResizeMode = ResizeMode.NoResize; completionWindow.InsertionRequest += CompletionWindow_InsertionRequest; + + TextChanged += ScriptEditor_TextChanged; + } + + private bool preventCodeUpdate; + private void ScriptEditor_TextChanged(object sender, EventArgs e) + { + if (!preventCodeUpdate) + { + preventCodeUpdate = true; + Code = Text; + preventCodeUpdate = false; + } + } + + private void OnCodeChanged() + { + if (!preventCodeUpdate) + { + preventCodeUpdate = true; + Text = Code; + preventCodeUpdate = false; + } } #endregion @@ -370,16 +433,17 @@ namespace Tango.Scripting.Editors { var knownType = GetCurrentKnownType(); + IList<ICompletionData> data = new List<ICompletionData>(); + if (knownType != null) { completionWindow.HideCompletion(); - IList<ICompletionData> data = new List<ICompletionData>(); if (!knownType.Type.IsEnum) { var typeMembers = knownType.Members.ToList(); - foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().GroupBy(x => x.NameWithTypeArguments)) + foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => !x.IsStatic).GroupBy(x => x.NameWithTypeArguments)) { var method = methodGroup.First(); @@ -432,7 +496,6 @@ namespace Tango.Scripting.Editors if (declaredType != null) { completionWindow.HideCompletion(); - IList<ICompletionData> data = new List<ICompletionData>(); var typeMembers = declaredType.Symbols.ToList(); @@ -491,6 +554,34 @@ namespace Tango.Scripting.Editors ShowCompletionWindow(data, GetCurrentWord()); } + else + { + //Maybe static ... + var typeText = GetPreviousWord(); + knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == typeText); + + if (knownType != null) + { + var typeMembers = knownType.Members.ToList(); + + foreach (var methodGroup in typeMembers.OfType<KnownTypeMethod>().Where(x => x.IsStatic).GroupBy(x => x.NameWithTypeArguments)) + { + var method = methodGroup.First(); + + data.Add(new MethodCompletionItem() + { + Class = knownType.FriendlyName, + Name = method.NameWithTypeArguments, + ReturnType = method.ReturnTypeFriendlyName, + Description = method.Summary, + Parameters = method.Parameters, + Overloads = methodGroup.Count() - 1, + }); + } + + ShowCompletionWindow(data.OrderBy(x => x.Text).ToList(), GetCurrentWord()); + } + } } } else if (e.Text == "(" || e.Text == ",") @@ -534,6 +625,18 @@ namespace Tango.Scripting.Editors return; } } + + var staticMethodSession = GetStaticMethodSession(); + + if (staticMethodSession != null) + { + var content = CreateMethodSessionPopupContent(staticMethodSession); + if (content.Methods.Count > 0) + { + ShowPopup(content); + return; + } + } } catch (Exception ex) { @@ -552,12 +655,12 @@ namespace Tango.Scripting.Editors foreach (var asm in ReferenceAssemblies) { - foreach (var ns in asm.Assembly.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) + foreach (var ns in asm.GetTypes().Select(x => x.Namespace).Distinct().Where(x => x != null)) { data.Add(new NamespaceCompletionItem() { Name = ns, - Assembly = asm.Assembly.GetName().Name, + Assembly = asm.GetName().Name, }); } } @@ -1147,33 +1250,114 @@ namespace Tango.Scripting.Editors return popup; } - private void InvalidateHighlighting() + public static void LoadCachedAssemblies(List<Assembly> assemblies) + { + if (_isLoadingCachedAssemblies) return; + + _isLoadingCachedAssemblies = true; + + if (!_isCacheAssembliesLoaded) + { + foreach (var file in System.IO.Directory.GetFiles(KNOWN_TYPES_CACHE_FOLDER)) + { + try + { + AssemblyCacheProgress?.Invoke(null, new TangoProgressChangedEventArgs<int>() + { + Progress = new TangoProgress<int>() + { + IsIndeterminate = true, + Maximum = 100, + Message = $"Loading metadata cache for '{System.IO.Path.GetFileName(file)}'..." + } + }); + + var cachedAssembly = JsonConvert.DeserializeObject<CachedAssembly>(System.IO.File.ReadAllText(file), _jsonSettings); + + foreach (var knownType in cachedAssembly.KnownTypes) + { + _knownTypesCache.Add(knownType.Type, knownType); + } + + _cachedAssemblies.Add(cachedAssembly); + } + catch { } + } + + _isCacheAssembliesLoaded = true; + } + + foreach (var asm in assemblies) + { + if (!_cachedAssemblies.Exists(x => x.Name == asm.FullName)) + { + String asmFileName = System.IO.Path.GetFileName(asm.Location); + + CachedAssembly cachedAssembly = new CachedAssembly(); + cachedAssembly.Name = asm.FullName; + _cachedAssemblies.Add(cachedAssembly); + + var types = asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive).ToList(); + + int i = 0; + + foreach (var type in types) + { + AssemblyCacheProgress?.Invoke(null, new TangoProgressChangedEventArgs<int>() + { + Progress = new TangoProgress<int>() + { + IsIndeterminate = false, + Maximum = types.Count, + Value = i++, + Message = $"Caching metadata for '{asmFileName}'..." + } + }); + + KnownType knownType = new KnownType(type); + _knownTypesCache.Add(type, knownType); + cachedAssembly.KnownTypes.Add(knownType); + knownType.LoadDocumentation(); + } + + String cachedAssemblyFile = System.IO.Path.Combine(KNOWN_TYPES_CACHE_FOLDER, asmFileName); + File.WriteAllText(cachedAssemblyFile, JsonConvert.SerializeObject(cachedAssembly, _jsonSettings)); + } + } + + _isLoadingCachedAssemblies = false; + } + + private void InvalidateHighlighting(bool loadKnownTypes = true) { if (!_isLoadingTypes) { _isLoadingTypes = true; - _knownTypes.Clear(); var assemblies = ReferenceAssemblies.ToList(); var usings = _current_usings.ToList(); Thread t = new Thread(() => { - foreach (var asm in assemblies.Select(x => x.Assembly)) + LoadCachedAssemblies(assemblies); + + if (loadKnownTypes) { - Parallel.ForEach(asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive), (type) => + _knownTypes.Clear(); + + foreach (var asm in assemblies) { - if (usings.Exists(x => type.Namespace == x)) + foreach (var knownType in _knownTypesCache.ToList().Select(x => x.Value).ToList()) { - lock (_knownTypes) + if (usings.Exists(x => knownType.Type.Namespace == x)) { - if (!_knownTypes.Exists(x => x.Type.FullName == type.FullName)) + lock (_knownTypes) { - _knownTypes.Add(new KnownType(type)); + _knownTypes.Add(knownType); } } } - }); + } } if (_knownTypes.Count > 0 || _declaredTypes.Count > 0) @@ -1246,10 +1430,10 @@ namespace Tango.Scripting.Editors })); - foreach (var knownType in _knownTypes) - { - knownType.LoadDocumentation(); - } + //foreach (var knownType in _knownTypes) + //{ + // knownType.LoadDocumentation(); + //} } _isLoadingTypes = false; @@ -1263,10 +1447,19 @@ namespace Tango.Scripting.Editors { var declaredTypes = _parser.GetDeclaredTypes(Text); + if (AdditionalScripts != null) + { + foreach (var script in AdditionalScripts) + { + declaredTypes.AddRange(_parser.GetDeclaredTypes(script.Code)); + } + } + + if (declaredTypes.Exists(x => !_declaredTypes.Exists(y => y.Name == x.Name)) || _declaredTypes.Exists(x => !declaredTypes.Exists(y => y.Name == x.Name))) { _declaredTypes = declaredTypes; - InvalidateHighlighting(); + InvalidateHighlighting(false); } _declaredTypes = declaredTypes; @@ -1452,6 +1645,48 @@ namespace Tango.Scripting.Editors } } + else + { + var expression2 = _parser.GetCurrentConstructionExpressionAlt(GetCurrentLineText()); + + if (expression2 != null && expression2.Identifier != null) + { + ConstructionSession session = new ConstructionSession(); + + var line = GetCurrentLine(); + int parameterIndex = 0; + for (int i = CaretOffset; i > line.Offset; i--) + { + String c = Document.GetText(i, 1); + + if (c == "(") + { + KnownType type = null; + + if (expression2.Identifier != null) + { + var typeName = expression2.Identifier.ToString(); + type = _knownTypes.FirstOrDefault(x => x.Type.Name == typeName); + + if (type != null) + { + session.Type = type; + session.ParameterIndex = parameterIndex; + return session; + } + else + { + return null; + } + } + } + else if (c == ",") + { + parameterIndex++; + } + } + } + } return null; } @@ -1515,6 +1750,65 @@ namespace Tango.Scripting.Editors return null; } + private MethodSession GetStaticMethodSession() + { + var words = GetCurrentLineText().Split(' '); + + if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) + { + return null; + } + + var expression = words.LastOrDefault(); + + if (expression != null) + { + int parameterIndex = expression.Count(x => x == ','); + expression = new string(expression.TakeWhile(x => x != '(').ToArray()); + + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\r|\s|\t|\(|\)|\[|\]|<.*>")).ToList(); + var variableName = tree.FirstOrDefault(); + + if (variableName != null && tree.Count > 1) + { + tree.RemoveAt(0); + var variables = _parser.GetContextSymbols(Document.Text, CaretOffset); + var variable = variableName; + + if (variable != null) + { + var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable, "<.+>", "<T>")); + + if (knownType != null) + { + while (tree.Count > 1) + { + var memberName = tree.First(); + tree.RemoveAt(0); + var member = knownType.Members.FirstOrDefault(x => x.Name == memberName); + + if (member == null) + { + return null; + } + + knownType = _knownTypes.FirstOrDefault(x => x.Type.Namespace + "." + x.Type.Name == member.ReturnType.Namespace + "." + member.ReturnType.Name); + } + + return new MethodSession() + { + Type = knownType, + MethodName = tree.Last(), + ParameterIndex = parameterIndex, + }; + } + } + } + } + + return null; + } + private DeclaredMethodSession GetDeclaredMethodSession() { var words = GetCurrentLineText().Split(' '); diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj index ce7c361e3..d6c89f0a4 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Tango.Scripting.Editors.csproj @@ -77,6 +77,9 @@ <Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <HintPath>..\..\packages\Microsoft.CodeAnalysis.CSharp.2.4.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath> </Reference> + <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> + </Reference> <Reference Include="PresentationCore"> <RequiredTargetFramework>3.0</RequiredTargetFramework> </Reference> @@ -177,6 +180,7 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="AvalonEditCommands.cs" /> + <Compile Include="CachedAssembly.cs" /> <Compile Include="CodeCompletion\CompletionListBox.cs" /> <Compile Include="CodeCompletion\CompletionListBoxItem.cs" /> <Compile Include="CodeCompletion\CompletionWindowBase.cs" /> @@ -579,6 +583,10 @@ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> </ProjectReference> + <ProjectReference Include="..\Tango.Scripting.Core\Tango.Scripting.Core.csproj"> + <Project>{5812E1C6-ABAA-4066-94AC-971C27B4F46A}</Project> + <Name>Tango.Scripting.Core</Name> + </ProjectReference> <ProjectReference Include="..\Tango.Scripting\Tango.Scripting.csproj"> <Project>{1e938fd2-c669-4738-98c9-77f96ce4d451}</Project> <Name>Tango.Scripting</Name> @@ -628,7 +636,7 @@ </ItemGroup> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_UseGlobalSettings="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UseGlobalSettings="True" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/app.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/app.config index d3a17b4de..16d75cf59 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/app.config +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/app.config @@ -77,6 +77,14 @@ </dependentAssembly> + <dependentAssembly> + + <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" /> + + <bindingRedirect oldVersion="0.0.0.0-5.0.5.0" newVersion="5.0.5.0" /> + + </dependentAssembly> + </assemblyBinding> </runtime> diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/packages.config b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/packages.config index 00eef19db..a0f62a1d4 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/packages.config +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/packages.config @@ -4,6 +4,7 @@ <package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net461" /> <package id="Microsoft.CodeAnalysis.Common" version="2.4.0" targetFramework="net461" /> <package id="Microsoft.CodeAnalysis.CSharp" version="2.4.0" targetFramework="net461" /> + <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net461" /> <package id="System.AppContext" version="4.3.0" targetFramework="net461" /> <package id="System.Collections" version="4.3.0" targetFramework="net461" /> <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" /> 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 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> + </startup> +</configuration>
\ 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 @@ +<Application x:Class="Tango.Scripting.Test.App" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="clr-namespace:Tango.Scripting.Test" + StartupUri="MainWindow.xaml"> + <Application.Resources> + + </Application.Resources> +</Application> 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 +{ + /// <summary> + /// Interaction logic for App.xaml + /// </summary> + 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 @@ +<Window x:Class="Tango.Scripting.Test.MainWindow" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:scripting="clr-namespace:Tango.Scripting.Editors;assembly=Tango.Scripting.Editors" + xmlns:local="clr-namespace:Tango.Scripting.Test" + mc:Ignorable="d" + Title="MainWindow" Height="450" Width="800" d:DataContext="{d:DesignInstance Type={x:Type local:MainWindowVM},IsDesignTimeCreatable=False}"> + <Grid> + <DockPanel> + <Menu DockPanel.Dock="Top" IsMainMenu="True"> + <MenuItem Header="File"> + <MenuItem Header="Add Script" Command="{Binding AddScriptCommand}"></MenuItem> + </MenuItem> + <MenuItem Header="Debug"> + <MenuItem Header="Run" Command="{Binding RunCommand}"></MenuItem> + </MenuItem> + </Menu> + + <TabControl ItemsSource="{Binding Project.Scripts}" SelectedIndex="0"> + <TabControl.ItemTemplate> + <DataTemplate> + <TextBlock Text="{Binding Name}"></TextBlock> + </DataTemplate> + </TabControl.ItemTemplate> + <TabControl.ContentTemplate> + <DataTemplate> + <scripting:ScriptEditor + ReferenceAssemblies="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.Project.ReferenceAssembliesLoaded}" + AdditionalScripts="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.Project.AdditionalScripts}" + Code="{Binding Code,Mode=TwoWay}" /> + </DataTemplate> + </TabControl.ContentTemplate> + </TabControl> + </DockPanel> + </Grid> +</Window> 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 +{ + /// <summary> + /// Interaction logic for MainWindow.xaml + /// </summary> + public partial class MainWindow : Window + { + public MainWindow() + { + ScriptEditor.AssemblyCacheProgress += ScriptEditor_AssemblyCacheProgress; + ScriptEditor.LoadCachedAssemblies(new List<System.Reflection.Assembly>() + { + 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<int> 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 +//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file +//inside a <PropertyGroup>. For example, if you are using US english +//in your source files, set the <UICulture> 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 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// 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. +// </auto-generated> +//------------------------------------------------------------------------------ + +namespace Tango.Scripting.Test.Properties { + using System; + + + /// <summary> + /// A strongly-typed resource class, for looking up localized strings, etc. + /// </summary> + // 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() { + } + + /// <summary> + /// Returns the cached ResourceManager instance used by this class. + /// </summary> + [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; + } + } + + /// <summary> + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// </summary> + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// <summary> + /// Looks up a localized resource of type System.Byte[]. + /// </summary> + 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + <data name="template" type="System.Resources.ResXFileRef, System.Windows.Forms"> + <value>..\Resources\template.csx;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </data> +</root>
\ 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 @@ +//------------------------------------------------------------------------------ +// <auto-generated> +// 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. +// </auto-generated> +//------------------------------------------------------------------------------ + +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 @@ +<?xml version='1.0' encoding='utf-8'?> +<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)"> + <Profiles> + <Profile Name="(Default)" /> + </Profiles> + <Settings /> +</SettingsFile>
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{564A30E2-E681-422A-9528-3E8CE301B837}</ProjectGuid> + <OutputType>WinExe</OutputType> + <RootNamespace>Tango.Scripting.Test</RootNamespace> + <AssemblyName>Tango.Scripting.Test</AssemblyName> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <WarningLevel>4</WarningLevel> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <Deterministic>true</Deterministic> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <DocumentationFile> + </DocumentationFile> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xaml"> + <RequiredTargetFramework>4.0</RequiredTargetFramework> + </Reference> + <Reference Include="WindowsBase" /> + <Reference Include="PresentationCore" /> + <Reference Include="PresentationFramework" /> + </ItemGroup> + <ItemGroup> + <ApplicationDefinition Include="App.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </ApplicationDefinition> + <Compile Include="Properties\Resources.Designer.cs"> + <AutoGen>True</AutoGen> + <DesignTime>True</DesignTime> + <DependentUpon>Resources.resx</DependentUpon> + </Compile> + <Page Include="MainWindow.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> + <Compile Include="App.xaml.cs"> + <DependentUpon>App.xaml</DependentUpon> + <SubType>Code</SubType> + </Compile> + <Compile Include="MainWindow.xaml.cs"> + <DependentUpon>MainWindow.xaml</DependentUpon> + <SubType>Code</SubType> + </Compile> + </ItemGroup> + <ItemGroup> + <Compile Include="MainWindowVM.cs" /> + <Compile Include="Properties\AssemblyInfo.cs"> + <SubType>Code</SubType> + </Compile> + <Compile Include="Properties\Settings.Designer.cs"> + <AutoGen>True</AutoGen> + <DependentUpon>Settings.settings</DependentUpon> + <DesignTimeSharedInput>True</DesignTimeSharedInput> + </Compile> + <EmbeddedResource Include="Properties\Resources.resx"> + <Generator>ResXFileCodeGenerator</Generator> + <LastGenOutput>Resources.Designer.cs</LastGenOutput> + </EmbeddedResource> + <None Include="lib.csx" /> + <None Include="Properties\Settings.settings"> + <Generator>SettingsSingleFileGenerator</Generator> + <LastGenOutput>Settings.Designer.cs</LastGenOutput> + </None> + <None Include="Resources\template.csx" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.SharedUI\Tango.SharedUI.csproj"> + <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> + <Name>Tango.SharedUI</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Scripting.Basic\Tango.Scripting.Basic.csproj"> + <Project>{2b29a699-1d65-463a-8250-a2ce81d019c9}</Project> + <Name>Tango.Scripting.Basic</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Scripting.Core\Tango.Scripting.Core.csproj"> + <Project>{5812e1c6-abaa-4066-94ac-971c27b4f46a}</Project> + <Name>Tango.Scripting.Core</Name> + </ProjectReference> + <ProjectReference Include="..\Tango.Scripting.Editors\Tango.Scripting.Editors.csproj"> + <Project>{da62fa39-668b-47a6-b0f2-d2c1daf777b0}</Project> + <Name>Tango.Scripting.Editors</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <PackageReference Include="FontAwesome.WPF"> + <Version>4.7.0.9</Version> + </PackageReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project>
\ 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"; + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting/Parsing/ScriptParser.cs b/Software/Visual_Studio/Scripting/Tango.Scripting/Parsing/ScriptParser.cs index 15760c950..7accdbb83 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting/Parsing/ScriptParser.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting/Parsing/ScriptParser.cs @@ -258,7 +258,21 @@ namespace Tango.Scripting.Parsing { SyntaxTree tree = CSharpSyntaxTree.ParseText(code); CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); - return root.DescendantNodes().OfType<ObjectCreationExpressionSyntax>().FirstOrDefault(); + var creationSyntax = root.DescendantNodes().OfType<ObjectCreationExpressionSyntax>().FirstOrDefault(); + return creationSyntax; + } + + public MethodDeclarationSyntax GetCurrentConstructionExpressionAlt(String code) + { + if (code.Contains("=") && code.Contains("new")) + { + SyntaxTree tree = CSharpSyntaxTree.ParseText(code); + CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); + var creationSyntax = root.DescendantNodes().OfType<MethodDeclarationSyntax>().FirstOrDefault(); + return creationSyntax; + } + + return null; } public T GetExpressionFirst<T>(String line) where T : CSharpSyntaxNode |
