From 5ee4696c9a82fa23ec477c28b725af104abe90ef Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 2 May 2018 14:23:40 +0300 Subject: Worked on DeveloperConsole. Added some fields to VSTS work item. (resolved...) Resolved issue with application crash when trying to show notification before main window initialized. Added DeveloperConsole permission to DB. Added SetWorkItemAssignment to TFS client. --- .../Console/ConsoleWindow.xaml | 118 ++++++++++++++++++- .../Console/ConsoleWindow.xaml.cs | 10 +- .../Console/ConsoleWindowVM.cs | 129 +++++++++++++++++++-- 3 files changed, 243 insertions(+), 14 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml index 3a30eda57..22338fea7 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml @@ -8,6 +8,7 @@ xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:views="clr-namespace:Tango.MachineStudio.UI.Views" + xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:sharedControls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:console="clr-namespace:Tango.MachineStudio.UI.Console" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Console" @@ -29,7 +30,105 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -57,12 +156,23 @@ - + - - + + + + + + + + + LOG + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs index e22582a46..de2c728b0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindow.xaml.cs @@ -26,10 +26,18 @@ namespace Tango.MachineStudio.UI.Console { InitializeComponent(); - this.Loaded += (_, __) => + this.Loaded += (_, __) => { _vm = this.DataContext as ConsoleWindowVM; + _vm.SetLogTextBox(txtLog); }; } + + //Auto scroll to bottom of response log each time it is changed. + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + txtLog.SelectionStart = txtLog.Text.Length; + txtLog.ScrollToEnd(); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs index 9c1192f06..a3a0a734e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Console/ConsoleWindowVM.cs @@ -1,10 +1,13 @@ -using System; +using Microsoft.Win32; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; +using System.Windows.Controls; using System.Windows.Threading; using Tango.Core.Commands; using Tango.Core.Helpers; @@ -19,6 +22,8 @@ namespace Tango.MachineStudio.UI.Console { private IStudioModuleLoader _moduleLoader; private INotificationProvider _notificatrion; + private TextBox _txtLog; + private String _currentFile; /// @@ -26,28 +31,36 @@ namespace Tango.MachineStudio.UI.Console /// public ObservableCollection> HighlightTypes { get; set; } + internal void SetLogTextBox(TextBox txtLog) + { + _txtLog = txtLog; + } + /// /// Gets or sets the intellisense types. /// public ObservableCollection> IntellisenseTypes { get; set; } private String _code; - + /// + /// Gets or sets the code. + /// public String Code { get { return _code; } set { _code = value; RaisePropertyChangedAuto(); } } - private String _log; - - public String Log + private bool _isRunning; + /// + /// Gets or sets a value indicating whether a stub is currently running. + /// + public bool IsRunning { - get { return _log; } - set { _log = value; RaisePropertyChangedAuto(); } + get { return _isRunning; } + set { _isRunning = value; RaisePropertyChanged(nameof(IsRunning)); InvalidateRelayCommands(); } } - /// /// Gets or sets the run command. /// @@ -63,6 +76,26 @@ namespace Tango.MachineStudio.UI.Console /// public RelayCommand ClearCommand { get; set; } + /// + /// Gets or sets the new command. + /// + public RelayCommand NewCommand { get; set; } + + /// + /// Gets or sets the open command. + /// + public RelayCommand OpenCommand { get; set; } + + /// + /// Gets or sets the save command. + /// + public RelayCommand SaveCommand { get; set; } + + /// + /// Gets or sets the save as command. + /// + public RelayCommand SaveAsCommand { get; set; } + public ConsoleWindowVM(IStudioModuleLoader moduleLoader, INotificationProvider notification) { _moduleLoader = moduleLoader; @@ -117,6 +150,12 @@ namespace Tango.MachineStudio.UI.Console } Code = EmbeddedResourceHelper.GetEmbeddedResourceText("Tango.MachineStudio.UI.Console.CodeTemplate.cs"); + + NewCommand = new RelayCommand(CreateNew); + OpenCommand = new RelayCommand(OpenFile); + SaveCommand = new RelayCommand(SaveFile); + SaveAsCommand = new RelayCommand(SaveAsFile); + ClearCommand = new RelayCommand(ClearLog); } private void Stop() @@ -127,6 +166,7 @@ namespace Tango.MachineStudio.UI.Console private async void Run() { ScriptEngine engine = new ScriptEngine(new ConsoleOnExecuteParameters(new ConsoleManager(WriteLine))); + engine.Stop(); engine.ReferencedAssemblies.Add(this.GetType()); engine.ReferencedAssemblies.Add(typeof(INotificationProvider)); @@ -140,7 +180,78 @@ namespace Tango.MachineStudio.UI.Console private void WriteLine(String text) { - Log += text + Environment.NewLine; + InvokeUI(() => + { + _txtLog.AppendText(text); + }); + } + + /// + /// Clears the log. + /// + private void ClearLog() + { + _txtLog.Clear(); + } + + /// + /// Saves the selected script file. + /// + private void SaveFile() + { + if (_currentFile == null) + { + SaveAsFile(); + } + else + { + File.WriteAllText(_currentFile, Code); + } + } + + /// + /// Saves the selected script file. + /// + private void SaveAsFile() + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Filter = "C# Script Files|*.cs"; + dlg.DefaultExt = ".cs"; + if (dlg.ShowDialog().Value) + { + File.WriteAllText(dlg.FileName, Code); + _currentFile = dlg.FileName; + } + } + + /// + /// Opens a script from HD. + /// + private void OpenFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Filter = "C# Script Files|*.cs"; + if (dlg.ShowDialog().Value) + { + OpenFile(dlg.FileName); + } + } + + /// + /// Opens the file. + /// + /// The file. + private void OpenFile(String file) + { + Code = File.ReadAllText(file); + _currentFile = file; + } + + private void CreateNew() + { + _txtLog.Clear(); + _currentFile = null; + Code = String.Empty; } } } -- cgit v1.3.1