From 499e0a03bb41e2330a47ccca83e6e6dfe7c5a634 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 22 Apr 2020 02:08:25 +0300 Subject: Scripting. --- .../Tango.Scripting.Editors/CachedUsing.cs | 20 ++ .../Tango.Scripting.Editors/Images/event.png | Bin 0 -> 210 bytes .../Intellisense/EventCompletionItem.cs | 22 ++ .../Intellisense/KnownType.cs | 24 +- .../Intellisense/KnownTypeEvent.cs | 21 ++ .../Tango.Scripting.Editors/ScriptEditor.cs | 334 ++++++++++++++++----- .../Tango.Scripting.Editors.csproj | 8 +- .../Tango.Scripting.Editors/Themes/Generic.xaml | 3 + 8 files changed, 356 insertions(+), 76 deletions(-) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedUsing.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Images/event.png create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedUsing.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedUsing.cs new file mode 100644 index 000000000..4a663bee9 --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/CachedUsing.cs @@ -0,0 +1,20 @@ +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 CachedUsing + { + public String Namespace { get; set; } + public List KnownTypes { get; set; } + + public CachedUsing() + { + KnownTypes = new List(); + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Images/event.png b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Images/event.png new file mode 100644 index 000000000..4566835c0 Binary files /dev/null and b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Images/event.png differ diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs new file mode 100644 index 000000000..5c510c39f --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/EventCompletionItem.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class EventCompletionItem : CompletionItem + { + private static BitmapSource image = GetImage("event.png"); + + public override string Text => Name; + public override CompletionItemPopupControl PopupControl => new FieldCompletionItemPopup(); + public override BitmapSource Image => image; + + public String Name { get; set; } + public String Class { get; set; } + public String Type { get; set; } + } +} 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 6675eb582..3dc465541 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownType.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; using System.Xml; using Tango.Core; @@ -15,15 +16,17 @@ namespace Tango.Scripting.Editors.Intellisense { private bool _initialized; + public String Alias { get; set; } public bool DocumentationLoaded { get; set; } public Type Type { get; private set; } - public String Name { get; private set; } + public String Name { get; set; } public String TypeDefinition { get; private set; } public String FriendlyName { get; private set; } public String Summary { get; set; } public List Constructors { get; set; } public List Methods { get; set; } public List Properties { get; set; } + public List Events { get; set; } public List Members { get @@ -32,6 +35,7 @@ namespace Tango.Scripting.Editors.Intellisense members.AddRange(Properties); members.AddRange(Methods); + members.AddRange(Events); return members.OrderBy(x => x.Name).ToList(); } @@ -45,6 +49,7 @@ namespace Tango.Scripting.Editors.Intellisense Methods = new List(); Properties = new List(); Fields = new List(); + Events = new List(); Type = type; Name = type.Name; @@ -177,7 +182,7 @@ namespace Tango.Scripting.Editors.Intellisense //Load Properties { - var properties = Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPublic).ToList(); + var properties = Type.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance).ToList(); for (int i = 0; i < properties.Count; i++) { @@ -192,6 +197,21 @@ namespace Tango.Scripting.Editors.Intellisense } } + //Load Events + { + var events = Type.GetRuntimeEvents().ToList(); + + for (int i = 0; i < events.Count; i++) + { + var ev = events[i]; + + KnownTypeEvent p = new KnownTypeEvent(this); + p.Name = ev.Name; + + Events.Add(p); + } + } + //Load Enum Values { if (Type.IsEnum) diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs new file mode 100644 index 000000000..7403d2cbd --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Intellisense/KnownTypeEvent.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Scripting.Editors.Intellisense +{ + public class KnownTypeEvent : KnownTypeMember + { + public KnownTypeEvent() + { + Summary = "Loading documentation..."; + } + + public KnownTypeEvent(KnownType knownType) : this() + { + Type = knownType; + } + } +} diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs index a4493d2c4..29af14ddc 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/ScriptEditor.cs @@ -59,10 +59,14 @@ namespace Tango.Scripting.Editors private static Dictionary _knownTypesCache; private static String KNOWN_TYPES_CACHE_FOLDER; private static List _cachedAssemblies; + private static List _cachedUsings; private static bool _isLoadingCachedAssemblies; private static bool _isCacheAssembliesLoaded; + private static object _loadUsingsLock = new object(); - public static event EventHandler> AssemblyCacheProgress; + public static event EventHandler> LoadingSymbolsProgress; + public static event EventHandler LoadingSymbolsStarted; + public static event EventHandler LoadingSymbolsCompleted; #region Mini Classes @@ -96,6 +100,8 @@ namespace Tango.Scripting.Editors #region Properties + public static List BlockedUsingsCache { get; set; } + /// /// Gets or sets a value indicating whether to enable folding. /// @@ -164,6 +170,8 @@ namespace Tango.Scripting.Editors { DefaultStyleKeyProperty.OverrideMetadata(typeof(ScriptEditor), new FrameworkPropertyMetadata(typeof(ScriptEditor))); + BlockedUsingsCache = new List(); + if (KNOWN_TYPES_CACHE_FOLDER == null) { KNOWN_TYPES_CACHE_FOLDER = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Scripting", "Cache"); @@ -178,6 +186,7 @@ namespace Tango.Scripting.Editors _knownTypesCache = new Dictionary(); _cachedAssemblies = new List(); + _cachedUsings = new List(); } /// @@ -458,7 +467,17 @@ namespace Tango.Scripting.Editors }); } - foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod)).GroupBy(x => x.Name)) + foreach (var ev in typeMembers.OfType()) + { + data.Add(new EventCompletionItem() + { + Class = knownType.FriendlyName, + Name = ev.Name, + Description = ev.Summary, + }); + } + + foreach (var methodGroup in typeMembers.Where(x => x.GetType() != typeof(KnownTypeMethod) && x.GetType() != typeof(KnownTypeEvent)).GroupBy(x => x.Name)) { var member = methodGroup.First(); @@ -469,7 +488,6 @@ namespace Tango.Scripting.Editors Type = member.ReturnTypeFriendlyName, Description = member.Summary, }); - } } else @@ -558,7 +576,7 @@ namespace Tango.Scripting.Editors { //Maybe static ... var typeText = GetPreviousWord(); - knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == typeText); + knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == typeText || x.Alias == typeText); if (knownType != null) { @@ -902,7 +920,7 @@ namespace Tango.Scripting.Editors IList data = completionWindow.CompletionList.CompletionData; data.Clear(); - foreach (var item in suggestions) + foreach (var item in suggestions.DistinctBy(x => x.Text)) { data.Add(item); } @@ -984,6 +1002,13 @@ namespace Tango.Scripting.Editors { if (expression != null) { + var insideMethodExp = expression.Split('(').LastOrDefault(); + + if (insideMethodExp != null) + { + expression = insideMethodExp; + } + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); var variableName = tree.FirstOrDefault(); @@ -1003,7 +1028,8 @@ namespace Tango.Scripting.Editors if (variable != null) { - var knownType = _knownTypes.FirstOrDefault(x => x.FriendlyName == Regex.Replace(variable.Type, "<.+>", "")); + var name = Regex.Replace(variable.Type, "<.+>", ""); + var knownType = _knownTypes.FirstOrDefault(x => name == x.FriendlyName || name == x.Alias); if (knownType != null) { @@ -1036,6 +1062,13 @@ namespace Tango.Scripting.Editors if (expression != null) { + var insideMethodExp = expression.Split('(').LastOrDefault(); + + if (insideMethodExp != null) + { + expression = insideMethodExp; + } + var tree = expression.Split('.').Select(x => x.Remove(@"\n|\t|\r|\(.*\)|\[.*\]|\s")).ToList(); var variableName = tree.FirstOrDefault(); @@ -1250,84 +1283,224 @@ namespace Tango.Scripting.Editors return popup; } - public static void LoadCachedAssemblies(List assemblies) + public static void LoadUsingsSymbols(List assemblies, List usings) { - if (_isLoadingCachedAssemblies) return; + lock (_loadUsingsLock) + { + LoadingSymbolsStarted?.Invoke(null, new EventArgs()); - _isLoadingCachedAssemblies = true; + var allTypes = assemblies.SelectMany(x => x.GetTypes()); - if (!_isCacheAssembliesLoaded) - { - foreach (var file in System.IO.Directory.GetFiles(KNOWN_TYPES_CACHE_FOLDER)) + foreach (var use in usings) { - try + if (!_cachedUsings.Exists(x => x.Namespace == use)) { - AssemblyCacheProgress?.Invoke(null, new TangoProgressChangedEventArgs() + var useFileName = System.IO.Path.Combine(KNOWN_TYPES_CACHE_FOLDER, use + ".json"); + + if (File.Exists(useFileName)) { - Progress = new TangoProgress() + LoadingSymbolsProgress?.Invoke(null, new TangoProgressChangedEventArgs() { - IsIndeterminate = true, - Maximum = 100, - Message = $"Loading metadata cache for '{System.IO.Path.GetFileName(file)}'..." - } - }); + Progress = new TangoProgress() + { + IsIndeterminate = true, + Maximum = 100, + Message = $"Loading symbols for '{use}'..." + } + }); - var cachedAssembly = JsonConvert.DeserializeObject(System.IO.File.ReadAllText(file), _jsonSettings); + CachedUsing cached = JsonConvert.DeserializeObject(File.ReadAllText(useFileName), _jsonSettings); + _cachedUsings.Add(cached); + foreach (var knownType in cached.KnownTypes) + { + _knownTypesCache.Add(knownType.Type, knownType); + } - foreach (var knownType in cachedAssembly.KnownTypes) - { - _knownTypesCache.Add(knownType.Type, knownType); + continue; } - _cachedAssemblies.Add(cachedAssembly); - } - catch { } - } - - _isCacheAssembliesLoaded = true; - } + var useTypes = allTypes.Where(x => x.IsVisible && x.IsPublic && x.Namespace == use).ToList(); - foreach (var asm in assemblies) - { - if (!_cachedAssemblies.Exists(x => x.Name == asm.FullName)) - { - String asmFileName = System.IO.Path.GetFileName(asm.Location); + CachedUsing cachedUsing = new CachedUsing(); + cachedUsing.Namespace = use; + _cachedUsings.Add(cachedUsing); - CachedAssembly cachedAssembly = new CachedAssembly(); - cachedAssembly.Name = asm.FullName; - _cachedAssemblies.Add(cachedAssembly); + int i = 1; - var types = asm.GetTypes().Where(x => x.IsVisible && x.IsPublic && !x.IsPrimitive).ToList(); + foreach (var type in useTypes) + { + LoadingSymbolsProgress?.Invoke(null, new TangoProgressChangedEventArgs() + { + Progress = new TangoProgress() + { + IsIndeterminate = false, + Maximum = useTypes.Count, + Value = i++, + Message = $"Loading symbols for '{use}'..." + } + }); - int i = 0; + KnownType knownType = new KnownType(type); - foreach (var type in types) - { - AssemblyCacheProgress?.Invoke(null, new TangoProgressChangedEventArgs() - { - Progress = new TangoProgress() + if (type.IsPrimitive) { - IsIndeterminate = false, - Maximum = types.Count, - Value = i++, - Message = $"Caching metadata for '{asmFileName}'..." + if (type == typeof(Int32)) + { + knownType.Alias = "int"; + } + else if (type == typeof(float)) + { + knownType.Alias = "float"; + } + else if (type == typeof(Double)) + { + knownType.Alias = "double"; + } + else if (type == typeof(long)) + { + knownType.Alias = "long"; + } + else if (type == typeof(bool)) + { + knownType.Alias = "bool"; + } + else if (type == typeof(uint)) + { + knownType.Alias = "uint"; + } } - }); - KnownType knownType = new KnownType(type); - _knownTypesCache.Add(type, knownType); - cachedAssembly.KnownTypes.Add(knownType); - knownType.LoadDocumentation(); - } + _knownTypesCache.Add(type, knownType); + cachedUsing.KnownTypes.Add(knownType); + knownType.LoadDocumentation(); + } - String cachedAssemblyFile = System.IO.Path.Combine(KNOWN_TYPES_CACHE_FOLDER, asmFileName); - File.WriteAllText(cachedAssemblyFile, JsonConvert.SerializeObject(cachedAssembly, _jsonSettings)); + if (!BlockedUsingsCache.Exists(x => x == use)) + { + Task.Factory.StartNew(() => + { + var json = JsonConvert.SerializeObject(cachedUsing, _jsonSettings); + File.WriteAllText(useFileName, json); + }); + } + } } - } - _isLoadingCachedAssemblies = false; + LoadingSymbolsCompleted?.Invoke(null, new EventArgs()); + } } + //public static void LoadCachedAssemblies(List assemblies, List usings = null) + //{ + // if (_isLoadingCachedAssemblies) return; + + // _isLoadingCachedAssemblies = true; + + // LoadingSymbolsStarted?.Invoke(null, new EventArgs()); + + // if (!_isCacheAssembliesLoaded) + // { + // foreach (var file in System.IO.Directory.GetFiles(KNOWN_TYPES_CACHE_FOLDER)) + // { + // try + // { + // LoadingSymbolsProgress?.Invoke(null, new TangoProgressChangedEventArgs() + // { + // Progress = new TangoProgress() + // { + // IsIndeterminate = true, + // Maximum = 100, + // Message = $"Loading metadata cache for '{System.IO.Path.GetFileName(file)}'..." + // } + // }); + + // var cachedAssembly = JsonConvert.DeserializeObject(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).ToList(); + + // int i = 0; + + // foreach (var type in types) + // { + // LoadingSymbolsProgress?.Invoke(null, new TangoProgressChangedEventArgs() + // { + // Progress = new TangoProgress() + // { + // IsIndeterminate = false, + // Maximum = types.Count, + // Value = i++, + // Message = $"Caching metadata for '{asmFileName}'..." + // } + // }); + + // KnownType knownType = new KnownType(type); + + // if (type.IsPrimitive) + // { + // if (type == typeof(Int32)) + // { + // knownType.Alias = "int"; + // } + // else if (type == typeof(float)) + // { + // knownType.Alias = "float"; + // } + // else if (type == typeof(Double)) + // { + // knownType.Alias = "double"; + // } + // else if (type == typeof(long)) + // { + // knownType.Alias = "long"; + // } + // else if (type == typeof(bool)) + // { + // knownType.Alias = "bool"; + // } + // else if (type == typeof(uint)) + // { + // knownType.Alias = "uint"; + // } + // } + + // _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)); + // } + // } + + // LoadingSymbolsCompleted?.Invoke(null, new EventArgs()); + + // _isLoadingCachedAssemblies = false; + //} + private void InvalidateHighlighting(bool loadKnownTypes = true) { if (!_isLoadingTypes) @@ -1339,22 +1512,19 @@ namespace Tango.Scripting.Editors Thread t = new Thread(() => { - LoadCachedAssemblies(assemblies); + LoadUsingsSymbols(assemblies, usings); if (loadKnownTypes) { _knownTypes.Clear(); - foreach (var asm in assemblies) + foreach (var knownType in _knownTypesCache.ToList().Select(x => x.Value).ToList()) { - foreach (var knownType in _knownTypesCache.ToList().Select(x => x.Value).ToList()) + if (usings.Exists(x => knownType.Type.Namespace == x)) { - if (usings.Exists(x => knownType.Type.Namespace == x)) + lock (_knownTypes) { - lock (_knownTypes) - { - _knownTypes.Add(knownType); - } + _knownTypes.Add(knownType); } } } @@ -1589,7 +1759,11 @@ namespace Tango.Scripting.Editors private ConstructionSession GetConstructionSession() { - var expression = _parser.GetCurrentConstructionExpression(GetCurrentLineText()); + var currentLine = GetCurrentLineText(); + + //if (currentLine.Count(x => x == '(') > 1) return null; + + var expression = _parser.GetCurrentConstructionExpression(currentLine); if (expression != null) { @@ -1693,7 +1867,14 @@ namespace Tango.Scripting.Editors private MethodSession GetMethodSession() { - var words = GetCurrentLineText().Split(' '); + var currentLine = GetCurrentLineText(); + + if (currentLine.Count(x => x == '(') > 1) + { + currentLine = currentLine.Split('(')[currentLine.Split('(').Length - 2]; + } + + var words = currentLine.Split(' '); if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) { @@ -1811,14 +1992,21 @@ namespace Tango.Scripting.Editors private DeclaredMethodSession GetDeclaredMethodSession() { - var words = GetCurrentLineText().Split(' '); + var currentLine = GetCurrentLineText(); + + if (currentLine.Count(x => x == '(') > 1) + { + currentLine = currentLine.Split('(')[currentLine.Split('(').Length - 2]; + } + + var words = currentLine.Split(' '); if (words.Count() > 0 && (words.First() == "private" || words.First() == "public" || words.First() == "void")) { return null; } - var expression = GetPreviousWords().LastOrDefault(); + var expression = currentLine; if (expression != null) { @@ -1833,7 +2021,7 @@ namespace Tango.Scripting.Editors if (variable != null) { - var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Class, "<.+>", "")); + var declaredType = _declaredTypes.FirstOrDefault(x => x.Name == Regex.Replace(variable.Type, "<.+>", "")); if (declaredType != null) { 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 d6c89f0a4..cabacbc28 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 @@ -181,6 +181,7 @@ + @@ -201,6 +202,7 @@ + @@ -340,6 +342,7 @@ + @@ -634,9 +637,12 @@ + + + - + \ No newline at end of file diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Themes/Generic.xaml b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Themes/Generic.xaml index ce5cb39e1..6455b8fcb 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Themes/Generic.xaml +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Themes/Generic.xaml @@ -47,6 +47,7 @@ + @@ -567,4 +568,6 @@ + + -- cgit v1.3.1 From 5ed5ef7ef65731a9e509cb7a707722458da206d1 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 22 Apr 2020 13:28:13 +0300 Subject: Working on FSE scripting. Fixed issue with gradient generation using the color converter RGB only entry point for RGB and LAB brush stops. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../Tango.FSE.Stubs/Contracts/ITestDesignerView.cs | 13 ++++ .../Dialogs/AddReferenceAssemblyViewVM.cs | 10 +-- .../FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs | 6 +- .../Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj | 3 + .../FSE/Modules/Tango.FSE.Stubs/TestProject.cs | 37 +++++++++++ .../ViewModels/TestDesignerViewVM.cs | 69 +++++++++++++++++---- .../Tango.FSE.Stubs/Views/TestDesignerView.xaml | 34 ++++++---- .../Visual_Studio/PPC/Tango.PPC.UI/app.manifest | 2 +- .../Scripting/Tango.Scripting.Basic/Project.cs | 40 +++++------- .../Tango.Scripting.Basic/ReferenceAssembly.cs | 54 ++++++++++++++++ .../Tango.Scripting.Editors/ScriptEditor.cs | 24 ++++++- .../ExtensionMethods/ConversionOutputExtensions.cs | 16 ++++- .../Tango.Core/Helpers/AssemblyHelper.cs | 7 +++ .../DefaultGradientGenerationConfiguration.cs | 2 +- 16 files changed, 254 insertions(+), 63 deletions(-) create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs create mode 100644 Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 30056be9a..1a0f8aa56 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 0509b635d..f1a5186a8 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs new file mode 100644 index 000000000..604d54571 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Contracts/ITestDesignerView.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.FSE.Stubs.Contracts +{ + public interface ITestDesignerView + { + + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs index 0f79da8d6..aa32f6a03 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Dialogs/AddReferenceAssemblyViewVM.cs @@ -24,7 +24,7 @@ namespace Tango.FSE.Stubs.Dialogs public AddReferenceAssemblyViewVM(List existing) { - OKText = "ADD"; + OKText = "DONE"; TangoIOC.Default.Inject(this); @@ -34,11 +34,13 @@ namespace Tango.FSE.Stubs.Dialogs foreach (var file in Directory.GetFiles(startPath, "*.dll")) { - source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + if (Path.GetFileName(file).StartsWith("Tango")) + { + source.Add(ReferenceAssembly.FromFile(Path.GetFileName(file))); + } } - String dotNetVersion = AssemblyHelper.GetTargetFrameworkVersion(Assembly.GetExecutingAssembly()).ToString(); - String dotNetPath = $@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v{dotNetVersion}"; + String dotNetPath = AssemblyHelper.GetAssemblyTargetFrameworkFolder(Assembly.GetExecutingAssembly()); foreach (var file in Directory.GetFiles(dotNetPath, "*.dll")) { diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs index 3e3bddece..978455ff8 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ProjectRunner.cs @@ -10,7 +10,7 @@ namespace Tango.FSE.Stubs { public class ProjectRunner : ExtendedObject { - private ProjectSession _currentSession; + private ProjectSession _currentSession; public event EventHandler StateChanged; @@ -51,9 +51,9 @@ namespace Tango.FSE.Stubs get { return State != ProjectRunnerState.Running && State != ProjectRunnerState.Compiling; } } - public Project Project { get; private set; } + public TestProject Project { get; private set; } - public ProjectRunner(Project project) + public ProjectRunner(TestProject project) { Project = project; } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj index 54d6f3507..d80488f27 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Tango.FSE.Stubs.csproj @@ -78,6 +78,7 @@ ..\..\..\packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll + ..\..\..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll @@ -95,6 +96,7 @@ + @@ -108,6 +110,7 @@ + diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs new file mode 100644 index 000000000..533764392 --- /dev/null +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/TestProject.cs @@ -0,0 +1,37 @@ +using Google.Protobuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Tango.Integration.Operation; +using Tango.Scripting.Basic; +using Tango.Transport; + +namespace Tango.FSE.Stubs +{ + public class TestProject : Project + { + public static TestProject New(String name) + { + TestProject project = new TestProject(); + project.Name = name; + + project.Scripts.Add(Script.New("Program.csx", Encoding.UTF8.GetString(Properties.Resources.main_template), true)); + project.Scripts.Add(Script.New("lib.csx", Encoding.UTF8.GetString(Properties.Resources.lib_template))); + + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(String))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(Enumerable))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(Form))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(TestProject))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(PMR.Common.MessageType))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(ITransporter))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(IMachineOperator))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(IMessage))); + project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(System.Drawing.Point))); + + return project; + } + } +} diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs index a63469f14..87835316d 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/ViewModels/TestDesignerViewVM.cs @@ -3,9 +3,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Input; +using System.Windows.Threading; using Tango.Core; using Tango.Core.Commands; using Tango.Core.ExtensionMethods; @@ -29,6 +31,8 @@ namespace Tango.FSE.Stubs.ViewModels Results } + private DispatcherTimer _compileTimer; + #region Properties private ToolWindows _selectedToolWindow; @@ -38,8 +42,8 @@ namespace Tango.FSE.Stubs.ViewModels set { _selectedToolWindow = value; RaisePropertyChangedAuto(); } } - private Project _project; - public Project Project + private TestProject _project; + public TestProject Project { get { return _project; } set { _project = value; RaisePropertyChangedAuto(); OnProjectChanged(); } @@ -98,6 +102,13 @@ namespace Tango.FSE.Stubs.ViewModels set { _isLoadingSymbols = value; RaisePropertyChangedAuto(); } } + private ObservableCollection _loadedAssemblies; + public ObservableCollection LoadedAssemblies + { + get { return _loadedAssemblies; } + set { _loadedAssemblies = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -108,6 +119,7 @@ namespace Tango.FSE.Stubs.ViewModels public RelayCommand StopProjectCommand { get; set; } public RelayCommand CompileProjectCommand { get; set; } public RelayCommand AddReferenceAssemblyCommand { get; set; } + public RelayCommand RemoveReferenceAssemblyCommand { get; set; } #endregion @@ -117,6 +129,8 @@ namespace Tango.FSE.Stubs.ViewModels { Status = "Ready"; + LoadedAssemblies = new ObservableCollection(); + CompilationErrors = new List(); Logger = new TextController(); ScriptEditor.LoadingSymbolsProgress += ScriptEditor_LoadingSymbolsProgress; @@ -132,6 +146,12 @@ namespace Tango.FSE.Stubs.ViewModels StopProjectCommand = new RelayCommand(StopProject, () => ProjectRunner != null && ProjectRunner.IsRunning); CompileProjectCommand = new RelayCommand(async () => await CompileProject(), () => ProjectRunner != null && ProjectRunner.CanCompile); AddReferenceAssemblyCommand = new RelayCommand(AddReferenceAssembly); + RemoveReferenceAssemblyCommand = new RelayCommand(RemoveReferenceAssembly); + + _compileTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle); + _compileTimer.Interval = TimeSpan.FromSeconds(2); + _compileTimer.Tick += _compileTimer_Tick; + _compileTimer.Start(); CreateNewProject(); } @@ -268,6 +288,25 @@ namespace Tango.FSE.Stubs.ViewModels InvalidateRelayCommands(); } + private async void _compileTimer_Tick(object sender, EventArgs e) + { + if (!IsVisible) return; + + _compileTimer.Stop(); + + if (Project != null) + { + CompilationErrors = (await Project.Compile()).Errors; + + if (CompilationErrors.Count > 0) + { + SelectedToolWindow = ToolWindows.Errors; + } + } + + _compileTimer.Start(); + } + #endregion #region Private Methods @@ -283,22 +322,15 @@ namespace Tango.FSE.Stubs.ViewModels { Project.ReferenceAssemblies.Add(asm); } + + LoadReferenceAssemblies(); } } private void CreateNewProject() { - var project = Project.New("test1"); - project.Scripts.Add(Script.New("Program.csx", Encoding.UTF8.GetString(Properties.Resources.main_template), true)); - project.Scripts.Add(Script.New("lib.csx", Encoding.UTF8.GetString(Properties.Resources.lib_template))); - project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(this.GetType())); - project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(PMR.Common.MessageType))); - project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(ITransporter))); - project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(IMachineOperator))); - project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(IMessage))); - project.ReferenceAssemblies.Add(ReferenceAssembly.FromType(typeof(System.Drawing.Point))); - - Project = project; + Project = TestProject.New("test1"); + LoadReferenceAssemblies(); } private void OnProjectChanged() @@ -316,6 +348,17 @@ namespace Tango.FSE.Stubs.ViewModels InvalidateRelayCommands(); } + private void LoadReferenceAssemblies() + { + LoadedAssemblies = Project.LoadReferenceAssemblies().ToObservableCollection(); + } + + private void RemoveReferenceAssembly(ReferenceAssembly assembly) + { + Project.ReferenceAssemblies.Remove(assembly); + LoadedAssemblies = Project.LoadReferenceAssemblies().ToObservableCollection(); + } + #endregion #region ITestLogger diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml index 47df50d24..e434e4e53 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Stubs/Views/TestDesignerView.xaml @@ -14,6 +14,10 @@ mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Type=vm:TestDesignerViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.TestDesignerViewVM}" Background="{StaticResource FSE_PrimaryBackgroundBrush}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"> + + + + @@ -262,7 +266,7 @@ @@ -367,20 +371,26 @@ - - - - - - - - - - - + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index d72e75011..efc5f8179 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - + diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs index 14a9d94da..446e5b529 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs @@ -15,6 +15,7 @@ using Tango.Core; using Tango.Core.IO; using Tango.Scripting.Core; using System.IO; +using Tango.Core.Helpers; namespace Tango.Scripting.Basic { @@ -38,9 +39,6 @@ namespace Tango.Scripting.Basic public ObservableCollection ReferenceAssemblies { get; set; } - [JsonIgnore] - public ObservableCollection ReferenceAssembliesLoaded { get; set; } - public ObservableCollection